diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-01-14 09:31:44 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-01-14 09:31:44 +0700 |
| commit | 183cd9e68ea05e31c63000aeb992eb618edb02b5 (patch) | |
| tree | 45d710db372c2a0eba437a0137cbb74d9935a7f2 /indoteknik_custom/models/sale_order.py | |
| parent | 63878bd84a6eb9094e702963d7c78fcd8dfa1808 (diff) | |
| parent | 6dda865a1b3262ce78ed2db024fd03efb091d6a6 (diff) | |
Merge branch 'odoo-production' into feature/integrasi_biteship
# Conflicts:
# indoteknik_custom/__manifest__.py
# indoteknik_custom/models/__init__.py
# indoteknik_custom/security/ir.model.access.csv
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 7fc6d96a..7b2d9bf8 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')) @@ -999,8 +1031,9 @@ class SaleOrder(models.Model): if self.have_outstanding_invoice: raise UserError("Invoice harus di Cancel dahulu") - elif self.have_outstanding_picking: - raise UserError("DO harus di Cancel dahulu") + for line in self.order_line: + if line.qty_delivered > 0: + raise UserError("DO harus di-cancel terlebih dahulu.") if not self.web_approval: self.web_approval = 'company' @@ -1378,4 +1411,16 @@ class SaleOrder(models.Model): 'npwp': partner.npwp, 'email': partner.email, 'customer_type': partner.customer_type, - })
\ No newline at end of file + }) + + def write(self, vals): + for order in self: + if order.state in ['sale', 'cancel']: + if 'order_line' in vals: + new_lines = vals.get('order_line', []) + for command in new_lines: + if command[0] == 0: # A new line is being added + raise UserError( + "SO tidak dapat ditambahkan produk baru karena SO sudah menjadi sale order.") + res = super(SaleOrder, self).write(vals) + return res
\ No newline at end of file |
