-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add request and update quotation, and tests
- Loading branch information
matthieu.saison
committed
Nov 14, 2023
1 parent
3a2c41d
commit 0eef8e8
Showing
13 changed files
with
221 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file is going to be generated by oca-gen-addon-readme. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import sale_order | ||
from . import product_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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.Boolean( | ||
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: | ||
rec.shop_only_quotation = ( | ||
all(rec.product_variant_ids.mapped("shop_only_quotation")) | ||
if rec.product_variant_ids | ||
else False | ||
) | ||
|
||
def _inverse_shop_only_quotation(self): | ||
# Sets the value on all its variants | ||
for rec in self: | ||
rec.product_variant_ids.shop_only_quotation = rec.shop_only_quotation | ||
|
||
def _create_variant_ids(self): | ||
# Make sure new variants have the same value than the template. | ||
templates = self.filtered("shop_only_quotation") | ||
res = super()._create_variant_ids() | ||
products = templates.product_variant_ids.filtered( | ||
lambda rec: not rec.shop_only_quotation | ||
) | ||
products.shop_only_quotation = True | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import quotation | ||
from . import cart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, 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_schema_sale.schemas.sale import Sale | ||
|
||
cart_router = APIRouter(tags=["carts"]) | ||
|
||
|
||
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from extendable_pydantic import StrictExtendableBaseModel | ||
|
||
from odoo.addons.shopinvader_schema_sale.schemas.sale import Sale | ||
|
||
|
||
class Sale(Sale, extends=True): | ||
available_for_quotation: bool | None = None | ||
shop_only_quotation: bool | None = None | ||
|
||
@classmethod | ||
def from_sale_order(cls, odoo_rec): | ||
res = super().from_sale_order(odoo_rec) | ||
res.available_for_quotation = True | ||
res.shop_only_quotation = odoo_rec.shop_only_quotation | ||
# res.shop_only_quotation = any( | ||
# odoo_rec.order_line.product_id.mapped("shop_only_quotation") | ||
# ) mettre un champs calculé coté odoo sur model sale_order | ||
return res | ||
|
||
|
||
class QuotationUpdateInput(StrictExtendableBaseModel): | ||
customer_ref: str | None = None | ||
|
||
def to_sale_order_vals(self) -> dict: | ||
return {"client_order_ref": self.customer_ref} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters