Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][16.0][MIG] shopinvader_api_quotation #1447

Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/shopinvader_api_quotation/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
82 changes: 82 additions & 0 deletions shopinvader_api_quotation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
=========================
Shopinvader Api Quotation
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4c1e06e244ef06ce9c71452a43b833eb1be5023f7e91a5077e0499c05fbc1163
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github
:target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_api_quotation
:alt: shopinvader/odoo-shopinvader

|badge1| |badge2| |badge3|

This module adds a REST API for shopinvader to manage quotations.

The Customer can convert a cart into a quotation (the typology of the sale
order is set to quotation).

Initially, the quotation has the `shopinvader_state` "estimating".
After updating the price manually when the button "sent" on Odoo backend
is submitted, the quotation will be sent by email (native behaviour) and the
shopinvader_state will switch to "estimated".

On Shopinvader site, the customer can see the state, the amount ... of quotation.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/shopinvader/odoo-shopinvader/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/shopinvader/odoo-shopinvader/issues/new?body=module:%20shopinvader_api_quotation%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Akretion

Contributors
~~~~~~~~~~~~

* Sebastien BEAU <[email protected]>
* Benoît GUILLOT <[email protected]>
* Iván Todorovich <[email protected]>
* Simone Orsi <[email protected]>
* Matthieu Saison <[email protected]>

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Akretion R&D
* LaboAndCo

Maintainers
~~~~~~~~~~~

This module is part of the `shopinvader/odoo-shopinvader <https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_api_quotation>`_ project on GitHub.

