diff --git a/sale_order_secondary_unit/__manifest__.py b/sale_order_secondary_unit/__manifest__.py index 1210a3feff3..9b31ce1dca6 100644 --- a/sale_order_secondary_unit/__manifest__.py +++ b/sale_order_secondary_unit/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Sale Order Secondary Unit", "summary": "Sale product in a secondary unit", - "version": "15.0.2.0.0", + "version": "16.0.1.0.0", "development_status": "Production/Stable", "category": "Sale", "website": "https://github.com/OCA/sale-workflow", diff --git a/sale_order_secondary_unit/models/sale_order.py b/sale_order_secondary_unit/models/sale_order.py index 935dd50cf6a..554d8fb9c18 100644 --- a/sale_order_secondary_unit/models/sale_order.py +++ b/sale_order_secondary_unit/models/sale_order.py @@ -21,7 +21,7 @@ class SaleOrderLine(models.Model): store=True, readonly=False, compute="_compute_product_uom_qty", copy=True ) - @api.depends("secondary_uom_qty", "secondary_uom_id", "product_uom_qty") + @api.depends("product_uom_qty") def _compute_product_uom_qty(self): self._compute_helper_target_field_qty() @@ -30,14 +30,14 @@ def onchange_product_uom_for_secondary(self): self._onchange_helper_product_uom_for_secondary() @api.onchange("product_id") - def product_id_change(self): + def _onchange_product_id_warning(self): """ If default sales secondary unit set on product, put on secondary quantity 1 for being the default quantity. We override this method, that is the one that sets by default 1 on the other quantity with that purpose. """ - res = super().product_id_change() + res = super()._onchange_product_id_warning() line_uom_qty = self.product_uom_qty self.secondary_uom_id = self.product_id.sale_secondary_uom_id if self.product_id.sale_secondary_uom_id: @@ -48,8 +48,9 @@ def product_id_change(self): self.product_uom_qty = line_uom_qty return res - @api.depends("secondary_uom_qty", "product_uom_qty", "price_unit") + @api.onchange("price_unit", "secondary_uom_qty", "secondary_uom_id") def _compute_secondary_uom_unit_price(self): + self._compute_helper_target_field_qty() for line in self: if line.secondary_uom_id: try: diff --git a/sale_order_secondary_unit/tests/test_sale_order_secondary_unit.py b/sale_order_secondary_unit/tests/test_sale_order_secondary_unit.py index 5a7211cfc70..3836dbfa303 100644 --- a/sale_order_secondary_unit/tests/test_sale_order_secondary_unit.py +++ b/sale_order_secondary_unit/tests/test_sale_order_secondary_unit.py @@ -35,6 +35,7 @@ def setUpClass(cls): }, ) ], + "list_price": 1000.00, } ) cls.secondary_unit = cls.env["product.secondary.unit"].search( @@ -65,7 +66,7 @@ def test_onchange_secondary_unit_product_uom_qty(self): self.assertEqual(self.order.order_line.secondary_uom_qty, 7.0) def test_default_secondary_unit(self): - self.order.order_line.product_id_change() + self.order.order_line._onchange_product_id_warning() self.assertEqual(self.order.order_line.secondary_uom_id, self.secondary_unit) def test_onchange_order_product_uom(self): @@ -95,12 +96,15 @@ def test_independent_type(self): def test_secondary_uom_unit_price(self): # Remove secondary uom in sale line to do a complete test of secondary price - self.order.order_line.secondary_uom_id = False - self.assertEqual(self.order.order_line.secondary_uom_unit_price, 0) - self.order.order_line.update( - {"secondary_uom_id": self.secondary_unit.id, "product_uom_qty": 2} - ) - + with Form(self.env["sale.order"]) as order_form: + order_form.partner_id = self.partner + order_form.pricelist_id = self.price_list + with order_form.order_line.new() as line_form: + line_form.product_id = self.product + line_form.product_uom_qty = 2 + line_form.secondary_uom_id = self.secondary_unit + line_form.price_unit = 1000.00 + self.order = order_form.save() self.assertEqual(self.order.order_line.secondary_uom_qty, 4) self.assertEqual(self.order.order_line.secondary_uom_unit_price, 500) diff --git a/sale_order_secondary_unit/views/product_views.xml b/sale_order_secondary_unit/views/product_views.xml index 960783fd6ee..a2ef9844cfe 100644 --- a/sale_order_secondary_unit/views/product_views.xml +++ b/sale_order_secondary_unit/views/product_views.xml @@ -6,10 +6,13 @@ Product template Secondary Unit product.template - - + diff --git a/sale_order_secondary_unit/views/sale_order_views.xml b/sale_order_secondary_unit/views/sale_order_views.xml index 65a9366cf01..608658778e5 100644 --- a/sale_order_secondary_unit/views/sale_order_views.xml +++ b/sale_order_secondary_unit/views/sale_order_views.xml @@ -6,48 +6,51 @@ Sale Order Secondary Unit sale.order - - - - + - - -> + diff --git a/setup/sale_order_secondary_unit/odoo/addons/sale_order_secondary_unit b/setup/sale_order_secondary_unit/odoo/addons/sale_order_secondary_unit new file mode 120000 index 00000000000..c1ca3bc48b3 --- /dev/null +++ b/setup/sale_order_secondary_unit/odoo/addons/sale_order_secondary_unit @@ -0,0 +1 @@ +../../../../sale_order_secondary_unit \ No newline at end of file diff --git a/setup/sale_order_secondary_unit/setup.py b/setup/sale_order_secondary_unit/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/sale_order_secondary_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)