summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-05-14 08:28:53 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-05-14 08:28:53 +0700
commitbf79c492c047b8b9e0aa7657959a6f94263765dd (patch)
treea13bb331f5f4cc85a13bf4285dec0e23c5c7d9de
parent2c565f289de7d5827a7d9e09b4919ecffcf0437c (diff)
(andri) add log note di product ketika variant ada perubahan
-rwxr-xr-xindoteknik_custom/models/product_template.py31
1 files 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"<li><b>{field_label}</b>: '{old_val_str}' → '{new_val_str}'</li>")
if changes:
- message = "<b>Updated:</b><ul>%s</ul>" % "".join(changes)
- record.message_post(body=message)
+ # Post message to variant
+ variant_message = "<b>Updated:</b><ul>%s</ul>" % "".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 = "<b>Variant Updates:</b><br/>"
+
+ for variant_id, variant_data in variants_data.items():
+ # Create clickable link using your format
+ variant_link = f"<a href=\"#id={variant_id}&model=product.product&view_type=form\">{variant_data['name']}</a><br/>"
+ template_message += f"{variant_link}<ul>{''.join(variant_data['changes'])}</ul><br/>"
+
+ template.message_post(body=template_message)
# simpan data lama dan log perubahan field
def write(self, vals):