You are welcome to contribute.
2 changes: 2 additions & 0 deletions shopinvader_api_quotation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import routers
from . import models
30 changes: 30 additions & 0 deletions shopinvader_api_quotation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Shopinvader Api Quotation",
"summary": "Shopinvader Quotation",
"version": "16.0.1.0.1",
"category": "e-commerce",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"author": "Akretion",
"license": "AGPL-3",
"depends": [
"crm",
"fastapi",
"shopinvader_schema_sale",
"shopinvader_api_security_sale",
"shopinvader_api_cart",
"shopinvader_api_sale",
"sale_cart",
],
"data": [
"views/product_view.xml",
# " views/sale_view.xml",
],
"external_dependencies": {
"python": [
"fastapi",
"pydantic>=2.0.0",
"extendable_pydantic>=1.0.0",
]
},
"installable": True,
}
3 changes: 3 additions & 0 deletions shopinvader_api_quotation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import sale_order
from . import product_template
from . import product_product
13 changes: 13 additions & 0 deletions shopinvader_api_quotation/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2021 Camptocamp (https://www.camptocamp.com).
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductProduct(models.Model):
_inherit = "product.product"

shop_only_quotation = fields.Boolean(
string="Shopinvader: Only for Quotation",
)
51 changes: 51 additions & 0 deletions shopinvader_api_quotation/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2017-2018 Akretion (http://www.akretion.com).
# Copyright 2021 Camptocamp (https://www.camptocamp.com).
# @author Benoît GUILLOT <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

shop_only_quotation = fields.Selection(
selection=[
("all_variant", "All Variant"),
("manually_on_variant", "Manually on Variant"),
("never", "Never"),
],
string="Shopinvader: Only for Quotation",
compute="_compute_shop_only_quotation",
inverse="_inverse_shop_only_quotation",
store=True,
)

@api.depends("product_variant_ids.shop_only_quotation")
def _compute_shop_only_quotation(self):
# True only if true for all its variants
for rec in self:
if not rec.product_variant_ids or not any(
rec.product_variant_ids.mapped("shop_only_quotation")
):
rec.shop_only_quotation = "never"
elif all(rec.product_variant_ids.mapped("shop_only_quotation")):
rec.shop_only_quotation = "all_variant"
elif any(rec.product_variant_ids.mapped("shop_only_quotation")):
rec.shop_only_quotation = "manually_on_variant"

def _inverse_shop_only_quotation(self):
# Sets the value on all its variants
for rec in self:
if rec.shop_only_quotation == "all_variant":
rec.product_variant_ids.shop_only_quotation = True
elif rec.shop_only_quotation == "never":
rec.product_variant_ids.shop_only_quotation = False

def _create_variant_ids(self):
# Make sure new variants have the same value than the template.
res = super()._create_variant_ids()
for rec in self:
if rec.shop_only_quotation == "all_variant":
rec.product_variant_ids.shop_only_quotation = True
return res
41 changes: 41 additions & 0 deletions shopinvader_api_quotation/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2017-2018 Akretion (http://www.akretion.com).
# Copyright 2021 Camptocamp (http://www.camptocamp.com)
# @author Benoît GUILLOT <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import _, fields, models
from odoo.exceptions import UserError


class SaleOrder(models.Model):
_inherit = "sale.order"

typology = fields.Selection(
selection_add=[("quotation", "Quotation")],
ondelete={"quotation": "cascade"},
)
available_for_quotation = fields.Boolean(compute="_compute_available_for_quotation")
shop_only_quotation = fields.Boolean(compute="_compute_shop_only_quotation")

def action_request_quotation(self):
if any(rec.state != "draft" or rec.typology != "cart" for rec in self):
raise UserError(
_(
"Only orders of cart typology in draft state "
"can be converted to quotation"
)
)
for rec in self:
rec.typology = "quotation"
return self

def _compute_available_for_quotation(self):
for record in self:
record.available_for_quotation = True

def _compute_shop_only_quotation(self):
for record in self:
record.shop_only_quotation = any(
record.order_line.product_id.mapped("shop_only_quotation")
)
5 changes: 5 additions & 0 deletions shopinvader_api_quotation/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Sebastien BEAU <[email protected]>
* Benoît GUILLOT <[email protected]>
* Iván Todorovich <[email protected]>
* Simone Orsi <[email protected]>
* Matthieu Saison <[email protected]>
4 changes: 4 additions & 0 deletions shopinvader_api_quotation/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The development of this module has been financially supported by:

* Akretion R&D
* LaboAndCo
11 changes: 11 additions & 0 deletions shopinvader_api_quotation/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module adds a REST API for shopinvader to manage quotations.

The Customer can convert a cart into a quotation (the typology of the sale
order is set to quotation).

Initially, the quotation has the `shopinvader_state` "estimating".
After updating the price manually when the button "sent" on Odoo backend
is submitted, the quotation will be sent by email (native behaviour) and the
shopinvader_state will switch to "estimated".

On Shopinvader site, the customer can see the state, the amount ... of quotation.
2 changes: 2 additions & 0 deletions shopinvader_api_quotation/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import quotation
matthieusaison marked this conversation as resolved.
Show resolved Hide resolved
from . import cart
25 changes: 25 additions & 0 deletions shopinvader_api_quotation/routers/cart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Annotated

from fastapi import Depends

from odoo import api

from odoo.addons.base.models.res_partner import Partner as ResPartner
from odoo.addons.fastapi.dependencies import (
authenticated_partner,
authenticated_partner_env,
)
from odoo.addons.shopinvader_api_cart.routers import cart_router
from odoo.addons.shopinvader_schema_sale.schemas.sale import Sale


@cart_router.post("/{uuid}/request_quotation")
def request_quotation(
env: Annotated[api.Environment, Depends(authenticated_partner_env)],
partner: Annotated["ResPartner", Depends(authenticated_partner)],
uuid: str | None = None,
) -> Sale:
sale = env["sale.order"]._find_open_cart(partner.id, uuid)
sale.action_request_quotation()

return Sale.from_sale_order(sale)
102 changes: 102 additions & 0 deletions shopinvader_api_quotation/routers/quotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from typing import Annotated

from fastapi import APIRouter, Depends

from odoo import models
from odoo.api import Environment

from odoo.addons.base.models.res_partner import Partner as ResPartner
from odoo.addons.extendable_fastapi.schemas import PagedCollection
from odoo.addons.fastapi.dependencies import (
authenticated_partner,
authenticated_partner_env,
paging,
)
from odoo.addons.fastapi.schemas import Paging
from odoo.addons.shopinvader_schema_sale.schemas.sale import Sale, SaleSearch

from ..schemas.sale import QuotationUpdateInput

# create a router
quotation_router = APIRouter(tags=["quotations"])


@quotation_router.get("/quotations/{quotation_id}")
def get(
env: Annotated[Environment, Depends(authenticated_partner_env)],
partner: Annotated[ResPartner, Depends(authenticated_partner)],
quotation_id: int | None = None,
) -> Sale | None:
return Sale.from_sale_order(
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._get(quotation_id)
)


@quotation_router.get("/quotations/{quotation_id}/confirm", status_code=200)
def confirm_quotation(
env: Annotated[Environment, Depends(authenticated_partner_env)],
partner: Annotated[ResPartner, Depends(authenticated_partner)],
quotation_id: int | None = None,
) -> None:
order = (
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._confirm(quotation_id)
)
return Sale.from_sale_order(order)


@quotation_router.get("/quotations", status_code=200)
def search_quotation(
params: Annotated[SaleSearch, Depends()],
paging: Annotated[Paging, Depends(paging)],
env: Annotated[Environment, Depends(authenticated_partner_env)],
partner: Annotated[ResPartner, Depends(authenticated_partner)],
) -> PagedCollection[Sale]:
count, orders = (
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._search(paging, params)
)
return PagedCollection[Sale](
count=count,
items=[Sale.from_sale_order(order) for order in orders],
)


matthieusaison marked this conversation as resolved.
Show resolved Hide resolved
@quotation_router.post("/quotations/{quotation_id}")
def update_quotation(
data: QuotationUpdateInput,
env: Annotated[Environment, Depends(authenticated_partner_env)],
partner: Annotated["ResPartner", Depends(authenticated_partner)],
quotation_id: int,
) -> Sale:
order = (
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._update(quotation_id, data)
)
return Sale.from_sale_order(order)


class ShopinvaderApiSaleSalesRouterHelper(models.AbstractModel):
_name = "shopinvader_api_quotation.quotations_router.helper"
_inherit = "shopinvader_api_sale.sales_router.helper"

def _get_domain_adapter(self):
return [
("partner_id", "=", self.partner.id),
("typology", "=", "quotation"),
]

def _confirm(self, quotation):
matthieusaison marked this conversation as resolved.
Show resolved Hide resolved
order = self._get(quotation)
order.action_confirm()
return order

def _update(self, quotation, data):
matthieusaison marked this conversation as resolved.
Show resolved Hide resolved
order = self._get(quotation)
order.write(data.to_sale_order_vals())
return order
1 change: 1 addition & 0 deletions shopinvader_api_quotation/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale
Loading
Loading