From 7545b9b47c47ecc8d9e0b5f0d9bc93f9b39c46b8 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Sat, 21 Feb 2026 09:57:29 +0700 Subject: [PATCH] fix: Conditionally process and invalidate the `uom_po_id` field based on its existence and value. --- wizard/change_uom.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wizard/change_uom.py b/wizard/change_uom.py index 62a38c4..16a666c 100644 --- a/wizard/change_uom.py +++ b/wizard/change_uom.py @@ -73,13 +73,16 @@ class ProductUomChangeWizard(models.TransientModel): self.env.cr.execute("UPDATE product_template SET uom_id = %s WHERE id = %s", (self.new_uom_id.id, self.product_tmpl_id.id)) # Also update Purchase UOM if specified - if self.new_uom_po_id: - if not self.new_uom_po_id._has_common_reference(self.product_tmpl_id.uom_po_id): + if self.new_uom_po_id and 'uom_po_id' in self.product_tmpl_id._fields: + if self.product_tmpl_id.uom_po_id and not self.new_uom_po_id._has_common_reference(self.product_tmpl_id.uom_po_id): raise UserError(_("New Purchase UOM must be in the same category as the current Purchase UOM.")) self.env.cr.execute("UPDATE product_template SET uom_po_id = %s WHERE id = %s", (self.new_uom_po_id.id, self.product_tmpl_id.id)) # Invalidate cache to ensure the new value is read - self.product_tmpl_id.invalidate_recordset(['uom_id', 'uom_po_id']) + fields_to_invalidate = ['uom_id'] + if 'uom_po_id' in self.product_tmpl_id._fields: + fields_to_invalidate.append('uom_po_id') + self.product_tmpl_id.invalidate_recordset(fields_to_invalidate) # Log note in chatter self.product_tmpl_id.message_post(body=f"UOM forcefully changed from {self.current_uom_id.name} to {self.new_uom_id.name} via Wizard.")