summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-07-12 09:03:33 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-07-12 09:03:33 +0700
commitf9874dc8419c35737fb96b8aa8480f0d60e47e1d (patch)
treef39312737e19e0841cc02e82dd196826a26eccb4
parentba2bd3f91857cf6085eb760451ec695182dd1a3a (diff)
revisi due extension
-rw-r--r--indoteknik_custom/models/account_move.py7
-rw-r--r--indoteknik_custom/models/account_move_due_extension.py19
-rwxr-xr-xindoteknik_custom/models/sale_order.py51
-rw-r--r--indoteknik_custom/views/account_move.xml2
4 files changed, 52 insertions, 27 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index c2e93632..0f021e6b 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -13,6 +13,8 @@ class AccountMove(models.Model):
resi_tukar_faktur = fields.Char(string='Resi Faktur')
date_terima_tukar_faktur = fields.Date(string='Terima Faktur')
shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur')
+ due_extension = fields.Integer(string='Due Extension', default=0)
+ new_due_date = fields.Date(string='New Due')
def unlink(self):
res = super(AccountMove, self).unlink()
@@ -69,7 +71,10 @@ class AccountMove(models.Model):
for invoice in self:
invoice_day_to_due = 0
if invoice.payment_state not in ['paid', 'in_payment', 'reversed'] and invoice.invoice_date_due:
- invoice_day_to_due = invoice.invoice_date_due - date.today()
+ if invoice.new_due_date:
+ invoice_day_to_due = invoice.new_due_date - date.today()
+ elif not invoice.new_due_date:
+ invoice_day_to_due = invoice.invoice_date_due - date.today()
invoice_day_to_due = invoice_day_to_due.days
invoice.invoice_day_to_due = invoice_day_to_due
diff --git a/indoteknik_custom/models/account_move_due_extension.py b/indoteknik_custom/models/account_move_due_extension.py
index 1e3bdad1..d767917b 100644
--- a/indoteknik_custom/models/account_move_due_extension.py
+++ b/indoteknik_custom/models/account_move_due_extension.py
@@ -74,8 +74,15 @@ class DueExtension(models.Model):
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.new_due_date = new_due
+
+ if self.day_extension == '3':
+ line.invoice_id.due_extension = 3
+ elif self.day_extension == '7':
+ line.invoice_id.due_extension = 7
+ elif self.day_extension == '14':
+ line.invoice_id.due_extension = 14
if self.order_id._notification_margin_leader():
self.order_id.approval_status = 'pengajuan2'
@@ -123,8 +130,7 @@ class DueExtension(models.Model):
'efaktur_id': invoice.efaktur_id.id,
'reference': invoice.ref,
'total_amt': invoice.amount_total,
- 'open_amt': invoice.amount_residual_signed,
- 'due_date': invoice.invoice_date_due
+ 'open_amt': invoice.amount_residual_signed
}])
count += 1
_logger.info("Due Extension Line generated %s" % count)
@@ -157,5 +163,8 @@ class DueExtensionLine(models.Model):
def _compute_due_date(self):
for line in self:
- line.due_date = line.invoice_id.invoice_date_due
+ if line.invoice_id.new_due_date:
+ line.due_date = line.invoice_id.new_due_date
+ else:
+ line.due_date = line.invoice_id.invoice_date_due
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 5a3cada9..7c60d20c 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -8,6 +8,7 @@ import string
import requests
import math
import json
+from datetime import timedelta, date
_logger = logging.getLogger(__name__)
@@ -389,27 +390,35 @@ class SaleOrder(models.Model):
if self.due_id and self.due_id.is_approve == False:
raise UserError('Document Over Due Yang Anda Buat Belum Di Approve')
- if not self.env.user.is_leader and not self.env.user.is_sales_manager:
- query = [
- ('partner_id', '=', parent_id),
- ('state', '=', 'posted'),
- ('move_type', '=', 'out_invoice'),
- ('amount_residual_signed', '>', 0)
- ]
- invoices = self.env['account.move'].search(query, order='invoice_date')
- due_extension = self.env['due.extension'].create([{
- 'partner_id': parent_id,
- 'day_extension': '3',
- 'order_id': self.id,
- }])
- due_extension.generate_due_line()
- self.due_id = due_extension.id
- if len(self.due_id.due_line) > 0:
- return True
- else:
- due_extension.unlink()
- return False
-
+ query = [
+ ('partner_id', '=', parent_id),
+ ('state', '=', 'posted'),
+ ('move_type', '=', 'out_invoice'),
+ ('amount_residual_signed', '>', 0)
+ ]
+ invoices = self.env['account.move'].search(query, order='invoice_date')
+
+ for invoice in invoices:
+ invoice_due_extension = invoice.due_extension
+ new_due = invoice.invoice_date_due + timedelta(days=invoice_due_extension)
+
+ current_time = date.today()
+ if invoices:
+ if current_time > new_due:
+ if not self.env.user.is_leader and not self.env.user.is_sales_manager:
+ due_extension = self.env['due.extension'].create([{
+ 'partner_id': parent_id,
+ 'day_extension': '3',
+ 'order_id': self.id,
+ }])
+ due_extension.generate_due_line()
+ self.due_id = due_extension.id
+ if len(self.due_id.due_line) > 0:
+ return True
+ else:
+ due_extension.unlink()
+ return False
+
def _notification_margin_leader(self):
if self.total_percent_margin <= 15 and not self.env.user.is_leader:
return True
diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml
index 9faf3149..30f0eca9 100644
--- a/indoteknik_custom/views/account_move.xml
+++ b/indoteknik_custom/views/account_move.xml
@@ -15,6 +15,7 @@
<field name="shipper_faktur_id"/>
<field name="resi_tukar_faktur"/>
<field name="date_terima_tukar_faktur"/>
+ <field name="due_extension"/>
</field>
</field>
</record>
@@ -30,6 +31,7 @@
</field>
<field name="invoice_date_due" position="after">
<field name="invoice_day_to_due" attrs="{'invisible': [['payment_state', 'in', ('paid', 'in_payment', 'reversed')]]}"/>
+ <field name="due_extension"/>
</field>
<field name="payment_state" position="after">
<field name="invoice_payment_term_id"/>