From 292ce85b0e841f14e41a35ff7fad420009b6b600 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 7 Jul 2023 14:14:49 +0700 Subject: count due --- .../models/account_move_due_extension.py | 56 +++++++++++++--------- indoteknik_custom/models/res_partner.py | 1 + indoteknik_custom/views/account_move_views.xml | 1 + indoteknik_custom/views/res_partner.xml | 1 + 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/indoteknik_custom/models/account_move_due_extension.py b/indoteknik_custom/models/account_move_due_extension.py index 93dfe62b..1e3bdad1 100644 --- a/indoteknik_custom/models/account_move_due_extension.py +++ b/indoteknik_custom/models/account_move_due_extension.py @@ -27,6 +27,11 @@ class DueExtension(models.Model): ('7', '7 Hari'), ('14', '14 Hari'), ], string='Day Extension', help='Menambah Due Date yang sudah limit dari hari ini', tracking=True) + counter = fields.Integer(string="Counter", compute='_compute_counter') + + def _compute_counter(self): + for due in self: + due.counter = due.partner_id.counter @api.model def create(self, vals): @@ -58,32 +63,37 @@ class DueExtension(models.Model): def approve_new_due(self): if self.env.user.is_accounting: - self.is_approve = True - self.approval_status = 'approved' + if not self.approval_status == 'approved': + self.is_approve = True + self.approval_status = 'approved' + + self.partner_id.counter+=1 - if self.partner_id: - if self.day_extension: - day_extension = int(self.day_extension) - new_due = date.today() + timedelta(days=day_extension) + if self.partner_id: + if self.day_extension: + day_extension = int(self.day_extension) + new_due = date.today() + timedelta(days=day_extension) + + for line in self.due_line: + line.invoice_id.invoice_date_due = new_due - for line in self.due_line: - line.invoice_id.invoice_date_due = new_due - - if self.order_id._notification_margin_leader(): - self.order_id.approval_status = 'pengajuan2' - return self.order_id._notification_has_margin_leader() + if self.order_id._notification_margin_leader(): + self.order_id.approval_status = 'pengajuan2' + return self.order_id._notification_has_margin_leader() - if self.order_id._notification_margin_manager(): - self.order_id.approval_status = 'pengajuan1' - return self.order_id._notification_has_margin_manager() - - sales = self.env['sale.order'].search([ - ('id', '=', self.order_id.id) - ]) - - # sales.state = 'sale' - sales.action_confirm() - self.order_id.due_id = self.id + if self.order_id._notification_margin_manager(): + self.order_id.approval_status = 'pengajuan1' + return self.order_id._notification_has_margin_manager() + + sales = self.env['sale.order'].search([ + ('id', '=', self.order_id.id) + ]) + + # sales.state = 'sale' + sales.action_confirm() + self.order_id.due_id = self.id + else: + raise UserError('Document ini sudah di approve') else: raise UserError('Hanya Finance Yang Bisa Approve') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index bdeb8a2c..5dec8da8 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -18,6 +18,7 @@ class ResPartner(models.Model): ('nonpkp', 'Non PKP') ]) sppkp = fields.Char(string="SPPKP") + counter = fields.Integer(string="Counter", default=0) def unlink(self): if self._name == 'res.partner': diff --git a/indoteknik_custom/views/account_move_views.xml b/indoteknik_custom/views/account_move_views.xml index 02926682..983fbd5a 100644 --- a/indoteknik_custom/views/account_move_views.xml +++ b/indoteknik_custom/views/account_move_views.xml @@ -61,6 +61,7 @@ + diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml index c77d942b..d609fdd5 100644 --- a/indoteknik_custom/views/res_partner.xml +++ b/indoteknik_custom/views/res_partner.xml @@ -8,6 +8,7 @@ + -- cgit v1.2.3