summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_pricelist.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/purchase_pricelist.py')
-rwxr-xr-xindoteknik_custom/models/purchase_pricelist.py41
1 files changed, 27 insertions, 14 deletions
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py
index 6ac74c69..764911cf 100755
--- a/indoteknik_custom/models/purchase_pricelist.py
+++ b/indoteknik_custom/models/purchase_pricelist.py
@@ -146,33 +146,46 @@ class PurchasePricelist(models.Model):
old_value = old_values.get(record.id, {}).get(field_name)
new_value = record[field_name]
- def stringify(val):
+ def stringify(val, field, record):
if val in [None, False]:
return 'None'
+ # Handle Selection
if isinstance(field, fields.Selection):
selection = field.selection
if callable(selection):
selection = selection(record)
return dict(selection).get(val, str(val))
+ # Handle Boolean
if isinstance(field, fields.Boolean):
return 'Yes' if val else 'No'
+ # Handle Many2one
if isinstance(field, fields.Many2one):
- return val.name if hasattr(val, 'name') else str(val)
+ if isinstance(val, int):
+ rec = record.env[field.comodel_name].browse(val)
+ return rec.display_name if rec.exists() else str(val)
+ elif isinstance(val, models.BaseModel):
+ return val.display_name
+ return str(val)
+ # Handle Many2many
if isinstance(field, fields.Many2many):
- records = val if isinstance(val, models.Model) else val
- names = []
- if records:
- for attr in ['name', 'x_name', 'display_name']:
- if hasattr(records[0], attr):
- names = records.mapped(attr)
- break
- if not names:
- names = [str(r.id) for r in records]
- return ", ".join(names) if names else 'None'
+ records = val if isinstance(val, models.BaseModel) else record[field.name]
+ if not records:
+ return 'None'
+ for attr in ['name', 'x_name', 'display_name']:
+ if hasattr(records[0], attr):
+ return ", ".join(records.mapped(attr))
+ return ", ".join(str(r.id) for r in records)
+ # Handle One2many
+ if isinstance(field, fields.One2many):
+ records = val if isinstance(val, models.BaseModel) else record[field.name]
+ if not records:
+ return 'None'
+ return f"{field.comodel_name}({', '.join(str(r.id) for r in records)})"
+ # Default case (Char, Float, Integer, etc)
return str(val)
- old_val_str = stringify(old_value)
- new_val_str = stringify(new_value)
+ old_val_str = stringify(old_value, field, record)
+ new_val_str = stringify(new_value, field, record)
if old_val_str != new_val_str:
changes.append(f"<li><b>{field_label}</b>: '{old_val_str}' → '{new_val_str}'</li>")