summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-02-07 14:24:02 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-02-07 14:24:02 +0700
commit3187466a66abb41931e346e7865dfa6432f3da9e (patch)
treeb33369459860851c46f2b428d87a7395148a76fa
parent62c558bf0f97121f804762780374f44adfb0406e (diff)
<iman> add chek kredit limit tapi ditambah dengan so yang to invoice
-rwxr-xr-xindoteknik_custom/models/sale_order.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 4bdd9f2c..0d2e42cb 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -768,6 +768,7 @@ class SaleOrder(models.Model):
def sale_order_approve(self):
self.check_credit_limit()
+ self.check_limit_so_to_invoice()
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()
@@ -826,6 +827,7 @@ class SaleOrder(models.Model):
return self._create_approval_notification('Pimpinan')
elif order._requires_approval_margin_manager():
self.check_credit_limit()
+ self.check_limit_so_to_invoice()
order.approval_status = 'pengajuan1'
return self._create_approval_notification('Sales Manager')
@@ -932,6 +934,28 @@ class SaleOrder(models.Model):
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 check_limit_so_to_invoice(self):
+ for rec in self:
+ # Ambil jumlah outstanding_amount dan rec.amount_total sebagai current_total
+ outstanding_amount = rec.outstanding_amount
+ current_total = rec.amount_total + outstanding_amount
+
+ # Ambil blocking stage dari partner
+ block_stage = rec.partner_id.parent_id.blocking_stage if rec.partner_id.parent_id else rec.partner_id.blocking_stage or 0
+
+ # Ambil jumlah nilai dari SO yang invoice_status masih 'to invoice'
+ so_to_invoice = 0
+ for sale in rec.partner_id.sale_order_ids:
+ if sale.invoice_status == 'to invoice':
+ so_to_invoice = so_to_invoice + sale.amount_total
+ # Hitung remaining credit limit
+ remaining_credit_limit = block_stage - current_total - so_to_invoice
+
+ # Validasi limit
+ if remaining_credit_limit <= 0:
+ raise UserError(_("The credit limit for %s will exceed the Blocking Stage if the Sale Order is confirmed. The remaining credit limit is %s, from %s and the outstanding amount is %s.")
+ % (rec.partner_id.name, block_stage - current_total, 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'))
@@ -981,6 +1005,7 @@ class SaleOrder(models.Model):
def action_confirm(self):
for order in self:
order.check_credit_limit()
+ order.check_limit_so_to_invoice()
if self.validate_different_vendor() and not self.vendor_approval:
return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor')