summaryrefslogtreecommitdiff
path: root/addons/product/tests
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2020-04-01 11:38:17 +0000
committerArnold Moyaux <arm@odoo.com>2020-06-18 11:35:38 +0000
commitf979e3e093409fb043ed83b5d6764c272096c923 (patch)
tree36e2d83c9a929cad83e729179c27b118d4de3770 /addons/product/tests
parente617aa91c536093f481da28b0cf061a6abe55b2a (diff)
[FIX] product: editing uom on product.product
Updating the uom_id on a product_product will eventually change also the uom_po_id to have them belonging to the same category. Saving the update call write() on product with a dict of two values (uom_id and uom_po_id) As product.product is inherited from product.template, the write() on the corresponding product_template is called but in this case 2 times for each values. The first time, only uom_id is updated. The _check_uom constraint is triggered and obviously failed. The uom_po_id on the template is not yet updated. This commit makes the sync in the beginning of write() of product.template. Which means before calling the constraint. This commit also makes the onchanges on uom_id acts the same between product.product and product.template. Task : 2197818 closes odoo/odoo#48714 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
Diffstat (limited to 'addons/product/tests')
-rw-r--r--addons/product/tests/test_variants.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py
index d1ee1107a91..b5a09d9f736 100644
--- a/addons/product/tests/test_variants.py
+++ b/addons/product/tests/test_variants.py
@@ -8,7 +8,7 @@ from PIL import Image
from . import common
from odoo.exceptions import UserError
-from odoo.tests.common import TransactionCase
+from odoo.tests.common import TransactionCase, Form
class TestVariantsSearch(TransactionCase):
@@ -922,6 +922,27 @@ class TestVariantsArchive(common.TestProductCommon):
name_searched = self.env['product.template'].name_search(name='cima')
self.assertIn(template.id, [ng[0] for ng in name_searched])
+ def test_uom_update_variant(self):
+ """ Changing the uom on the template do not behave the same
+ as changing on the product product."""
+ units = self.env.ref('uom.product_uom_unit')
+ cm = self.env.ref('uom.product_uom_cm')
+ template = self.env['product.template'].create({
+ 'name': 'kardon'
+ })
+
+ template_form = Form(template)
+ template_form.uom_id = cm
+ self.assertEqual(template_form.uom_po_id, cm)
+ template = template_form.save()
+
+ variant_form = Form(template.product_variant_ids)
+ variant_form.uom_id = units
+ self.assertEqual(variant_form.uom_po_id, units)
+ variant = variant_form.save()
+ self.assertEqual(variant.uom_po_id, units)
+ self.assertEqual(template.uom_po_id, units)
+
def _update_color_vars(self, ptal):
self.ptal_color = ptal
self.assertEqual(self.ptal_color.attribute_id, self.pa_color)