diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-08-29 10:52:19 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-08-29 10:52:19 +0700 |
| commit | 101948d6029b06a69759b8f246f1744312f035c0 (patch) | |
| tree | c3f181d9dee63064ce092a1bf2f0cb3fb406aa65 | |
| parent | 0112ac064a7484685119cf9371ffbea32de6fd59 (diff) | |
(andri) add is locked CBD jika ada customer yang sudah jatuh tempo
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 28 | ||||
| -rw-r--r-- | indoteknik_custom/models/approval_payment_term.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 15 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 9 | ||||
| -rw-r--r-- | indoteknik_custom/views/res_partner.xml | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 9 |
6 files changed, 59 insertions, 6 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index c44cad78..55e640e4 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -105,6 +105,34 @@ class AccountMove(models.Model): tracking=True ) + def _check_and_lock_cbd(self): + cbd_term = self.env['account.payment.term'].browse(26) + today = date.today() + + # Cari semua invoice overdue + overdue_invoices = self.search([ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), + ('invoice_date_due', '!=', False), + ('invoice_date_due', '<=', today - timedelta(days=30)), + ], limit=3) + + _logger.info(f"Found {len(overdue_invoices)} overdue invoices for CBD lock check.") + _logger.info(f"Overdue Invoices: {overdue_invoices.mapped('name')}") + + # Ambil partner unik dari invoice + partners_to_lock = overdue_invoices.mapped('partner_id').filtered(lambda p: not p.is_cbd_locked) + _logger.info(f"Partners to lock: {partners_to_lock.mapped('name')}") + + # Lock hanya partner yang belum locked + if partners_to_lock: + partners_to_lock.write({ + 'is_cbd_locked': True, + 'property_payment_term_id': cbd_term.id, + }) + + def compute_partial_payment(self): for move in self: if move.amount_total_signed > 0 and move.amount_residual_signed > 0 and move.payment_state == 'partial': diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py index 8618856a..08d91738 100644 --- a/indoteknik_custom/models/approval_payment_term.py +++ b/indoteknik_custom/models/approval_payment_term.py @@ -171,7 +171,8 @@ class ApprovalPaymentTerm(models.Model): 'blocking_stage': self.blocking_stage, 'warning_stage': self.warning_stage, 'active_limit': self.active_limit, - 'property_payment_term_id': self.property_payment_term_id.id + 'property_payment_term_id': self.property_payment_term_id.id, + 'is_locked_cbd': False, }) self.approve_date = datetime.utcnow() self.state = 'approved' diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 148a3fd0..017be730 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -1,6 +1,6 @@ from odoo import models, fields, api from odoo.exceptions import UserError, ValidationError -from datetime import datetime +from datetime import datetime, timedelta from odoo.http import request import re import requests @@ -181,10 +181,15 @@ class ResPartner(models.Model): payment_difficulty = fields.Selection([('bermasalah', 'Bermasalah'),('sulit', 'Sulit'),('agak_sulit', 'Agak Sulit'),('normal', 'Normal')], string='Payment Difficulty', tracking=3) payment_history_url = fields.Text(string='Payment History URL') - # no compute - # payment_diff = fields.Selection([('bermasalah', 'Bermasalah'),('sulit', 'Sulit'),('agak_sulit', 'Agak Sulit'),('normal', 'Normal')], string='Payment Difficulty', tracking=3) - - # tidak terpakai + is_cbd_locked = fields.Boolean("Locked to CBD?", default=False, tracking=True, help="Jika dicentang, maka partner ini terkunci pada payment term CBD karena memiliki invoice yang sudah jatuh tempo lebih dari 30 hari.") + + # centang manual is_cbd_locked jika payment term diubah ke CBD + @api.onchange('is_cbd_locked') + def _onchange_is_cbd_locked(self): + if self.is_cbd_locked: + cbd_term = self.env['account.payment.term'].browse(26) + if cbd_term: + self.property_payment_term_id = cbd_term.id @api.model def _default_payment_term(self): diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index ffb53dce..992c1a5d 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -394,6 +394,15 @@ class SaleOrder(models.Model): ('paid', 'Full Paid'), ('no_invoice', 'No Invoice'), ], string="Payment Status Invoice", compute="_compute_payment_state_custom", store=False) + partner_is_cbd_locked = fields.Boolean( + string="Partner Locked CBD", + compute="_compute_partner_is_cbd_locked" + ) + + @api.depends('partner_id.is_cbd_locked') + def _compute_partner_is_cbd_locked(self): + for order in self: + order.partner_is_cbd_locked = order.partner_id.is_cbd_locked @api.depends('invoice_ids.payment_state', 'invoice_ids.amount_total', 'invoice_ids.amount_residual') def _compute_payment_state_custom(self): diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml index ca1a36de..7541df35 100644 --- a/indoteknik_custom/views/res_partner.xml +++ b/indoteknik_custom/views/res_partner.xml @@ -21,6 +21,7 @@ <field name="reference_number"/> </field> <field name="property_payment_term_id" position="after"> + <field name="is_cbd_locked" readonly="1"/> <field name="user_payment_terms_sales" readonly="1"/> <field name="date_payment_terms_sales" readonly="1"/> </field> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index a1a5e0cd..29d1a980 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -42,6 +42,15 @@ class="btn-primary" attrs="{'invisible': ['|', ('state', 'not in', ['sale', 'done']), ('has_refund', '=', True)]}" /> </xpath> --> + <xpath expr="//sheet" position="before"> + <field name="partner_is_cbd_locked" invisible="1"/> + <div class="alert alert-danger" + role="alert" + style="height: 40px; margin-bottom:0px;" + attrs="{'invisible':[('partner_is_cbd_locked','=',False)]}"> + <strong>Warning!</strong> Payment Terms Customer terkunci menjadi Cash Before Delivery (C.B.D.) karena ada invoice telah jatuh tempo 30 hari. Silakan ajukan Approval Payment Term untuk membuka kunci. + </div> + </xpath> <div class="oe_button_box" name="button_box"> <field name="advance_payment_move_ids" invisible="1"/> <button name="action_open_advance_payment_moves" |
