fix: Conditionally process and invalidate the uom_po_id field based on its existence and value.

This commit is contained in:
Suherdy Yacob 2026-02-21 09:57:29 +07:00
parent e794526034
commit 7545b9b47c

View File

@ -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)) 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 # Also update Purchase UOM if specified
if self.new_uom_po_id: if self.new_uom_po_id and 'uom_po_id' in self.product_tmpl_id._fields:
if not self.new_uom_po_id._has_common_reference(self.product_tmpl_id.uom_po_id): 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.")) 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)) 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 # 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 # 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.") 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.")