[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) <quwo@odoo.com>
Signed-off-by: Levi Siuzdak <sile@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user