From b3ce733937b64bce6c4f0e7599eb25849e4a0744 Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Mon, 5 Feb 2024 13:04:09 +0000 Subject: [PATCH] [FIX] product: Correct ID retrieval in contact price list calculation when changing province How to reproduce the error: 1. Go to Contacts. 2. Select a Contact of Type Company: Find and select a contact that is a company type and to which a price list has already been set up previously. In case no price list has been set previously, set the price list and save the contact. 3. Edit the contact and modify the address state without the need to save the changes. 4. View the PriceList: After changing the province, look at the price list field. You can verify that the price list has become blank immediately after making the change in state, without the need to save the changes. Current behaviour: the price list is deleted when the state of the address is changed. Expected behaviour: keep the previously set price list. Explanation: The code was incorrectly using "p.id" instead of "p._origin.id" to get the contact ID. This resulted in a non-existent key being retrieved and caused the loss of the price list in the contact when changing the province. The fix adjusts the code to correctly use "p._origin.id", ensuring correct retrieval of the ID and avoiding unwanted changes to the price list. Example of data obtained by debugging: - Edited user: Deco Addict - Data obtained in "res": res {53: product.pricelist(1,)} - Data retrieved in "p.id": (p.id) > NewId_53 - Data retrieved at "p._origin.id": (p._origin.id) > 53 TT47536 closes odoo/odoo#153326 X-original-commit: 570715ecc6c9b105a2edaed23a68f557e5cf1987 Signed-off-by: Victor Feyens (vfe) --- addons/product/models/res_partner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/models/res_partner.py b/addons/product/models/res_partner.py index 79cc3140d0c..edb01c5ee59 100644 --- a/addons/product/models/res_partner.py +++ b/addons/product/models/res_partner.py @@ -22,7 +22,7 @@ class ResPartner(models.Model): def _compute_product_pricelist(self): res = self.env['product.pricelist']._get_partner_pricelist_multi(self.ids) for partner in self: - partner.property_product_pricelist = res.get(partner.id) + partner.property_product_pricelist = res.get(partner._origin.id) def _inverse_product_pricelist(self): for partner in self: