summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/account_move.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-11-19 14:49:01 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-11-19 14:49:01 +0700
commitbb2be920076aabc49b4f9fdd896d14e096e633eb (patch)
tree588196ba53fb7e41d96a61272bdb74b4821fe661 /indoteknik_custom/models/account_move.py
parent9c4f131ffaf37ca47a78b320a68f7de4e846ecfb (diff)
parent58623e9509789381dbe334969de647b4ad0302a4 (diff)
Merge branch 'odoo-backup' into locatorlocator
# Conflicts: # indoteknik_custom/models/__init__.py # indoteknik_custom/models/stock_move.py # indoteknik_custom/security/ir.model.access.csv # indoteknik_custom/views/stock_picking.xml
Diffstat (limited to 'indoteknik_custom/models/account_move.py')
-rw-r--r--indoteknik_custom/models/account_move.py53
1 files changed, 48 insertions, 5 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 44b3cb76..6212664e 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -3,7 +3,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError
from markupsafe import escape as html_escape
from datetime import timedelta, date, datetime
from pytz import timezone, utc
-import logging
+import logging, json
import base64
import PyPDF2
import os
@@ -11,6 +11,7 @@ import re
from terbilang import Terbilang
from collections import defaultdict
from odoo.tools.misc import formatLang
+import socket
_logger = logging.getLogger(__name__)
@@ -32,7 +33,6 @@ class AccountMove(models.Model):
new_due_date = fields.Date(string='New Due')
counter = fields.Integer(string="Counter", default=0)
cost_centre_id = fields.Many2one('cost.centre', string='Cost Centre')
- analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account')
due_line = fields.One2many('due.extension.line', 'invoice_id', compute='_compute_due_line', string='Due Extension Lines')
no_faktur_pajak = fields.Char(string='No Faktur Pajak')
date_completed = fields.Datetime(string='Date Completed')
@@ -106,6 +106,32 @@ class AccountMove(models.Model):
help="Tanggal janji bayar dari customer setelah reminder dikirim.",
tracking=True
)
+ internal_notes_contact = fields.Text(related='partner_id.comment', string="Internal Notes", readonly=True, help="Internal Notes dari contact utama customer.")
+
+ payment_info = fields.Text(
+ string="Payment Info",
+ compute='_compute_payment_info',
+ store=False,
+ help="Informasi pembayaran yang diambil dari payment yang sudah direkonsiliasi ke invoice ini."
+ )
+
+ def _compute_payment_info(self):
+ for rec in self:
+ summary = ""
+ try:
+ widget_data = rec.invoice_payments_widget
+ if widget_data:
+ data = json.loads(widget_data)
+ lines = []
+ for item in data.get('content', []):
+ amount = item.get('amount', 0.0)
+ date = item.get('date') or item.get('payment_date') or ''
+ formatted_amount = formatLang(self.env, amount, currency_obj=rec.currency_id)
+ lines.append(f"<li><i>Paid on {date}</i> - {formatted_amount}</li>")
+ summary = f"<ul>{''.join(lines)}</ul>" if lines else (data.get('title', '') or "")
+ except Exception:
+ summary = ""
+ rec.payment_info = summary
# def _check_and_lock_cbd(self):
# cbd_term = self.env['account.payment.term'].browse(26)
@@ -160,7 +186,8 @@ class AccountMove(models.Model):
def action_sync_promise_date(self):
self.ensure_one()
finance_user_ids = [688]
- if self.env.user.id not in finance_user_ids:
+ is_it = self.env.user.has_group('indoteknik_custom.group_role_it')
+ if self.env.user.id not in finance_user_ids and not is_it:
raise UserError('Hanya Finance (Widya) yang dapat menggunakan fitur ini.')
if not self.customer_promise_date:
raise UserError("Isi Janji Bayar terlebih dahulu sebelum melakukan sinkronisasi.")
@@ -168,10 +195,11 @@ class AccountMove(models.Model):
other_invoices = self.env['account.move'].search([
('id', '!=', self.id),
('partner_id', '=', self.partner_id.id),
- ('invoice_date_due', '=', self.invoice_date_due),
+ ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']),
('move_type', '=', 'out_invoice'),
('state', '=', 'posted'),
- ('date_terima_tukar_faktur', '!=', False)
+ ('date_terima_tukar_faktur', '!=', False),
+ ('invoice_payment_term_id.name', 'ilike', 'tempo')
])
lines = []
for inv in other_invoices:
@@ -191,7 +219,16 @@ class AccountMove(models.Model):
'target': 'new',
}
+ @staticmethod
+ def is_local_env():
+ hostname = socket.gethostname().lower()
+ keywords = ['andri', 'miqdad', 'fin', 'stephan', 'hafid', 'nathan']
+ return any(keyword in hostname for keyword in keywords)
+
def send_due_invoice_reminder(self):
+ if self.is_local_env():
+ _logger.warning("📪 Local environment detected — skip sending email reminders.")
+ return
today = fields.Date.today()
target_dates = [
today + timedelta(days=7),
@@ -213,6 +250,9 @@ class AccountMove(models.Model):
self._send_invoice_reminders(invoices, mode='due')
def send_overdue_invoice_reminder(self):
+ if self.is_local_env():
+ _logger.warning("📪 Local environment detected — skip sending email reminders.")
+ return
today = fields.Date.today()
invoices = self.env['account.move'].search([
('move_type', '=', 'out_invoice'),
@@ -228,6 +268,9 @@ class AccountMove(models.Model):
self._send_invoice_reminders(invoices, mode='overdue')
def _send_invoice_reminders(self, invoices, mode):
+ if self.is_local_env():
+ _logger.warning("📪 Local environment detected — skip sending email reminders.")
+ return
today = fields.Date.today()
template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder')