From aca89f41cf980e2ea9b7f266d4792be52d2e4aa1 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Thu, 8 May 2025 22:12:07 +0700 Subject: (andri) add log note pada purchase list untuk catat perubahan tiap fields --- indoteknik_custom/models/purchase_pricelist.py | 67 +++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_pricelist.py') diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index e5b35d7f..6ac74c69 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -6,6 +6,7 @@ from pytz import timezone class PurchasePricelist(models.Model): _name = 'purchase.pricelist' _rec_name = 'product_id' + _inherit = ['mail.thread', 'mail.activity.mixin'] name = fields.Char(string='Name', compute="_compute_name") product_id = fields.Many2one('product.product', string="Product", required=True) @@ -120,4 +121,68 @@ class PurchasePricelist(models.Model): rec.sync_pricelist_tier() rec.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr') - \ No newline at end of file + + def _collect_old_values(self, vals): + return { + record.id: { + field_name: record[field_name] + for field_name in vals.keys() + if field_name in record._fields + } + for record in self + } + + def _log_field_changes(self, vals, old_values): + exclude_fields = ['solr_flag', 'desc_update_solr', 'last_update_solr', 'is_edited'] + + for record in self: + changes = [] + for field_name in vals: + if field_name not in record._fields or field_name in exclude_fields: + continue + + field = record._fields[field_name] + field_label = field.string or field_name + old_value = old_values.get(record.id, {}).get(field_name) + new_value = record[field_name] + + def stringify(val): + if val in [None, False]: + return 'None' + if isinstance(field, fields.Selection): + selection = field.selection + if callable(selection): + selection = selection(record) + return dict(selection).get(val, str(val)) + if isinstance(field, fields.Boolean): + return 'Yes' if val else 'No' + if isinstance(field, fields.Many2one): + return val.name if hasattr(val, 'name') else str(val) + 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' + return str(val) + + old_val_str = stringify(old_value) + new_val_str = stringify(new_value) + + if old_val_str != new_val_str: + changes.append(f"
  • {field_label}: '{old_val_str}' → '{new_val_str}'
  • ") + + if changes: + message = "Updated:" % "".join(changes) + record.message_post(body=message) + + def write(self, vals): + old_values = self._collect_old_values(vals) + result = super(PurchasePricelist, self).write(vals) + self._log_field_changes(vals, old_values) + return result \ No newline at end of file -- cgit v1.2.3 From 0f7e495ae7a28bd897929322e0419de91ecb1675 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Fri, 9 May 2025 11:21:46 +0700 Subject: (andri) penyesuaian log note pada purchase pricelist & handle perubahan log note image di product & variant (only notif add/update/delete) --- indoteknik_custom/models/purchase_pricelist.py | 41 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'indoteknik_custom/models/purchase_pricelist.py') 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"
  • {field_label}: '{old_val_str}' → '{new_val_str}'
  • ") -- cgit v1.2.3 From 2469ee37cfe854f0419a8c3fbabed5bc32bcaa6e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 13 May 2025 14:56:55 +0700 Subject: push --- indoteknik_custom/models/purchase_pricelist.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'indoteknik_custom/models/purchase_pricelist.py') diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index e5b35d7f..dd680f4d 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -83,6 +83,15 @@ class PurchasePricelist(models.Model): massage="Ada duplikat product dan vendor, berikut data yang anda duplikat : \n" + str(existing_purchase.product_id.name) + " - " + str(existing_purchase.vendor_id.name) + " - " + str(existing_purchase.product_price) if existing_purchase: raise UserError(massage) + + def sync_pricelist_item_promo(self, product): + pricelist_product = self.env['product.pricelist.item'].search([('product_id', '=', product.id), ('pricelist_id', '=', 17022)]) + for pricelist in pricelist_product: + if pricelist.fixed_price == 0: + flashsale = self.env['product.pricelist.item'].search([('product_id', '=', product.id), ('pricelist_id.is_flash_sale', '=', True)]) + if flashsale: + flashsale.fixed_price = 0 + return def action_calculate_pricelist(self): MAX_PRICELIST = 10 @@ -94,6 +103,8 @@ class PurchasePricelist(models.Model): records = self.env['purchase.pricelist'].browse(active_ids) price_group = self.env['price.group'].collect_price_group() for rec in records: + if rec.include_price == 0: + rec.sync_pricelist_item_promo(rec.product_id) product_group = rec.product_id.product_tmpl_id.x_manufacture.pricing_group or None price_incl = rec.include_price -- cgit v1.2.3