Skip to content

Commit

Permalink
update & add test product
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu.saison committed Nov 14, 2023
1 parent 0eef8e8 commit 53964f5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
19 changes: 11 additions & 8 deletions shopinvader_api_quotation/routers/quotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get(
quotation_id: int | None = None,
) -> Sale | None:
return Sale.from_sale_order(
env["shopinvader_api_sale.sales_router.helper"]
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._get(quotation_id)
)
Expand All @@ -41,7 +41,7 @@ def confirm_quotation(
quotation_id: int | None = None,
) -> None:
order = (
env["shopinvader_api_sale.sales_router.helper"]
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._confirm(quotation_id)
)
Expand All @@ -56,7 +56,7 @@ def search_quotation(
partner: Annotated[ResPartner, Depends(authenticated_partner)],
) -> PagedCollection[Sale]:
count, orders = (
env["shopinvader_api_sale.sales_router.helper"]
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._search(paging, params)
)
Expand All @@ -74,17 +74,15 @@ def update_quotation(
quotation_id: int,
) -> Sale:
order = (
env["shopinvader_api_sale.sales_router.helper"]
env["shopinvader_api_quotation.quotations_router.helper"]
.new({"partner": partner})
._get(quotation_id)
._update(quotation_id, data)
)

vals = data.to_sale_order_vals()
order.write(vals)
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):
Expand All @@ -97,3 +95,8 @@ def _confirm(self, quotation):
order = self._get(quotation)
order.action_confirm()
return order

def _update(self, quotation, data):
order = self._get(quotation)
order.write(data.to_sale_order_vals())
return order
1 change: 1 addition & 0 deletions shopinvader_api_quotation/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_shopinvader_api_quotation
from . import test_product
65 changes: 65 additions & 0 deletions shopinvader_api_quotation/tests/test_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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.tests.common import SavepointCase


class TestProduct(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.attribute = cls.env.ref("product.product_attribute_2")
cls.value_1 = cls.env.ref("product.product_attribute_value_3")
cls.value_2 = cls.env.ref("product.product_attribute_value_4")
cls.product_template = cls.env["product.template"].create(
{
"name": "Test Product",
}
)

def test_simple_product(self):
# Back and forth flow, setting and reading on template and single variant
self.assertFalse(self.product_template.shop_only_quotation)
self.product_template.shop_only_quotation = True
self.assertTrue(self.product_template.product_variant_ids.shop_only_quotation)
self.product_template.product_variant_ids.shop_only_quotation = False
self.assertFalse(self.product_template.shop_only_quotation)

def test_multi_product(self):
# Configure product with multiple variants
self.product_template.attribute_line_ids = [
(
0,
0,
{
"attribute_id": self.attribute.id,
"value_ids": [(6, 0, [self.value_1.id, self.value_2.id])],
},
)
]
self.assertEqual(len(self.product_template.product_variant_ids), 2)
template = self.product_template
product_1 = self.product_template.product_variant_ids[0]
product_2 = self.product_template.product_variant_ids[1]
# Set on the template should set all variants
template.shop_only_quotation = True
self.assertTrue(product_1.shop_only_quotation)
self.assertTrue(product_2.shop_only_quotation)
# Set a variant to false should set the template to false
# It's only true if it's true for all variants
product_1.shop_only_quotation = False
self.assertFalse(template.shop_only_quotation)
self.assertTrue(product_2.shop_only_quotation, "Other variant shouldn't change")
# Set false on template should set all variants to false
template.shop_only_quotation = False
self.assertFalse(product_1.shop_only_quotation)
self.assertFalse(product_2.shop_only_quotation)
# Create a new variant combination should copy the value from template
template.shop_only_quotation = True
value_3 = self.value_2.copy({"name": "Another color"})
template.attribute_line_ids.value_ids = [(4, value_3.id)]
self.assertEqual(len(self.product_template.product_variant_ids), 3)
product_3 = self.product_template.product_variant_ids - (product_1 | product_2)
self.assertTrue(product_3.shop_only_quotation)

0 comments on commit 53964f5

Please sign in to comment.