summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-03-03 09:16:21 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-03-03 09:16:21 +0700
commit7c675cd5bc9f45d2ebca33a63b7184cbb97f0f2f (patch)
tree0cf6b05077f934c0a884fed510d82c6fc4386724
parentd67c586c80d87e7e2f3da703cd04e6680fbd62b7 (diff)
<iman> CR safa add log note when product detail change
-rw-r--r--indoteknik_custom/models/requisition.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py
index c972b485..1d350929 100644
--- a/indoteknik_custom/models/requisition.py
+++ b/indoteknik_custom/models/requisition.py
@@ -276,10 +276,11 @@ class RequisitionLine(models.Model):
_name = 'requisition.line'
_description = 'Requisition Line'
_order = 'requisition_id, id'
+ _inherit = ['mail.thread']
requisition_id = fields.Many2one('requisition', string='Ref', required=True, ondelete='cascade', index=True, copy=False)
brand_id = fields.Many2one('x_manufactures', string='Brand')
- product_id = fields.Many2one('product.product', string='Product')
+ product_id = fields.Many2one('product.product', string='Product', tracking=3,)
partner_id = fields.Many2one('res.partner', string='Vendor')
qty_purchase = fields.Float(string='Qty Purchase')
price_unit = fields.Float(string='Price')
@@ -331,6 +332,45 @@ class RequisitionLine(models.Model):
line.taxes_id = taxes
line.partner_id = purchase_pricelist.vendor_id.id
+ @api.model
+ def create(self, vals):
+ record = super(RequisitionLine, self).create(vals)
+ record._track_changes('Tambah')
+ return record
+
+ def write(self, vals):
+ for record in self:
+ old_values = {field: record[field] for field in vals if field in record}
+
+ result = super(RequisitionLine, self).write(vals)
+
+ for record in self:
+ record._track_changes('Updated', old_values)
+
+ return result
+
+ def unlink(self):
+ for record in self:
+ record._track_changes('Hapus')
+ return super(RequisitionLine, self).unlink()
+
+ def _track_changes(self, action, old_values=None):
+ message = f"Produk telah di-{action} : <br/>"
+ if action == 'Tambah':
+ # message += f"<br/> Product: {self.product_id.name}"
+ message += f"Product: {self.product_id.name} <br/> Vendor: {self.partner_id.name} <br/> Qty: {self.qty_purchase} <br/> Price: {self.price_unit} <br/> Tax: {self.tax_id.name} <br/> Subtotal: {self.subtotal} <br/> Brand: {self.brand_id.x_name}"
+ elif action == 'Hapus':
+ # message += f"<br/> Deleted Product: {self.product_id.name}"
+ message += f"<br/> Deleted Product: {self.product_id.name} <br/> Vendor: {self.partner_id.name} Qty: {self.qty_purchase} <br/> Price: {self.price_unit} <br/> Tax: {self.tax_id.name} <br/> Subtotal: {self.subtotal} <br/> Brand: {self.brand_id.x_name}"
+ else: # Updated
+ for field, old_value in old_values.items():
+ new_value = self[field]
+ if old_value != new_value:
+ field_label = self._fields[field].string # Ambil nama label field
+ message += f"{field_label}: {old_value} -> {new_value}<br/>"
+
+ if self.requisition_id:
+ self.requisition_id.message_post(body=message)
class RequisitionPurchaseMatch(models.Model):
_name = 'requisition.purchase.match'