From bcc86ad4b0f30217d17815119a5ff736f3b91ed5 Mon Sep 17 00:00:00 2001 From: "Levi Siuzdak (sile)" Date: Tue, 6 Feb 2024 13:44:51 +0000 Subject: [PATCH] [FIX] product: don't remove product_tmpl_id from supplierinfo Versions -------- - 15.0+ Steps ----- 1. Go to product variants; 2. select a product; 3. add a new Vendor line in the Purchase tab; 4. save; 5. add another Vendor line; 6. save. Issue ----- Previous line disappears from view. Cause ----- In 93bc96047ff684cb66b69186822493815cf37982 I added logic which sets the `product_tmpl_id` in `product.supplierinfo` if a `product_id` gets written without accompanying `product_tmpl_id`. Adding lines from the Product Variant views add `{'product_id': False}` to the values for every vendor in the list without a Product Variant, so their `product_tmpl_id` gets overwritten with the `product_tmpl_id` of an empty product. Solution -------- Only overwrite `product_tmpl_id` iff `product_id` gets written to a non-falsy value by changing `if 'product_id' in vals` to `if vals.get('product_id')`. opw-3664524 closes odoo/odoo#153168 X-original-commit: 03d4be7b8804863a7e7e9af29a8ec61c65d6dab3 Signed-off-by: Quentin Wolfs (quwo) Signed-off-by: Levi Siuzdak --- addons/product/models/product_supplierinfo.py | 3 ++- addons/product/tests/test_seller.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product_supplierinfo.py b/addons/product/models/product_supplierinfo.py index af0a94f6f2d..6bf474a2bfa 100644 --- a/addons/product/models/product_supplierinfo.py +++ b/addons/product/models/product_supplierinfo.py @@ -86,7 +86,8 @@ class SupplierInfo(models.Model): def _sanitize_vals(self, vals): """Sanitize vals to sync product variant & template on read/write.""" - if 'product_id' in vals and 'product_tmpl_id' not in vals: + # add product's product_tmpl_id if none present in vals + if vals.get('product_id') and not vals.get('product_tmpl_id'): product = self.env['product.product'].browse(vals['product_id']) vals['product_tmpl_id'] = product.product_tmpl_id.id diff --git a/addons/product/tests/test_seller.py b/addons/product/tests/test_seller.py index 42deb5ec410..7de18ed985f 100644 --- a/addons/product/tests/test_seller.py +++ b/addons/product/tests/test_seller.py @@ -146,3 +146,6 @@ class TestSeller(TransactionCase): }]) self.assertEqual(vendors, self.product_consu.seller_ids, "Sellers of a product should be listed in the product's seller_ids") + vendors.write({'product_id': False}) + self.assertEqual(vendors, self.product_consu.seller_ids, + "Setting the product_id to False shouldn't affect seller_ids.")