From bf79c492c047b8b9e0aa7657959a6f94263765dd Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Wed, 14 May 2025 08:28:53 +0700 Subject: (andri) add log note di product ketika variant ada perubahan --- indoteknik_custom/models/product_template.py | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 1d4723a6..2679fbfd 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1230,6 +1230,8 @@ class ProductProduct(models.Model): 'product_template_image_ids': 'Extra Product Media', } + template_changes = {} + for record in self: changes = [] for field_name in vals: @@ -1288,8 +1290,33 @@ class ProductProduct(models.Model): changes.append(f"
  • {field_label}: '{old_val_str}' → '{new_val_str}'
  • ") if changes: - message = "Updated:" % "".join(changes) - record.message_post(body=message) + # Post message to variant + variant_message = "Updated:" % "".join(changes) + record.message_post(body=variant_message) + + # Group changes by template for posting to template + template_id = record.product_tmpl_id.id + if template_id not in template_changes: + template_changes[template_id] = {} + + # Store variant information including ID for creating clickable link + template_changes[template_id][record.id] = { + 'name': record.display_name or f"Variant {record.id}", + 'changes': changes + } + + # Post grouped messages to templates with clickable links using your format + for template_id, variants_data in template_changes.items(): + template = self.env['product.template'].browse(template_id) + if template.exists(): + template_message = "Variant Updates:
    " + + for variant_id, variant_data in variants_data.items(): + # Create clickable link using your format + variant_link = f"{variant_data['name']}
    " + template_message += f"{variant_link}
    " + + template.message_post(body=template_message) # simpan data lama dan log perubahan field def write(self, vals): -- cgit v1.2.3