From 3021a1d4836a47721500d03eeed80ba029334b98 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 11 Jul 2025 15:24:46 +0700 Subject: fix bug --- indoteknik_custom/views/approval_payment_term.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/views/approval_payment_term.xml b/indoteknik_custom/views/approval_payment_term.xml index e785b72a..8d1d01e8 100644 --- a/indoteknik_custom/views/approval_payment_term.xml +++ b/indoteknik_custom/views/approval_payment_term.xml @@ -51,10 +51,10 @@ - - - - + + + + -- cgit v1.2.3 From b298a37963027a08e0046629bbcb795effa58e3a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 11 Jul 2025 15:40:38 +0700 Subject: view and add new status on approval payment term --- indoteknik_custom/models/approval_payment_term.py | 10 +++++++++- indoteknik_custom/views/approval_payment_term.xml | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py index 6e1c8103..cd54b53a 100644 --- a/indoteknik_custom/models/approval_payment_term.py +++ b/indoteknik_custom/models/approval_payment_term.py @@ -31,7 +31,13 @@ class ApprovalPaymentTerm(models.Model): approve_leader = fields.Boolean('Approve Pimpinan', tracking=True, copy=False) reason = fields.Text('Reason', tracking=True) approve_date = fields.Datetime('Approve Date') - state = fields.Selection([('waiting_approval', 'Waiting Approval'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='waiting_approval', tracking=True) + state = fields.Selection([ + ('waiting_approval_sales_manager', 'Waiting Approval Sales Manager'), + ('waiting_approval_finance', 'Waiting Approval Finance'), + ('waiting_approval_leader', 'Waiting Approval Leader'), + ('approved', 'Approved'), + ('rejected', 'Rejected')], + default='waiting_approval_sales_manager', tracking=True) reason_reject = fields.Selection([('reason1', 'Reason 1'), ('reason2', 'Reason 2'), ('reason3', 'Reason 3')], string='Reason Reject', tracking=True) sale_order_ids = fields.Many2many( 'sale.order', @@ -77,10 +83,12 @@ class ApprovalPaymentTerm(models.Model): if (not user.id ==7 and user.id == 19 and not self.approve_sales_manager) or is_it: self.approve_sales_manager = True + self.state = 'waiting_approval_finance' return if (not user.id ==7 and user.id == 688 and not self.approve_finance) or is_it: self.approve_finance = True + self.state = 'waiting_approval_leader' return if (user.id == 7 and self.approve_finance) or is_it: diff --git a/indoteknik_custom/views/approval_payment_term.xml b/indoteknik_custom/views/approval_payment_term.xml index 8d1d01e8..373637a2 100644 --- a/indoteknik_custom/views/approval_payment_term.xml +++ b/indoteknik_custom/views/approval_payment_term.xml @@ -9,18 +9,18 @@ + - + decoration-info="state in ['waiting_approval_sales_manager', 'waiting_approval_finance', 'waiting_approval_leader']"/> -- cgit v1.2.3 From f6d21f2f6a8bbc597e70aa07a4f6c2fc43b4c176 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 12 Jul 2025 10:20:18 +0700 Subject: add change log widya only --- indoteknik_custom/models/approval_payment_term.py | 62 +++++++++++++++++++++++ indoteknik_custom/views/approval_payment_term.xml | 1 + 2 files changed, 63 insertions(+) diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py index cd54b53a..025f9ed4 100644 --- a/indoteknik_custom/models/approval_payment_term.py +++ b/indoteknik_custom/models/approval_payment_term.py @@ -53,6 +53,68 @@ class ApprovalPaymentTerm(models.Model): grand_total = fields.Float(string='Grand Total', compute="_compute_grand_total") + change_log_688 = fields.Text(string="Change Log", readonly=True, copy=False) + + def write(self, vals): + # Ambil nilai lama sebelum perubahan + old_values_dict = { + rec.id: rec.read(vals.keys())[0] + for rec in self + } + + res = super().write(vals) + + self._track_changes_for_user_688(vals, old_values_dict) + return res + + def _track_changes_for_user_688(self, vals, old_values_dict): + if self.env.user.id != 688: + return + + for rec in self: + changes = [] + old_values = old_values_dict.get(rec.id, {}) + + for field_name, new_value in vals.items(): + if field_name not in rec._fields or field_name == 'change_log_688': + continue + + field = rec._fields[field_name] + old_value = old_values.get(field_name) + + field_label = field.string # Ambil label user-friendly + + # Relational field + if field.type == 'many2one': + old_id = old_value[0] if old_value else False + is_different = old_id != new_value + if is_different: + old_display = old_value[1] if old_value else 'False' + new_display = rec.env[field.comodel_name].browse(new_value).display_name if new_value else 'False' + changes.append(f"[{field_label}] dari '{old_display}' ke '{new_display}'") + + else: + # Float khusus + if field.type == 'float': + is_different = not self._float_equal(old_value, new_value) + else: + is_different = old_value != new_value + + if is_different: + changes.append(f"[{field_label}] dari '{old_value}' ke '{new_value}'") + + if changes: + timestamp = fields.Datetime.now().strftime('%Y-%m-%d %H:%M:%S') + rec.change_log_688 = f"{timestamp} - Perubahan oleh Widya:\n" + "\n".join(changes) + + + @staticmethod + def _float_equal(val1, val2, eps=1e-6): + try: + return abs(float(val1 or 0.0) - float(val2 or 0.0)) < eps + except Exception: + return False + def _compute_grand_total(self): for rec in self: grand_total = sum(order.amount_total for order in rec.sale_order_ids) diff --git a/indoteknik_custom/views/approval_payment_term.xml b/indoteknik_custom/views/approval_payment_term.xml index 373637a2..cc9db914 100644 --- a/indoteknik_custom/views/approval_payment_term.xml +++ b/indoteknik_custom/views/approval_payment_term.xml @@ -21,6 +21,7 @@ + -- cgit v1.2.3