summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-12-16 10:16:23 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-12-16 10:16:23 +0700
commitcac17b71c07892411128a00f158a45af19344e98 (patch)
tree2c13a8098a72e86eeb21b799036cf72cb2c3cc33
parent335d724a7f359223138de74bf682cfc3530b5ea7 (diff)
add check kredit limit on ask approve so
-rwxr-xr-xindoteknik_custom/models/sale_order.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 7fc6d96a..f5e7e8a1 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -758,6 +758,7 @@ class SaleOrder(models.Model):
raise UserError("Salesperson sudah tidak aktif, mohon diisi yang benar pada data SO dan Contact")
def sale_order_approve(self):
+ self.check_credit_limit()
if self.validate_different_vendor() and not self.vendor_approval:
return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor')
self.check_due()
@@ -890,6 +891,37 @@ class SaleOrder(models.Model):
'email_to': salesperson_email,
}).send()
+ def check_credit_limit(self):
+ for rec in self:
+ outstanding_amount = rec.outstanding_amount
+ check_credit_limit = False
+ ######
+ block_stage = 0
+ if rec.partner_id.parent_id:
+ if rec.partner_id.parent_id.active_limit and rec.partner_id.parent_id.enable_credit_limit:
+ check_credit_limit = True
+ else:
+ if rec.partner_id.active_limit and rec.partner_id.enable_credit_limit:
+ check_credit_limit = True
+
+ term_days = 0
+ for term_line in rec.payment_term_id.line_ids:
+ term_days += term_line.days
+ if term_days == 0:
+ check_credit_limit = False
+
+ if check_credit_limit:
+ if rec.partner_id.parent_id:
+ block_stage = rec.partner_id.parent_id.blocking_stage or 0
+ else:
+ block_stage = rec.partner_id.blocking_stage or 0
+
+ if (outstanding_amount + rec.amount_total) >= block_stage:
+ if block_stage != 0:
+ remaining_credit_limit = block_stage - outstanding_amount
+ raise UserError(_("%s is in Blocking Stage, Remaining credit limit is %s, from %s and outstanding %s")
+ % (rec.partner_id.name, remaining_credit_limit, block_stage, outstanding_amount))
+
def validate_different_vendor(self):
if self.vendor_approval_id.filtered(lambda v: v.state == 'draft'):
draft_names = ", ".join(self.vendor_approval_id.filtered(lambda v: v.state == 'draft').mapped('number'))