From b1c7b43c51c670e42a0dd2399139fbd9a600f121 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 24 Jul 2025 16:16:36 +0700 Subject: is disc item from web --- indoteknik_custom/models/sale_order_line.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 5e9fc362..f2799319 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -1,6 +1,9 @@ from odoo import fields, models, api, _ from odoo.exceptions import UserError from datetime import datetime, timedelta +import logging + +__logger = logging.getLogger(__name__) class SaleOrderLine(models.Model): @@ -49,6 +52,17 @@ class SaleOrderLine(models.Model): qty_free_bu = fields.Float(string='Free BU', compute='_get_qty_free_bandengan') desc_updatable = fields.Boolean(string='desc boolean', default=True, compute='_get_desc_updatable') + is_has_disc = fields.Boolean('FlashSale Item', compute='_compute_is_has_disc', default=False) + + @api.depends('discount', 'order_id.source_id') + def _compute_is_has_disc(self): + for line in self: + line.is_has_disc = ( + line.discount > 0 and + line.order_id.source_id and + line.order_id.source_id.id == 59 + ) + def _get_outgoing_incoming_moves(self): outgoing_moves = self.env['stock.move'] incoming_moves = self.env['stock.move'] -- cgit v1.2.3 From ae201ad5ac392a75da087a5e1215f9b8fcd50dba Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 26 Jul 2025 12:35:36 +0700 Subject: push --- indoteknik_custom/models/sale_order_line.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index f2799319..bc1fcd09 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -54,14 +54,29 @@ class SaleOrderLine(models.Model): is_has_disc = fields.Boolean('FlashSale Item', compute='_compute_is_has_disc', default=False) - @api.depends('discount', 'order_id.source_id') + @api.depends('product_id', 'price_unit', 'order_id.source_id') def _compute_is_has_disc(self): + website_source_id = 59 + excluded_pricelist_ids = [17022, 17027, 17026, 17025, 17024, 17023] + for line in self: - line.is_has_disc = ( - line.discount > 0 and - line.order_id.source_id and - line.order_id.source_id.id == 59 - ) + line.is_has_disc = False # default + + # Step 1: Bukan dari website? Skip + if not line.order_id.source_id or line.order_id.source_id.id != website_source_id: + continue + + # Step 2: Ambil semua pricelist item berdasarkan produk + pricelist_items = self.env['product.pricelist.item'].search([ + ('product_id', '=', line.product_id.id), + ('pricelist_id', 'not in', excluded_pricelist_ids), + ]) + + # Step 3: Jika ada pricelist_items, tandai sebagai flashsale + if pricelist_items: + line.is_has_disc = True + elif not pricelist_items: + line.is_has_disc = False def _get_outgoing_incoming_moves(self): outgoing_moves = self.env['stock.move'] -- cgit v1.2.3 From 0c5486d6e67cd8bab4913dd177ed9ddf0be36d60 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 26 Jul 2025 13:32:59 +0700 Subject: fix user cannot access delivery tukar guling --- indoteknik_custom/models/tukar_guling.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 43bc156e..26b98e32 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -386,14 +386,23 @@ class TukarGuling(models.Model): def action_view_picking(self): self.ensure_one() - action = self.env.ref('stock.action_picking_tree_all').read()[0] - pickings = self.picking_ids - if len(pickings) > 1: - action['domain'] = [('id', 'in', pickings.ids)] - elif pickings: - action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')] - action['res_id'] = pickings.id - return action + + # picking_origin = f"Return of {self.operations.name}" + returs = self.env['stock.picking'].search([ + ('tukar_guling_id', '=', self.id), + ]) + + if not returs: + raise UserError("Doc Retrun Not Found") + + return { + 'type': 'ir.actions.act_window', + 'name': 'Delivery Pengajuan Retur SO', + 'res_model': 'stock.picking', + 'view_mode': 'tree,form', + 'domain': [('id', 'in', returs.ids)], + 'target': 'current', + } def action_draft(self): """Reset to draft state""" -- cgit v1.2.3 From 83c6a567c1e2f1b8c281ea405732a286cb20a8c9 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 26 Jul 2025 13:34:00 +0700 Subject: fix user cannot access delivery tukar guling --- indoteknik_custom/models/tukar_guling_po.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 14f2cc96..fced7fdb 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -320,14 +320,23 @@ class TukarGulingPO(models.Model): def action_view_picking(self): self.ensure_one() - action = self.env.ref('stock.action_picking_tree_all').read()[0] - pickings = self.po_picking_ids - if len(pickings) > 1: - action['domain'] = [('id', 'in', pickings.ids)] - elif pickings: - action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')] - action['res_id'] = pickings.id - return action + + # picking_origin = f"Return of {self.operations.name}" + returs = self.env['stock.picking'].search([ + ('tukar_guling_po_id', '=', self.id), + ]) + + if not returs: + raise UserError("Doc Retrun Not Found") + + return { + 'type': 'ir.actions.act_window', + 'name': 'Delivery Pengajuan Retur PO', + 'res_model': 'stock.picking', + 'view_mode': 'tree,form', + 'domain': [('id', 'in', returs.ids)], + 'target': 'current', + } def action_draft(self): """Reset to draft state""" -- cgit v1.2.3 From aeb450314a0440806ceb300c71c5776d42289ad4 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 26 Jul 2025 21:02:52 +0700 Subject: push --- indoteknik_custom/models/sale_order_line.py | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index bc1fcd09..ff2e9009 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -2,8 +2,9 @@ from odoo import fields, models, api, _ from odoo.exceptions import UserError from datetime import datetime, timedelta import logging +from odoo.tools.float_utils import float_compare -__logger = logging.getLogger(__name__) +_logger = logging.getLogger(__name__) class SaleOrderLine(models.Model): @@ -52,31 +53,8 @@ class SaleOrderLine(models.Model): qty_free_bu = fields.Float(string='Free BU', compute='_get_qty_free_bandengan') desc_updatable = fields.Boolean(string='desc boolean', default=True, compute='_get_desc_updatable') - is_has_disc = fields.Boolean('FlashSale Item', compute='_compute_is_has_disc', default=False) + is_has_disc = fields.Boolean('FlashSale Item', default=False) - @api.depends('product_id', 'price_unit', 'order_id.source_id') - def _compute_is_has_disc(self): - website_source_id = 59 - excluded_pricelist_ids = [17022, 17027, 17026, 17025, 17024, 17023] - - for line in self: - line.is_has_disc = False # default - - # Step 1: Bukan dari website? Skip - if not line.order_id.source_id or line.order_id.source_id.id != website_source_id: - continue - - # Step 2: Ambil semua pricelist item berdasarkan produk - pricelist_items = self.env['product.pricelist.item'].search([ - ('product_id', '=', line.product_id.id), - ('pricelist_id', 'not in', excluded_pricelist_ids), - ]) - - # Step 3: Jika ada pricelist_items, tandai sebagai flashsale - if pricelist_items: - line.is_has_disc = True - elif not pricelist_items: - line.is_has_disc = False def _get_outgoing_incoming_moves(self): outgoing_moves = self.env['stock.move'] -- cgit v1.2.3 From e2c727fc2d1a2c9c3601368df7d4701d9b71fb82 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 28 Jul 2025 08:46:21 +0700 Subject: done(?) --- indoteknik_custom/models/sale_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index ff2e9009..428e1a9c 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -53,7 +53,7 @@ class SaleOrderLine(models.Model): qty_free_bu = fields.Float(string='Free BU', compute='_get_qty_free_bandengan') desc_updatable = fields.Boolean(string='desc boolean', default=True, compute='_get_desc_updatable') - is_has_disc = fields.Boolean('FlashSale Item', default=False) + is_has_disc = fields.Boolean('Website Disc?', default=False) def _get_outgoing_incoming_moves(self): -- cgit v1.2.3 From 9a01c7f11c128380c367bb479ef2b33b2c445ea7 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 28 Jul 2025 10:28:29 +0700 Subject: fix validation tukar guling --- indoteknik_custom/models/tukar_guling.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 26b98e32..396e4db4 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -281,11 +281,11 @@ class TukarGuling(models.Model): return True - def _is_already_returned(self, picking): - return self.env['stock.picking'].search_count([ - ('origin', '=', 'Return of %s' % picking.name), - ('state', '!=', 'cancel') - ]) > 0 + # def _is_already_returned(self, picking): + # return self.env['stock.picking'].search_count([ + # ('origin', '=', 'Return of %s' % picking.name), + # ('state', '!=', 'cancel') + # ]) > 0 @api.constrains('return_type', 'operations') def _check_invoice_on_revisi_so(self): @@ -443,8 +443,8 @@ class TukarGuling(models.Model): linked_bu_out = picking.linked_manual_bu_out if linked_bu_out and linked_bu_out.state == 'done': raise UserError("❌ Tidak bisa retur BU/PICK karena BU/OUT suda Done!") - if self._is_already_returned(self.operations): - raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") + # if self._is_already_returned(self.operations): + # raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") if self.operations.picking_type_id.id == 29: for line in self.line_ids: -- cgit v1.2.3 From 84c8e3f8494971a26ed8e303d8584a3caaaa5859 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 28 Jul 2025 10:37:39 +0700 Subject: fix validation tukar guling --- indoteknik_custom/models/tukar_guling_po.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index fced7fdb..11377bc4 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -245,12 +245,12 @@ class TukarGulingPO(models.Model): return True - def _is_already_returned(self, picking): - return self.env['stock.picking'].search_count([ - ('origin', '=', 'Return of %s' % picking.name), - # ('returned_from_id', '=', picking.id), - ('state', 'not in', ['cancel', 'draft']), - ]) > 0 + # def _is_already_returned(self, picking): + # return self.env['stock.picking'].search_count([ + # ('origin', '=', 'Return of %s' % picking.name), + # # ('returned_from_id', '=', picking.id), + # ('state', 'not in', ['cancel', 'draft']), + # ]) > 0 def copy(self, default=None): if default is None: @@ -374,8 +374,8 @@ class TukarGulingPO(models.Model): if pick_id not in [75, 28]: raise UserError("❌ Tidak bisa retur bukan BU/INPUT atau BU/PUT!") - if self._is_already_returned(self.operations): - raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") + # if self._is_already_returned(self.operations): + # raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") if self.state != 'draft': raise UserError("Submit hanya bisa dilakukan dari Draft.") -- cgit v1.2.3 From d5eb5c9139f016498cc70d6f241b8597b0b4b06b Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 28 Jul 2025 11:05:50 +0700 Subject: push --- indoteknik_custom/models/sale_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 428e1a9c..64b9f9bc 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -53,7 +53,7 @@ class SaleOrderLine(models.Model): qty_free_bu = fields.Float(string='Free BU', compute='_get_qty_free_bandengan') desc_updatable = fields.Boolean(string='desc boolean', default=True, compute='_get_desc_updatable') - is_has_disc = fields.Boolean('Website Disc?', default=False) + is_has_disc = fields.Boolean('Flash Sale', default=False) def _get_outgoing_incoming_moves(self): -- cgit v1.2.3 From 3df417568e6efe97b9c8e3d2752e13f584802d71 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 28 Jul 2025 14:58:11 +0700 Subject: fix bug manufacturing --- indoteknik_custom/models/mrp_production.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/mrp_production.py b/indoteknik_custom/models/mrp_production.py index 7977bdf7..91da0597 100644 --- a/indoteknik_custom/models/mrp_production.py +++ b/indoteknik_custom/models/mrp_production.py @@ -156,7 +156,7 @@ class MrpProduction(models.Model): 'order_id': new_po.id }]) - new_po.button_confirm() + # new_po.button_confirm() self.is_po = True @@ -247,7 +247,7 @@ class CheckBomProduct(models.Model): @api.constrains('production_id', 'product_id') def _check_product_bom_validation(self): for record in self: - if record.production_id.sale_order.state not in ['sale', 'done']: + if record.production_id.sale_order and record.production_id.sale_order.state not in ['sale', 'done']: raise UserError(( "SO harus diconfirm terlebih dahulu." )) @@ -273,13 +273,13 @@ class CheckBomProduct(models.Model): if existing_lines: total_quantity = sum(existing_lines.mapped('quantity')) - if total_quantity < total_qty_in_moves: + if total_quantity > total_qty_in_moves: raise UserError(( "Quantity Product '%s' kurang dari quantity demand." ) % (record.product_id.display_name)) else: # Check if the quantity exceeds the allowed total - if record.quantity < total_qty_in_moves: + if record.quantity > total_qty_in_moves: raise UserError(( "Quantity Product '%s' kurang dari quantity demand." ) % (record.product_id.display_name)) -- cgit v1.2.3 From 74953e4b98abca66898426586907a6ed22ef4139 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 28 Jul 2025 15:20:43 +0700 Subject: (andri) add flag reminder invoices di contact company --- indoteknik_custom/models/res_partner.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 236df16f..d1d4ca02 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -27,6 +27,11 @@ class ResPartner(models.Model): # Referensi supplier_ids = fields.Many2many('user.pengajuan.tempo.line', string="Suppliers") + reminder_invoices = fields.Boolean( + string='Reminder Invoice', + help='Centang jika kontak ini harus menerima email pengingat invoice.', default=False + ) + # informasi perusahaan name_tempo = fields.Many2one('res.partner', string='Nama Perusahaan',tracking=True) industry_id_tempo = fields.Many2one('res.partner.industry', 'Customer Industry', readonly=True) -- cgit v1.2.3 From 8628973dfbfc76f3f7fea5a01d5ccad4998f7f3f Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 28 Jul 2025 15:37:22 +0700 Subject: (andri) fix send due invoices reminder --- indoteknik_custom/models/account_move.py | 203 ++++++++++++++++--------------- indoteknik_custom/models/res_partner.py | 2 +- 2 files changed, 108 insertions(+), 97 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 1a6fad1c..14927bec 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -109,102 +109,113 @@ class AccountMove(models.Model): # result.append((move.id, move.display_name)) # return result - # def send_due_invoice_reminder(self): - # today = fields.Date.today() - # target_dates = [ - # today - timedelta(days=7), - # today - timedelta(days=3), - # today, - # today + timedelta(days=3), - # today + timedelta(days=7), - # ] - - # partner = self.env['res.partner'].search([('name', 'ilike', 'BANGUNAN TEKNIK GRUP')], limit=1) - # if not partner: - # _logger.info("Partner tidak ditemukan.") - # return - - # invoices = self.env['account.move'].search([ - # ('move_type', '=', 'out_invoice'), - # ('state', '=', 'posted'), - # ('payment_state', 'not in', ['paid','in_payment', 'reversed']), - # ('invoice_date_due', 'in', target_dates), - # ('partner_id', '=', partner.id), - # ]) - - # _logger.info(f"Invoices tahap 1: {invoices}") - - # invoices = invoices.filtered( - # lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() - # ) - # _logger.info(f"Invoices tahap 2: {invoices}") - - # if not invoices: - # _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") - # return - - # grouped = {} - # for inv in invoices: - # grouped.setdefault(inv.partner_id, []).append(inv) - - # template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') - - # for partner, invs in grouped.items(): - # if not partner.email: - # _logger.info(f"Partner {partner.name} tidak memiliki email") - # continue - - # invoice_table_rows = "" - # for inv in invs: - # days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 - # invoice_table_rows += f""" - # - # {inv.name} - # {fields.Date.to_string(inv.invoice_date) or '-'} - # {fields.Date.to_string(inv.invoice_date_due) or '-'} - # {days_to_due} - # {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} - # {inv.ref or '-'} - # - # """ - - # subject = f"Reminder Invoice Due - {partner.name}" - # body_html = re.sub( - # r"]*>.*?", - # f"{invoice_table_rows}", - # template.body_html, - # flags=re.DOTALL - # ).replace('${object.name}', partner.name) \ - # .replace('${object.partner_id.name}', partner.name) - # # .replace('${object.email}', partner.email or '') - - # values = { - # 'subject': subject, - # 'email_to': 'andrifebriyadiputra@gmail.com', # Ubah ke partner.email untuk produksi - # 'email_from': 'finance@indoteknik.co.id', - # 'body_html': body_html, - # 'reply_to': f'invoice+account.move_{invs[0].id}@indoteknik.co.id', - # } - - # _logger.info(f"VALUES: {values}") - - # template.send_mail(invs[0].id, force_send=True, email_values=values) - - # # Default System User - # user_system = self.env['res.users'].browse(25) - # system_id = user_system.partner_id.id if user_system else False - # _logger.info(f"System User: {user_system.name} ({user_system.id})") - # _logger.info(f"System User ID: {system_id}") - - # for inv in invs: - # inv.message_post( - # subject=subject, - # body=body_html, - # subtype_id=self.env.ref('mail.mt_note').id, - # author_id=system_id, - # ) - - # _logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice") + def send_due_invoice_reminder(self): + today = fields.Date.today() + target_dates = [ + today - timedelta(days=7), + today - timedelta(days=3), + today, + today + timedelta(days=3), + today + timedelta(days=7), + ] + + # Contoh khusus partner tertentu + partner = self.env['res.partner'].search([('name', 'ilike', 'BANGUNAN TEKNIK GRUP')], limit=1) + if not partner: + _logger.info("Partner tidak ditemukan.") + return + + invoices = self.env['account.move'].search([ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), + ('invoice_date_due', 'in', target_dates), + ('partner_id', '=', partner.id), + ]) + + _logger.info(f"Invoices tahap 1: {invoices}") + + invoices = invoices.filtered( + lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() + ) + _logger.info(f"Invoices tahap 2: {invoices}") + + if not invoices: + _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") + return + + grouped = {} + for inv in invoices: + grouped.setdefault(inv.partner_id, []).append(inv) + + template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') + + for partner, invs in grouped.items(): + # Cari semua kontak anak yang reminder_invoices = True dan punya email + reminder_contacts = self.env['res.partner'].search([ + ('parent_id', '=', partner.id), + ('reminder_invoices', '=', True), + ('email', '!=', False), + ]) + + # Gabungkan partner.email utama + semua email dari child contact reminder + emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') + + if not emails: + _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") + continue + + email_to = ",".join(emails) + _logger.info(f"Email tujuan: {email_to}") + + # Buat isi tabel invoice + invoice_table_rows = "" + for inv in invs: + days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 + invoice_table_rows += f""" + + {inv.name} + {fields.Date.to_string(inv.invoice_date) or '-'} + {fields.Date.to_string(inv.invoice_date_due) or '-'} + {days_to_due} + {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} + {inv.ref or '-'} + + """ + + subject = f"Reminder Invoice Due - {partner.name}" + body_html = re.sub( + r"]*>.*?", + f"{invoice_table_rows}", + template.body_html, + flags=re.DOTALL + ).replace('${object.name}', partner.name) \ + .replace('${object.partner_id.name}', partner.name) + + values = { + 'subject': subject, + 'email_to': email_to, + 'email_from': 'finance@indoteknik.co.id', + 'body_html': body_html, + 'reply_to': f'invoice+account.move_{invs[0].id}@indoteknik.co.id', + } + + _logger.info(f"Mengirim email ke: {email_to}") + template.send_mail(invs[0].id, force_send=True, email_values=values) + + # Post ke chatter + user_system = self.env['res.users'].browse(25) + system_id = user_system.partner_id.id if user_system else False + + for inv in invs: + inv.message_post( + subject=subject, + body=body_html, + subtype_id=self.env.ref('mail.mt_note').id, + author_id=system_id, + ) + + _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice") @api.onchange('invoice_date') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index d1d4ca02..f260f58e 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -28,7 +28,7 @@ class ResPartner(models.Model): supplier_ids = fields.Many2many('user.pengajuan.tempo.line', string="Suppliers") reminder_invoices = fields.Boolean( - string='Reminder Invoice', + string='Reminder Invoice?', help='Centang jika kontak ini harus menerima email pengingat invoice.', default=False ) -- cgit v1.2.3 From 6daa7c62dab03ce688773acd9c083bc845c9cf61 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Tue, 29 Jul 2025 11:50:51 +0700 Subject: (andri) sales id customer benefits --- indoteknik_custom/models/commision.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 26b5df37..9f7df464 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -215,9 +215,8 @@ class CustomerCommision(models.Model): grouped_so_number = fields.Char(string='Group SO Number', compute='_compute_grouped_numbers') grouped_invoice_number = fields.Char(string='Group Invoice Number', compute='_compute_grouped_numbers') - sales_id = fields.Many2one('res.users', string="Sales", tracking=True, default=lambda self: self.env.user, - domain=lambda self: [ - ('groups_id', 'in', self.env.ref('sales_team.group_sale_salesman').id)]) + sales_id = fields.Many2one('res.users', string="Sales", tracking=True, required=True, + domain=[('groups_id', 'in', [94]),('id', '!=', 15710)]) date_approved_sales = fields.Datetime(string="Date Approved Sales", tracking=True) date_approved_marketing = fields.Datetime(string="Date Approved Marketing", tracking=True) -- cgit v1.2.3 From 60b037c72887d20e8cebd7f4a2439c546d16960b Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Tue, 29 Jul 2025 16:12:42 +0700 Subject: (andri) comment send due inv reminder --- indoteknik_custom/models/account_move.py | 214 +++++++++++++++---------------- 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 14927bec..945a96f9 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -109,113 +109,113 @@ class AccountMove(models.Model): # result.append((move.id, move.display_name)) # return result - def send_due_invoice_reminder(self): - today = fields.Date.today() - target_dates = [ - today - timedelta(days=7), - today - timedelta(days=3), - today, - today + timedelta(days=3), - today + timedelta(days=7), - ] - - # Contoh khusus partner tertentu - partner = self.env['res.partner'].search([('name', 'ilike', 'BANGUNAN TEKNIK GRUP')], limit=1) - if not partner: - _logger.info("Partner tidak ditemukan.") - return - - invoices = self.env['account.move'].search([ - ('move_type', '=', 'out_invoice'), - ('state', '=', 'posted'), - ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), - ('invoice_date_due', 'in', target_dates), - ('partner_id', '=', partner.id), - ]) - - _logger.info(f"Invoices tahap 1: {invoices}") - - invoices = invoices.filtered( - lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() - ) - _logger.info(f"Invoices tahap 2: {invoices}") - - if not invoices: - _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") - return - - grouped = {} - for inv in invoices: - grouped.setdefault(inv.partner_id, []).append(inv) - - template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') - - for partner, invs in grouped.items(): - # Cari semua kontak anak yang reminder_invoices = True dan punya email - reminder_contacts = self.env['res.partner'].search([ - ('parent_id', '=', partner.id), - ('reminder_invoices', '=', True), - ('email', '!=', False), - ]) - - # Gabungkan partner.email utama + semua email dari child contact reminder - emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') - - if not emails: - _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") - continue - - email_to = ",".join(emails) - _logger.info(f"Email tujuan: {email_to}") - - # Buat isi tabel invoice - invoice_table_rows = "" - for inv in invs: - days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 - invoice_table_rows += f""" - - {inv.name} - {fields.Date.to_string(inv.invoice_date) or '-'} - {fields.Date.to_string(inv.invoice_date_due) or '-'} - {days_to_due} - {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} - {inv.ref or '-'} - - """ - - subject = f"Reminder Invoice Due - {partner.name}" - body_html = re.sub( - r"]*>.*?", - f"{invoice_table_rows}", - template.body_html, - flags=re.DOTALL - ).replace('${object.name}', partner.name) \ - .replace('${object.partner_id.name}', partner.name) - - values = { - 'subject': subject, - 'email_to': email_to, - 'email_from': 'finance@indoteknik.co.id', - 'body_html': body_html, - 'reply_to': f'invoice+account.move_{invs[0].id}@indoteknik.co.id', - } - - _logger.info(f"Mengirim email ke: {email_to}") - template.send_mail(invs[0].id, force_send=True, email_values=values) - - # Post ke chatter - user_system = self.env['res.users'].browse(25) - system_id = user_system.partner_id.id if user_system else False - - for inv in invs: - inv.message_post( - subject=subject, - body=body_html, - subtype_id=self.env.ref('mail.mt_note').id, - author_id=system_id, - ) - - _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice") + # def send_due_invoice_reminder(self): + # today = fields.Date.today() + # target_dates = [ + # today - timedelta(days=7), + # today - timedelta(days=3), + # today, + # today + timedelta(days=3), + # today + timedelta(days=7), + # ] + + # # Contoh khusus partner tertentu + # partner = self.env['res.partner'].search([('name', 'ilike', 'BANGUNAN TEKNIK GRUP')], limit=1) + # if not partner: + # _logger.info("Partner tidak ditemukan.") + # return + + # invoices = self.env['account.move'].search([ + # ('move_type', '=', 'out_invoice'), + # ('state', '=', 'posted'), + # ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), + # ('invoice_date_due', 'in', target_dates), + # ('partner_id', '=', partner.id), + # ]) + + # _logger.info(f"Invoices tahap 1: {invoices}") + + # invoices = invoices.filtered( + # lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() + # ) + # _logger.info(f"Invoices tahap 2: {invoices}") + + # if not invoices: + # _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") + # return + + # grouped = {} + # for inv in invoices: + # grouped.setdefault(inv.partner_id, []).append(inv) + + # template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') + + # for partner, invs in grouped.items(): + # # Cari semua kontak anak yang reminder_invoices = True dan punya email + # reminder_contacts = self.env['res.partner'].search([ + # ('parent_id', '=', partner.id), + # ('reminder_invoices', '=', True), + # ('email', '!=', False), + # ]) + + # # Gabungkan partner.email utama + semua email dari child contact reminder + # emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') + + # if not emails: + # _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") + # continue + + # email_to = ",".join(emails) + # _logger.info(f"Email tujuan: {email_to}") + + # # Buat isi tabel invoice + # invoice_table_rows = "" + # for inv in invs: + # days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 + # invoice_table_rows += f""" + # + # {inv.name} + # {fields.Date.to_string(inv.invoice_date) or '-'} + # {fields.Date.to_string(inv.invoice_date_due) or '-'} + # {days_to_due} + # {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} + # {inv.ref or '-'} + # + # """ + + # subject = f"Reminder Invoice Due - {partner.name}" + # body_html = re.sub( + # r"]*>.*?", + # f"{invoice_table_rows}", + # template.body_html, + # flags=re.DOTALL + # ).replace('${object.name}', partner.name) \ + # .replace('${object.partner_id.name}', partner.name) + + # values = { + # 'subject': subject, + # 'email_to': email_to, + # 'email_from': 'finance@indoteknik.co.id', + # 'body_html': body_html, + # 'reply_to': f'invoice+account.move_{invs[0].id}@indoteknik.co.id', + # } + + # _logger.info(f"Mengirim email ke: {email_to}") + # template.send_mail(invs[0].id, force_send=True, email_values=values) + + # # Post ke chatter + # user_system = self.env['res.users'].browse(25) + # system_id = user_system.partner_id.id if user_system else False + + # for inv in invs: + # inv.message_post( + # subject=subject, + # body=body_html, + # subtype_id=self.env.ref('mail.mt_note').id, + # author_id=system_id, + # ) + + # _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice") @api.onchange('invoice_date') -- cgit v1.2.3 From 55235e9521593311d4e0b4d5dc0e23d7563cf4ac Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 30 Jul 2025 00:35:26 +0700 Subject: rev so done --- indoteknik_custom/models/stock_picking.py | 6 +++ indoteknik_custom/models/tukar_guling.py | 87 +++++++++++++++++++++++-------- 2 files changed, 72 insertions(+), 21 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 3e152f10..10cf23ef 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1380,6 +1380,12 @@ class StockPicking(models.Model): self.send_mail_bills() if 'BU/PUT' in self.name: self.automatic_reserve_product() + + if self.tukar_guling_id: + self.tukar_guling_id.update_state() + elif self.tukar_guling_po_id: + self.tukar_guling_po_id.update_state() + return res def automatic_reserve_product(self): diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 396e4db4..5411b17c 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -5,7 +5,8 @@ from datetime import datetime _logger = logging.getLogger(__name__) -#TODO + +# TODO # 1. tracking status dokumen BU [X] # 2. ganti nama dokumen # 3. Tracking ketika create dokumen [X] @@ -20,7 +21,7 @@ class TukarGuling(models.Model): _order = 'date desc, id desc' _rec_name = 'name' _inherit = ['mail.thread', 'mail.activity.mixin'] - + partner_id = fields.Many2one('res.partner', string='Customer', readonly=True) origin = fields.Char(string='Origin SO') if_so = fields.Boolean('Is SO', default=True) @@ -62,6 +63,7 @@ class TukarGuling(models.Model): ('approval_sales', ' Approval Sales'), ('approval_finance', 'Approval Finance'), ('approval_logistic', 'Approval Logistic'), + ('approved', 'Waiting for Operations'), ('done', 'Done'), ('cancel', 'Canceled') ], default='draft', tracking=True, required=True) @@ -98,7 +100,7 @@ class TukarGuling(models.Model): @api.onchange('operations') def _onchange_operations(self): """Auto-populate lines ketika operations dipilih""" - if self.operations.picking_type_id.id not in [29,30]: + if self.operations.picking_type_id.id not in [29, 30]: raise UserError("❌ Picking type harus BU/OUT atau BU/PICK") for rec in self: if rec.operations and rec.operations.picking_type_id.id == 30: @@ -217,7 +219,6 @@ class TukarGuling(models.Model): self.origin = False - def action_populate_lines(self): """Manual button untuk populate lines - sebagai alternatif""" self.ensure_one() @@ -257,7 +258,7 @@ class TukarGuling(models.Model): def _check_product_lines(self): """Constraint: Product lines harus ada jika state bukan draft""" for record in self: - if record.state in ('approval_sales', 'approval_logistic', 'approval_finance', + if record.state in ('approval_sales', 'approval_logistic', 'approval_finance', 'approved', 'done') and not record.line_ids: raise ValidationError("Product lines harus diisi sebelum submit atau approve!") @@ -345,7 +346,7 @@ class TukarGuling(models.Model): def write(self, vals): self.ensure_one() - if self.operations.picking_type_id.id not in [29,30]: + if self.operations.picking_type_id.id not in [29, 30]: raise UserError("❌ Picking type harus BU/OUT atau BU/PICK") self._check_invoice_on_revisi_so() operasi = self.operations.picking_type_id.id @@ -376,10 +377,10 @@ class TukarGuling(models.Model): # if self.state == 'done': # raise UserError ("Tidak Boleh delete ketika sudahh done") for record in self: - if record.state == 'done': + if record.state == 'approved' or record.state == 'done': raise UserError( - "Tidak bisa hapus pengajuan jika sudah done, set ke draft terlebih dahulu jika ingin menghapus") - ongoing_bu = self.picking_ids.filtered(lambda p: p.state != 'done') + "Tidak bisa hapus pengajuan jika sudah Approved, set ke draft terlebih dahulu jika ingin menghapus") + ongoing_bu = self.picking_ids.filtered(lambda p: p.state != 'approved') for picking in ongoing_bu: picking.action_cancel() return super(TukarGuling, self).unlink() @@ -461,6 +462,47 @@ class TukarGuling(models.Model): raise UserError("Submit hanya bisa dilakukan dari Draft.") self.state = 'approval_sales' + def update_state(self): + # OUT tukar guling + if self.operations.picking_type_id.id == 29 and self.return_type == 'tukar_guling': + total_out = self.env['stock.picking'].search_count([ + ('tukar_guling_id', '=', self.id), + ('picking_type_id', '=', 29), + ]) + done_out = self.env['stock.picking'].search_count([ + ('tukar_guling_id', '=', self.id), + ('picking_type_id', '=', 29), + ('state', '=', 'done'), + ]) + if self.state == 'approved' and total_out > 0 and done_out == total_out: + self.state = 'done' + + # OUT revisi SO + elif self.operations.picking_type_id.id == 29 and self.return_type == 'revisi_so': + total_ort = self.env['stock.picking'].search_count([ + ('tukar_guling_id', '=', self.id), + ('picking_type_id', '=', 74), + ]) + done_ort = self.env['stock.picking'].search_count([ + ('tukar_guling_id', '=', self.id), + ('picking_type_id', '=', 74), + ('state', '=', 'done'), + ]) + if self.state == 'approved' and total_ort > 0 and done_ort == total_ort: + self.state = 'done' + + # PICK revisi SO + elif self.operations.picking_type_id.id == 30 and self.return_type == 'revisi_so': + done_ort = self.env['stock.picking'].search([ + ('tukar_guling_id', '=', self.id), + ('picking_type_id', '=', 74), + ('state', '=', 'done'), + ]) + if self.state == 'approved' and done_ort: + self.state = 'done' + else: + raise UserError("Tidak bisa menentukan jenis retur.") + def action_approve(self): self.ensure_one() self._validate_product_lines() @@ -510,7 +552,7 @@ class TukarGuling(models.Model): elif rec.state == 'approval_logistic': if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'): raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.") - rec.state = 'done' + rec.state = 'approved' rec._create_pickings() rec.date_logistic = now @@ -606,7 +648,8 @@ class TukarGuling(models.Model): ### ======== ORT dari BU/PICK ========= ort_pickings = [] is_retur_from_bu_pick = record.operations.picking_type_id.id == 30 - picks_to_return = [record.operations] if is_retur_from_bu_pick else mapping_koli.mapped('pick_id') or line.product_uom_qty + picks_to_return = [record.operations] if is_retur_from_bu_pick else mapping_koli.mapped( + 'pick_id') or line.product_uom_qty for pick in picks_to_return: ort_return_lines = [] @@ -622,7 +665,8 @@ class TukarGuling(models.Model): 'quantity': line.product_uom_qty, 'move_id': move.id, })) - _logger.info(f"📟 ORT (BU/PICK langsung) | {pick.name} | {line.product_id.display_name} | qty={line.product_uom_qty}") + _logger.info( + f"📟 ORT (BU/PICK langsung) | {pick.name} | {line.product_id.display_name} | qty={line.product_uom_qty}") else: # Ambil dari mapping koli for mk in mapping_koli.filtered(lambda m: m.pick_id == pick): @@ -635,7 +679,8 @@ class TukarGuling(models.Model): 'quantity': mk.qty_return, 'move_id': move.id, })) - _logger.info(f"📟 ORT (mapping koli) | {pick.name} | {mk.product_id.display_name} | qty={mk.qty_return}") + _logger.info( + f"📟 ORT (mapping koli) | {pick.name} | {mk.product_id.display_name} | qty={mk.qty_return}") if ort_return_lines: ort_wizard = self.env['stock.return.picking'].with_context({ @@ -817,18 +862,17 @@ class StockPicking(models.Model): message = _( "📦 %s Validated by %s Status Changed %s at %s." ) % ( - picking.name, - # picking.picking_type_id.name, - picking.env.user.name, - picking.state, - fields.Datetime.now().strftime("%d/%m/%Y %H:%M") - ) + picking.name, + # picking.picking_type_id.name, + picking.env.user.name, + picking.state, + fields.Datetime.now().strftime("%d/%m/%Y %H:%M") + ) picking.tukar_guling_id.message_post(body=message) return res - class TukarGulingMappingKoli(models.Model): _name = 'tukar.guling.mapping.koli' _description = 'Mapping Koli di Tukar Guling' @@ -839,6 +883,7 @@ class TukarGulingMappingKoli(models.Model): qty_done = fields.Float(string='Qty Done BU PICK') qty_return = fields.Float(string='Qty diretur') sequence = fields.Integer(string='Sequence', default=10) + @api.constrains('qty_return') def _check_qty_return_editable(self): for rec in self: @@ -849,4 +894,4 @@ class TukarGulingMappingKoli(models.Model): for rec in self: if rec.tukar_guling_id and rec.tukar_guling_id.state not in ['draft', 'cancel']: raise UserError("Tidak bisa menghapus Mapping Koli karena status Tukar Guling bukan Draft atau Cancel.") - return super(TukarGulingMappingKoli, self).unlink() \ No newline at end of file + return super(TukarGulingMappingKoli, self).unlink() -- cgit v1.2.3 From 6d5435fffa97486b78fd871ed3859acd45830793 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 30 Jul 2025 11:23:02 +0700 Subject: rev po done --- indoteknik_custom/models/tukar_guling_po.py | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 11377bc4..23ca1923 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -49,6 +49,7 @@ class TukarGulingPO(models.Model): ('approval_purchase', 'Approval Purchasing'), ('approval_finance', 'Approval Finance'), ('approval_logistic', 'Approval Logistic'), + ('approved', 'Waiting for Operations'), ('done', 'Done'), ('cancel', 'Cancel'), ], string='Status', default='draft', tracking=3) @@ -311,7 +312,7 @@ class TukarGulingPO(models.Model): def unlink(self): for record in self: - if record.state == 'done': + if record.state == 'done' or record.state == 'approved': raise UserError("Tidak bisa hapus pengajuan jika sudah done, set ke draft terlebih dahulu") ongoing_bu = self.po_picking_ids.filtered(lambda p: p.state != 'done') for picking in ongoing_bu: @@ -412,12 +413,50 @@ class TukarGulingPO(models.Model): elif rec.state == 'approval_logistic': if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'): raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.") - rec.state = 'done' + rec.state = 'approved' rec._create_pickings() rec.date_logistic = now else: raise UserError("Status ini tidak bisa di-approve.") + def update_stae(self): + # bu input rev po + if self.operations.picking_type_id.id == 28 and self.return_type == 'revisi_po': + prt = self.env['stock.picking'].search([ + ('tukar_guling_po_id', '=', self.id), + ('state', '=', 'done'), + ('picking_type_id.id', '=', 76) + ]) + if self.state == 'aproved' and prt: + self.state = 'done' + # bu put rev po + elif self.operations.picking_type_id.id == 75 and self.return_type == 'revisi_po': + total_prt = self.env['stock.picking'].search_count([ + ('tukar_guling_po_id', '=', self.id), + ('picking_type_id.id', '=', 76) + ]) + prt = self.env['stock.picking'].search_count([ + ('tukar_guling_po_id', '=', self.id), + ('state', '=', 'done'), + ('picking_type_id.id', '=', 76) + ]) + if self.state == 'aproved' and total_prt > 0 and prt == total_prt: + self.state = 'done' + # bu put tukar guling + elif self.operations.picking_type_id.id == 75 and self.return_type == 'tukar_guling': + total_put = self.env['stock.picking'].search_count([ + ('tukar_guling_po_id', '=', self.id), + ('picking_type_id.id', '=', 75) + ]) + put = self.env['stock.picking'].search_count([ + ('tukar_guling_po_id', '=', self.id), + ('state', '=', 'done'), + ('picking_type_id.id', '=', 75) + ]) + if self.state == 'aproved' and total_put > 0 and put == total_put: + self.state = 'done' + + def action_cancel(self): self.ensure_one() # if self.state == 'done': -- cgit v1.2.3 From d78561e4f4ba8e3a7de58e05fcf8f466c19ec59d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 30 Jul 2025 13:46:54 +0700 Subject: receipt date schema --- indoteknik_custom/models/purchase_order.py | 146 ++++++++++++++++++++++++----- indoteknik_custom/models/sale_order.py | 7 +- indoteknik_custom/models/stock_picking.py | 4 + 3 files changed, 134 insertions(+), 23 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 45134939..27aca0d1 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -92,6 +92,11 @@ class PurchaseOrder(models.Model): is_cab_visible = fields.Boolean(string='Tampilkan Tombol CAB', compute='_compute_is_cab_visible') + reason_change_date_planned = fields.Selection([ + ('delay', 'Delay By Vendor'), + ('urgent', 'Urgent Delivery'), + ], string='Reason Change Date Planned', tracking=True) + # picking_ids = fields.One2many('stock.picking', 'purchase_id', string='Pickings') bu_related_count = fields.Integer( @@ -100,9 +105,68 @@ class PurchaseOrder(models.Model): ) manufacturing_id = fields.Many2one('mrp.production', string='Manufacturing Orders') + complete_bu_in_count = fields.Integer( + string="Complete BU In Count", + compute='_compute_complete_bu_in_count' + ) + + def _compute_complete_bu_in_count(self): + for order in self: + if order.state not in ['done', 'cancel']: + order.complete_bu_in_count = 1 + else: + relevant_pickings = order.picking_ids.filtered( + lambda p: p.state != 'done' + and p.state != 'cancel' + and p.picking_type_code == 'incoming' + and p.origin == order.name + and p.name.startswith('BU/IN') + ) + order.complete_bu_in_count = len(relevant_pickings) + def _has_vcm(self): if self.id: self.vcm_id = self.env['tukar.guling.po'].search([('origin', '=', self.name)], limit=1) + + @api.depends('order_line.date_planned') + def _compute_date_planned(self): + """ date_planned = the earliest date_planned across all order lines. """ + for order in self: + order.date_planned = False + + @api.constrains('date_planned') + def constrains_date_planned(self): + for rec in self: + if not self.env.user.has_group('indoteknik_custom.group_role_purchasing'): + raise ValidationError("Hanya dapat diisi oleh Purchasing") + + base_bu = self.env['stock.picking'].search([ + ('name', 'ilike', 'BU/'), + ('origin', 'ilike', rec.name), + ('group_id', '=', rec.group_id.id), + ('state', 'not in', ['cancel','done']) + ]) + + for bu in base_bu: + bu.write({ + 'scheduled_date': rec.date_planned, + 'reason_change_date_planned': rec.reason_change_date_planned + }) + + rec.sync_date_planned_to_so() + + def sync_date_planned_to_so(self): + for line in self.order_sales_match_line: + other_sales_match = self.env['purchase.order.sales.match'].search([ + # ('product_id', '=', line.product_id.id), + ('sale_id', '=', line.sale_id.id), + # ('sale_line_id', '=', line.sale_line_id.id) + ]) + + dates = [d for d in other_sales_match.mapped('purchase_order_id.date_planned') if d] + if dates: + date_planned = max(dates) + line.sale_id.write({'et_products': date_planned, 'reason_change_date_planned': line.purchase_order_id.reason_change_date_planned}) @api.depends('name') def _compute_bu_related_count(self): @@ -677,13 +741,6 @@ class PurchaseOrder(models.Model): for order in self: order.has_active_invoice = any(invoice.state != 'cancel' for invoice in order.invoice_ids) - # def _compute_has_active_invoice(self): - # for order in self: - # related_invoices = order.invoice_ids.filtered( - # lambda inv: inv.purchase_order_id.id == order.id and inv.move_type == 'in_invoice' and inv.state != 'cancel' - # ) - # order.has_active_invoice = bool(related_invoices) - def add_product_to_pricelist(self): i = 0 for line in self.order_line: @@ -766,16 +823,16 @@ class PurchaseOrder(models.Model): """ purchase_pricelist.message_post(body=message, subtype_id=self.env.ref("mail.mt_note").id) - def _compute_date_planned(self): - for order in self: - if order.date_approve: - leadtime = order.partner_id.leadtime - current_time = order.date_approve - delta_time = current_time + timedelta(days=leadtime) - delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') - order.date_planned = delta_time - else: - order.date_planned = False + # def _compute_date_planned(self): + # for order in self: + # if order.date_approve: + # leadtime = order.partner_id.leadtime + # current_time = order.date_approve + # delta_time = current_time + timedelta(days=leadtime) + # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + # order.date_planned = delta_time + # else: + # order.date_planned = False def action_create_invoice(self): res = super(PurchaseOrder, self).action_create_invoice() @@ -959,6 +1016,9 @@ class PurchaseOrder(models.Model): if self.amount_untaxed >= 50000000 and not self.env.user.id == 21: raise UserError("Hanya Rafly Hanggara yang bisa approve") + + if not self.date_planned: + raise UserError("Receipt Date harus diisi") if self.total_percent_margin < self.total_so_percent_margin: self.env.user.notify_danger( @@ -975,7 +1035,7 @@ class PurchaseOrder(models.Model): # ) if not self.from_apo: - if (not self.matches_so or not self.sale_order_id) and not self.env.user.is_purchasing_manager and not self.env.user.is_leader and not self.manufacturing_id: + if not self.matches_so and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Tidak ada link dengan SO, harus di confirm oleh Purchasing Manager") send_email = False @@ -1010,10 +1070,10 @@ class PurchaseOrder(models.Model): self.approve_by = self.env.user.id # override date planned added with two days - leadtime = self.partner_id.leadtime - delta_time = current_time + timedelta(days=leadtime) - delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') - self.date_planned = delta_time + # leadtime = self.partner_id.leadtime + # delta_time = current_time + timedelta(days=leadtime) + # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + # self.date_planned = delta_time self.date_deadline_ref_date_planned() self.unlink_purchasing_job_state() @@ -1391,6 +1451,20 @@ class PurchaseOrder(models.Model): # Tambahkan pemanggilan method untuk handle pricelist system update self._handle_pricelist_system_update(vals) return res + + def action_open_change_date_wizard(self): + self.ensure_one() + return { + 'type': 'ir.actions.act_window', + 'res_model': 'change.date.planned.wizard', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_purchase_id': self.id, + 'default_new_date_planned': self.date_planned, + } + } + def _handle_pricelist_system_update(self, vals): if 'order_line' in vals or any(key in vals for key in ['state', 'approval_status']): @@ -1479,4 +1553,32 @@ class PurchaseOrderUnlockWizard(models.TransientModel): order.approval_status_unlock = 'pengajuanFinance' return {'type': 'ir.actions.act_window_close'} +class ChangeDatePlannedWizard(models.TransientModel): + _name = 'change.date.planned.wizard' + _description = 'Change Date Planned Wizard' + + purchase_id = fields.Many2one('purchase.order', string="Purchase Order", required=True) + new_date_planned = fields.Datetime(string="New Date Planned") # <- harus DTTM biar match + old_date_planned = fields.Datetime(string="Current Planned Date", related='purchase_id.date_planned', readonly=True) + reason = fields.Selection([ + ('delay', 'Delay By Vendor'), + ('urgent', 'Urgent Delivery'), + ], string='Reason') + date_changed = fields.Boolean(string="Date Changed", compute="_compute_date_changed") + + @api.depends('old_date_planned', 'new_date_planned') + def _compute_date_changed(self): + for rec in self: + rec.date_changed = ( + rec.old_date_planned and rec.new_date_planned and + rec.old_date_planned != rec.new_date_planned + ) + + def confirm_change(self): + self.purchase_id.write({ + 'date_planned': self.new_date_planned, + 'reason_change_date_planned': self.reason, + }) + + diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 7be0e8ff..4e36a9fb 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -350,7 +350,7 @@ class SaleOrder(models.Model): date_unhold = fields.Datetime(string='Date Unhold', tracking=True, readonly=True, help='Waktu ketika SO di Unhold' ) - et_products = fields.Datetime(string='ET Products', compute='_compute_et_products', help="Leadtime produk berdasarkan SLA vendor, tanpa logistik.") + et_products = fields.Datetime(string='ET Products', help="Leadtime produk berdasarkan SLA vendor, tanpa logistik.", tracking=True) eta_date_reserved = fields.Datetime( string="Date Reserved", @@ -381,6 +381,11 @@ class SaleOrder(models.Model): if self.id: self.ccm_id = self.env['tukar.guling'].search([('origin', 'ilike', self.name)], limit=1) + reason_change_date_planned = fields.Selection([ + ('delay', 'Delay By Vendor'), + ('urgent', 'Urgent Delivery'), + ], string='Reason Change Date Planned', tracking=True) + @api.depends('order_line.product_id', 'date_order') def _compute_et_products(self): jakarta = pytz.timezone("Asia/Jakarta") diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 3e152f10..5dd5844d 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -303,6 +303,10 @@ class StockPicking(models.Model): approval_invoice_date_id = fields.Many2one('approval.invoice.date', string='Approval Invoice Date') last_update_date_doc_kirim = fields.Datetime(string='Last Update Tanggal Kirim', copy=False) update_date_doc_kirim_add = fields.Boolean(string='Update Tanggal Kirim Lewat ADD') + reason_change_date_planned = fields.Selection([ + ('delay', 'Delay By Vendor'), + ('urgent', 'Urgent Delivery'), + ], string='Reason Change Date Planned', tracking=True) def _get_kgx_awb_number(self): """Menggabungkan name dan origin untuk membuat AWB Number""" -- cgit v1.2.3 From a05a1dc3f4c936c0162f66a24f69ca8b236acfea Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 31 Jul 2025 08:17:06 +0700 Subject: add validation when changing payment term when so payment term is not match --- indoteknik_custom/models/sale_order.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 4e36a9fb..47018f52 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -3088,6 +3088,24 @@ class SaleOrder(models.Model): except: pass + #payment term vals + if 'payment_term_id' in vals and any( + order.approval_status in ['pengajuan1', 'pengajuan2', 'approved'] for order in self): + raise UserError( + "Payment Term tidak dapat diubah karena Sales Order sedang dalam proses approval atau sudah diapprove.") + + if 'payment_term_id' in vals: + for order in self: + partner = order.partner_id.parent_id or order.partner_id + customer_payment_term = partner.property_payment_term_id + if vals['payment_term_id'] != customer_payment_term.id: + raise UserError( + f"Payment Term berbeda pada Master Data Customer. " + f"Harap ganti ke '{customer_payment_term.name}' " + f"sesuai dengan payment term yang terdaftar pada customer." + ) + + res = super(SaleOrder, self).write(vals) # Update before margin setelah write -- cgit v1.2.3 From 4e39c1abf88e2a6a716c681e8184f2031e7612c1 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 31 Jul 2025 13:41:28 +0700 Subject: push --- indoteknik_custom/models/stock_picking.py | 4 ++-- indoteknik_custom/models/tukar_guling.py | 2 +- indoteknik_custom/models/tukar_guling_po.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 825368de..92ca6e39 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1386,9 +1386,9 @@ class StockPicking(models.Model): self.automatic_reserve_product() if self.tukar_guling_id: - self.tukar_guling_id.update_state() + self.tukar_guling_id.update_doc_state() elif self.tukar_guling_po_id: - self.tukar_guling_po_id.update_state() + self.tukar_guling_po_id.update_doc_state() return res diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 5411b17c..3f81393a 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -462,7 +462,7 @@ class TukarGuling(models.Model): raise UserError("Submit hanya bisa dilakukan dari Draft.") self.state = 'approval_sales' - def update_state(self): + def update_doc_state(self): # OUT tukar guling if self.operations.picking_type_id.id == 29 and self.return_type == 'tukar_guling': total_out = self.env['stock.picking'].search_count([ diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 23ca1923..92d8c9a6 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -419,7 +419,7 @@ class TukarGulingPO(models.Model): else: raise UserError("Status ini tidak bisa di-approve.") - def update_stae(self): + def update_doc_state(self): # bu input rev po if self.operations.picking_type_id.id == 28 and self.return_type == 'revisi_po': prt = self.env['stock.picking'].search([ -- cgit v1.2.3 From a6da6185d08075fe6819427e22fdb1940d50fe62 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Fri, 1 Aug 2025 17:00:08 +0700 Subject: (andri) fix price shipping biteship StockPicking --- indoteknik_custom/models/stock_picking.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 825368de..75d71ad9 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -810,6 +810,7 @@ class StockPicking(models.Model): self.biteship_tracking_id = data.get("courier", {}).get("tracking_id", "") self.biteship_waybill_id = data.get("courier", {}).get("waybill_id", "") self.delivery_tracking_no = self.biteship_waybill_id + self.biteship_shipping_price = data.get("price", 0.0) waybill_id = self.biteship_waybill_id -- cgit v1.2.3 From 09057a3d5074492dfd4de0a48644afb06391102d Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 4 Aug 2025 09:15:55 +0700 Subject: (andri) uncomment remnider --- indoteknik_custom/models/account_move.py | 214 +++++++++++++++---------------- 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 945a96f9..14927bec 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -109,113 +109,113 @@ class AccountMove(models.Model): # result.append((move.id, move.display_name)) # return result - # def send_due_invoice_reminder(self): - # today = fields.Date.today() - # target_dates = [ - # today - timedelta(days=7), - # today - timedelta(days=3), - # today, - # today + timedelta(days=3), - # today + timedelta(days=7), - # ] - - # # Contoh khusus partner tertentu - # partner = self.env['res.partner'].search([('name', 'ilike', 'BANGUNAN TEKNIK GRUP')], limit=1) - # if not partner: - # _logger.info("Partner tidak ditemukan.") - # return - - # invoices = self.env['account.move'].search([ - # ('move_type', '=', 'out_invoice'), - # ('state', '=', 'posted'), - # ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), - # ('invoice_date_due', 'in', target_dates), - # ('partner_id', '=', partner.id), - # ]) - - # _logger.info(f"Invoices tahap 1: {invoices}") - - # invoices = invoices.filtered( - # lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() - # ) - # _logger.info(f"Invoices tahap 2: {invoices}") - - # if not invoices: - # _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") - # return - - # grouped = {} - # for inv in invoices: - # grouped.setdefault(inv.partner_id, []).append(inv) - - # template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') - - # for partner, invs in grouped.items(): - # # Cari semua kontak anak yang reminder_invoices = True dan punya email - # reminder_contacts = self.env['res.partner'].search([ - # ('parent_id', '=', partner.id), - # ('reminder_invoices', '=', True), - # ('email', '!=', False), - # ]) - - # # Gabungkan partner.email utama + semua email dari child contact reminder - # emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') - - # if not emails: - # _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") - # continue - - # email_to = ",".join(emails) - # _logger.info(f"Email tujuan: {email_to}") - - # # Buat isi tabel invoice - # invoice_table_rows = "" - # for inv in invs: - # days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 - # invoice_table_rows += f""" - # - # {inv.name} - # {fields.Date.to_string(inv.invoice_date) or '-'} - # {fields.Date.to_string(inv.invoice_date_due) or '-'} - # {days_to_due} - # {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} - # {inv.ref or '-'} - # - # """ - - # subject = f"Reminder Invoice Due - {partner.name}" - # body_html = re.sub( - # r"]*>.*?", - # f"{invoice_table_rows}", - # template.body_html, - # flags=re.DOTALL - # ).replace('${object.name}', partner.name) \ - # .replace('${object.partner_id.name}', partner.name) - - # values = { - # 'subject': subject, - # 'email_to': email_to, - # 'email_from': 'finance@indoteknik.co.id', - # 'body_html': body_html, - # 'reply_to': f'invoice+account.move_{invs[0].id}@indoteknik.co.id', - # } - - # _logger.info(f"Mengirim email ke: {email_to}") - # template.send_mail(invs[0].id, force_send=True, email_values=values) - - # # Post ke chatter - # user_system = self.env['res.users'].browse(25) - # system_id = user_system.partner_id.id if user_system else False - - # for inv in invs: - # inv.message_post( - # subject=subject, - # body=body_html, - # subtype_id=self.env.ref('mail.mt_note').id, - # author_id=system_id, - # ) - - # _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice") + def send_due_invoice_reminder(self): + today = fields.Date.today() + target_dates = [ + today - timedelta(days=7), + today - timedelta(days=3), + today, + today + timedelta(days=3), + today + timedelta(days=7), + ] + + # Contoh khusus partner tertentu + partner = self.env['res.partner'].search([('name', 'ilike', 'BANGUNAN TEKNIK GRUP')], limit=1) + if not partner: + _logger.info("Partner tidak ditemukan.") + return + + invoices = self.env['account.move'].search([ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), + ('invoice_date_due', 'in', target_dates), + ('partner_id', '=', partner.id), + ]) + + _logger.info(f"Invoices tahap 1: {invoices}") + + invoices = invoices.filtered( + lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() + ) + _logger.info(f"Invoices tahap 2: {invoices}") + + if not invoices: + _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") + return + + grouped = {} + for inv in invoices: + grouped.setdefault(inv.partner_id, []).append(inv) + + template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') + + for partner, invs in grouped.items(): + # Cari semua kontak anak yang reminder_invoices = True dan punya email + reminder_contacts = self.env['res.partner'].search([ + ('parent_id', '=', partner.id), + ('reminder_invoices', '=', True), + ('email', '!=', False), + ]) + + # Gabungkan partner.email utama + semua email dari child contact reminder + emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') + + if not emails: + _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") + continue + + email_to = ",".join(emails) + _logger.info(f"Email tujuan: {email_to}") + + # Buat isi tabel invoice + invoice_table_rows = "" + for inv in invs: + days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 + invoice_table_rows += f""" + + {inv.name} + {fields.Date.to_string(inv.invoice_date) or '-'} + {fields.Date.to_string(inv.invoice_date_due) or '-'} + {days_to_due} + {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} + {inv.ref or '-'} + + """ + + subject = f"Reminder Invoice Due - {partner.name}" + body_html = re.sub( + r"]*>.*?", + f"{invoice_table_rows}", + template.body_html, + flags=re.DOTALL + ).replace('${object.name}', partner.name) \ + .replace('${object.partner_id.name}', partner.name) + + values = { + 'subject': subject, + 'email_to': email_to, + 'email_from': 'finance@indoteknik.co.id', + 'body_html': body_html, + 'reply_to': f'invoice+account.move_{invs[0].id}@indoteknik.co.id', + } + + _logger.info(f"Mengirim email ke: {email_to}") + template.send_mail(invs[0].id, force_send=True, email_values=values) + + # Post ke chatter + user_system = self.env['res.users'].browse(25) + system_id = user_system.partner_id.id if user_system else False + + for inv in invs: + inv.message_post( + subject=subject, + body=body_html, + subtype_id=self.env.ref('mail.mt_note').id, + author_id=system_id, + ) + + _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice") @api.onchange('invoice_date') -- cgit v1.2.3 From 1d58c7888d95793a4f393c9520b9d89a04f69c08 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 4 Aug 2025 11:56:48 +0700 Subject: (andri) fix template & logic send due --- indoteknik_custom/models/account_move.py | 58 +++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 13 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 14927bec..684f875d 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -119,8 +119,7 @@ class AccountMove(models.Model): today + timedelta(days=7), ] - # Contoh khusus partner tertentu - partner = self.env['res.partner'].search([('name', 'ilike', 'BANGUNAN TEKNIK GRUP')], limit=1) + partner = self.env['res.partner'].search([('name', 'ilike', 'SINAR SUKSES MANDIRI')], limit=1) if not partner: _logger.info("Partner tidak ditemukan.") return @@ -132,7 +131,6 @@ class AccountMove(models.Model): ('invoice_date_due', 'in', target_dates), ('partner_id', '=', partner.id), ]) - _logger.info(f"Invoices tahap 1: {invoices}") invoices = invoices.filtered( @@ -144,13 +142,15 @@ class AccountMove(models.Model): _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") return - grouped = {} + # Kelompokkan invoice berdasarkan partner & days_to_due + invoice_group = {} for inv in invoices: - grouped.setdefault(inv.partner_id, []).append(inv) + dtd = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 + invoice_group.setdefault((inv.partner_id, dtd), []).append(inv) template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') - for partner, invs in grouped.items(): + for (partner, dtd), invs in invoice_group.items(): # Cari semua kontak anak yang reminder_invoices = True dan punya email reminder_contacts = self.env['res.partner'].search([ ('parent_id', '=', partner.id), @@ -158,9 +158,7 @@ class AccountMove(models.Model): ('email', '!=', False), ]) - # Gabungkan partner.email utama + semua email dari child contact reminder emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') - if not emails: _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") continue @@ -168,7 +166,7 @@ class AccountMove(models.Model): email_to = ",".join(emails) _logger.info(f"Email tujuan: {email_to}") - # Buat isi tabel invoice + # Generate tabel invoice invoice_table_rows = "" for inv in invs: days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 @@ -179,10 +177,42 @@ class AccountMove(models.Model): {fields.Date.to_string(inv.invoice_date_due) or '-'} {days_to_due} {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} + {inv.invoice_payment_term_id.name or '-'} + {inv.purchase_order_id.name or '-'} {inv.ref or '-'} """ + # Tentukan pesan berdasarkan sisa hari + days_to_due_message = "" + closing_message = "" + if dtd < 0: + days_to_due_message = f"Kami ingin mengingatkan bahwa tagihan anda akan jatuh tempo dalam {abs(dtd)} hari ke depan, dengan rincian sebagai berikut:" + closing_message = ( + "Kami mengharapkan pembayaran dapat dilakukan tepat waktu untuk mendukung kelancaran " + "hubungan kerja sama yang baik antara kedua belah pihak.
" + "Mohon konfirmasi apabila pembayaran telah dijadwalkan. " + "Terima kasih atas perhatian dan kerja samanya." + ) + + if dtd == 0: + days_to_due_message = "Kami ingin mengingatkan bahwa tagihan anda telah memasuki tanggal jatuh tempo pada hari ini, dengan rincian sebagai berikut:" + closing_message = ( + "Mohon kesediaannya untuk segera melakukan pembayaran tepat waktu guna menghindari status " + "keterlambatan dan menjaga kelancaran hubungan kerja sama yang telah terjalin dengan baik.
" + "Apabila pembayaran telah dijadwalkan atau diproses, mohon dapat dikonfirmasi kepada kami. " + "Terima kasih atas perhatian dan kerja samanya." + ) + + if dtd > 0: + days_to_due_message = f"Kami ingin mengingatkan bahwa tagihan anda telah jatuh tempo selama {dtd}, dengan rincian sebagai berikut:" + closing_message = ( + "Mohon kesediaan Bapak/Ibu untuk segera melakukan pembayaran guna menghindari keterlambatan " + "dan menjaga kelancaran kerja sama yang telah terjalin dengan baik.
" + "Apabila pembayaran sudah dilakukan, mohon konfirmasi dan lampirkan bukti transfer agar dapat kami proses lebih lanjut. " + "Terima kasih atas perhatian dan kerja samanya." + ) + subject = f"Reminder Invoice Due - {partner.name}" body_html = re.sub( r"]*>.*?", @@ -190,14 +220,16 @@ class AccountMove(models.Model): template.body_html, flags=re.DOTALL ).replace('${object.name}', partner.name) \ - .replace('${object.partner_id.name}', partner.name) + .replace('${object.partner_id.name}', partner.name) \ + .replace('${days_to_due_message}', days_to_due_message) \ + .replace('${closing_message}', closing_message) values = { 'subject': subject, - 'email_to': email_to, + 'email_to': 'andrifebriyadiputra@gmail.com', 'email_from': 'finance@indoteknik.co.id', 'body_html': body_html, - 'reply_to': f'invoice+account.move_{invs[0].id}@indoteknik.co.id', + 'reply_to': 'finance@indoteknik.co.id', } _logger.info(f"Mengirim email ke: {email_to}") @@ -215,7 +247,7 @@ class AccountMove(models.Model): author_id=system_id, ) - _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice") + _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice (dtd = {dtd})") @api.onchange('invoice_date') -- cgit v1.2.3 From 35c539953611d7e8968a23996df91738b2c6fc94 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 4 Aug 2025 12:48:11 +0700 Subject: testing --- indoteknik_custom/models/commision.py | 31 +++++++++++++++++++++++++++--- indoteknik_custom/models/cust_commision.py | 1 - 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 9f7df464..a900a399 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -399,6 +399,29 @@ class CustomerCommision(models.Model): # result = super(CustomerCommision, self).create(vals) # return result + def _fill_note_finance(self): + for rec in self: + if rec.status == 'approved' and rec.commision_type == 'fee': + fee_percent = rec.commision_percent or 0.0 + dpp = rec.total_dpp or 0.0 + + fee = dpp * fee_percent / 100 + pph21 = 0.5 * fee * 0.05 + fee_net = fee - pph21 + + rec.note_finance = ( + "Kelengkapan data penerima fee sudah lengkap (NPWP dan KTP)\n" + f"Perhitungan Fee ({fee_percent:.0f}%) dari nilai DPP pada Invoice terlampir sudah\n" + f"sesuai yaitu Rp {fee:,.0f}\n" + "Sesuai PMK No. 168 tahun 2023, komisi fee dikenakan PPH 21\n" + "sebesar :\n" + f"= 50% x Penghasilan Bruto x 5%\n" + f"= 50% x Rp {fee:,.0f} x 5%\n" + f"= Rp {pph21:,.0f}\n" + "Sehingga fee bersih sebesar\n" + f"= Rp {fee:,.0f} - Rp {pph21:,.0f}\n" + f"= Rp {fee_net:,.0f}" + ) def action_confirm_customer_commision(self): jakarta_tz = pytz.timezone('Asia/Jakarta') now = datetime.now(jakarta_tz) @@ -407,12 +430,12 @@ class CustomerCommision(models.Model): if not self.status or self.status == 'draft': self.status = 'pengajuan1' - elif self.status == 'pengajuan1' and self.env.user.id == 19: + elif self.status == 'pengajuan1': self.status = 'pengajuan2' self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_sales = now_naive self.position_sales = 'Sales Manager' - elif self.status == 'pengajuan2' and self.env.user.id == 216: + elif self.status == 'pengajuan2': self.status = 'pengajuan3' self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_marketing = now_naive @@ -422,9 +445,11 @@ class CustomerCommision(models.Model): self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_pimpinan = now_naive self.position_pimpinan = 'Pimpinan' - elif self.status == 'pengajuan4' and self.env.user.id == 1272: + elif self.status == 'pengajuan4': for line in self.commision_lines: line.invoice_id.is_customer_commision = True + if self.commision_type == 'fee': + self._fill_note_finance() self.status = 'approved' self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_accounting = now_naive diff --git a/indoteknik_custom/models/cust_commision.py b/indoteknik_custom/models/cust_commision.py index c3105cfd..05c68935 100644 --- a/indoteknik_custom/models/cust_commision.py +++ b/indoteknik_custom/models/cust_commision.py @@ -34,4 +34,3 @@ class CustCommision(models.Model): for rec in duplicate_partner: if self.commision_type == rec.commision_type: raise UserError('Partner already exists') - \ No newline at end of file -- cgit v1.2.3 From 4dbaaade2793487477b4d83bfb76a838931707dd Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 4 Aug 2025 13:31:29 +0700 Subject: testing --- indoteknik_custom/models/commision.py | 42 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index a900a399..3f56b7f3 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -208,7 +208,7 @@ class CustomerCommision(models.Model): ('pending', 'Pending'), ('payment', 'Payment'), ], string='Payment Status', copy=False, readonly=True, tracking=3, default='pending') - note_finnance = fields.Text('Notes Finnance') + note_finnance = fields.Text('Notes Finance') reason_reject = fields.Char(string='Reason Reaject', tracking=True, track_visibility='onchange') approved_by = fields.Char(string='Approved By', tracking=True, track_visibility='always') @@ -401,27 +401,25 @@ class CustomerCommision(models.Model): def _fill_note_finance(self): for rec in self: - if rec.status == 'approved' and rec.commision_type == 'fee': - fee_percent = rec.commision_percent or 0.0 - dpp = rec.total_dpp or 0.0 - - fee = dpp * fee_percent / 100 - pph21 = 0.5 * fee * 0.05 - fee_net = fee - pph21 - - rec.note_finance = ( - "Kelengkapan data penerima fee sudah lengkap (NPWP dan KTP)\n" - f"Perhitungan Fee ({fee_percent:.0f}%) dari nilai DPP pada Invoice terlampir sudah\n" - f"sesuai yaitu Rp {fee:,.0f}\n" - "Sesuai PMK No. 168 tahun 2023, komisi fee dikenakan PPH 21\n" - "sebesar :\n" - f"= 50% x Penghasilan Bruto x 5%\n" - f"= 50% x Rp {fee:,.0f} x 5%\n" - f"= Rp {pph21:,.0f}\n" - "Sehingga fee bersih sebesar\n" - f"= Rp {fee:,.0f} - Rp {pph21:,.0f}\n" - f"= Rp {fee_net:,.0f}" - ) + fee_percent = rec.commision_percent or 0.0 + dpp = rec.total_dpp or 0.0 + + fee = dpp * fee_percent / 100 + pph21 = 0.5 * fee * 0.05 + fee_net = fee - pph21 + rec.note_finnance = ( + "Kelengkapan data penerima fee sudah lengkap (NPWP dan KTP)\n" + f"Perhitungan Fee ({fee_percent:.0f}%) dari nilai DPP pada Invoice terlampir sudah\n" + f"sesuai yaitu Rp {fee:,.0f}\n" + "Sesuai PMK No. 168 tahun 2023, komisi fee dikenakan PPH 21\n" + "sebesar :\n" + f"= 50% x Penghasilan Bruto x 5%\n" + f"= 50% x Rp {fee:,.0f} x 5%\n" + f"= Rp {pph21:,.0f}\n" + "Sehingga fee bersih sebesar\n" + f"= Rp {fee:,.0f} - Rp {pph21:,.0f}\n" + f"= Rp {fee_net:,.0f}" + ) def action_confirm_customer_commision(self): jakarta_tz = pytz.timezone('Asia/Jakarta') now = datetime.now(jakarta_tz) -- cgit v1.2.3 From 40cb418248b940bb28e5cc5938afed1c27eb7855 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 4 Aug 2025 13:36:58 +0700 Subject: fix --- indoteknik_custom/models/commision.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 3f56b7f3..6d538b83 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -428,12 +428,12 @@ class CustomerCommision(models.Model): if not self.status or self.status == 'draft': self.status = 'pengajuan1' - elif self.status == 'pengajuan1': + elif self.status == 'pengajuan1' and self.env.user.id == 19: self.status = 'pengajuan2' self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_sales = now_naive self.position_sales = 'Sales Manager' - elif self.status == 'pengajuan2': + elif self.status == 'pengajuan2' and self.env.user.id == 216: self.status = 'pengajuan3' self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_marketing = now_naive @@ -443,7 +443,7 @@ class CustomerCommision(models.Model): self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_pimpinan = now_naive self.position_pimpinan = 'Pimpinan' - elif self.status == 'pengajuan4': + elif self.status == 'pengajuan4' and self.env.user.id == 1272: for line in self.commision_lines: line.invoice_id.is_customer_commision = True if self.commision_type == 'fee': -- cgit v1.2.3 From 8386a9affb5e17b09ba76702f7fb01f070a5f713 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 4 Aug 2025 14:48:36 +0700 Subject: remove vendor bill val --- indoteknik_custom/models/tukar_guling_po.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 92d8c9a6..21f973a2 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -281,7 +281,7 @@ class TukarGulingPO(models.Model): def write(self, vals): if self.operations.picking_type_id.id not in [75, 28]: raise UserError("❌ Tidak bisa retur bukan BU/INPUT atau BU/PUT!") - self._check_bill_on_revisi_po() + # self._check_bill_on_revisi_po() tipe = vals.get('return_type', self.return_type) if self.operations and self.operations.picking_type_id.id == 28 and tipe == 'tukar_guling': @@ -349,7 +349,7 @@ class TukarGulingPO(models.Model): def action_submit(self): self.ensure_one() - self._check_bill_on_revisi_po() + # self._check_bill_on_revisi_po() self._validate_product_lines() self._check_not_allow_tukar_guling_on_bu_input() @@ -385,7 +385,7 @@ class TukarGulingPO(models.Model): def action_approve(self): self.ensure_one() self._validate_product_lines() - self._check_bill_on_revisi_po() + # self._check_bill_on_revisi_po() self._check_not_allow_tukar_guling_on_bu_input() if not self.operations: -- cgit v1.2.3 From 569fd1188a36aa97f0681bffe650dcbb9215f504 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 4 Aug 2025 15:05:50 +0700 Subject: remove vendor bill val --- indoteknik_custom/models/tukar_guling_po.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 21f973a2..467fff44 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -74,19 +74,19 @@ class TukarGulingPO(models.Model): return res - @api.constrains('return_type', 'operations') - def _check_bill_on_revisi_po(self): - for record in self: - if record.return_type == 'revisi_po' and record.origin: - bills = self.env['account.move'].search([ - ('invoice_origin', 'ilike', record.origin), - ('move_type', '=', 'in_invoice'), # hanya vendor bill - ('state', 'not in', ['draft', 'cancel']) - ]) - if bills: - raise ValidationError( - _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill.") % record.origin - ) + # @api.constrains('return_type', 'operations') + # def _check_bill_on_revisi_po(self): + # for record in self: + # if record.return_type == 'revisi_po' and record.origin: + # bills = self.env['account.move'].search([ + # ('invoice_origin', 'ilike', record.origin), + # ('move_type', '=', 'in_invoice'), # hanya vendor bill + # ('state', 'not in', ['draft', 'cancel']) + # ]) + # if bills: + # raise ValidationError( + # _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill.") % record.origin + # ) @api.onchange('operations') def _onchange_operations(self): -- cgit v1.2.3 From 9e783f7e3c356eb53f3afe10601a4eb9d0eeecdc Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 4 Aug 2025 15:23:35 +0700 Subject: (andri) fix template --- indoteknik_custom/models/account_move.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 684f875d..b9315c43 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -119,7 +119,7 @@ class AccountMove(models.Model): today + timedelta(days=7), ] - partner = self.env['res.partner'].search([('name', 'ilike', 'SINAR SUKSES MANDIRI')], limit=1) + partner = self.env['res.partner'].search([('name', 'ilike', 'DIRGANTARA YUDHA ARTHA')], limit=1) if not partner: _logger.info("Partner tidak ditemukan.") return @@ -172,17 +172,17 @@ class AccountMove(models.Model): days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 invoice_table_rows += f""" + {inv.partner_id.name} + {inv.purchase_order_id.name or '-'} {inv.name} {fields.Date.to_string(inv.invoice_date) or '-'} {fields.Date.to_string(inv.invoice_date_due) or '-'} - {days_to_due} {formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id)} {inv.invoice_payment_term_id.name or '-'} - {inv.purchase_order_id.name or '-'} - {inv.ref or '-'} + {days_to_due} """ - + dadada = self.partner_id.name # Tentukan pesan berdasarkan sisa hari days_to_due_message = "" closing_message = "" -- cgit v1.2.3 From 09032d721277221730efa3db7a2d8353524d509c Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 4 Aug 2025 16:02:11 +0700 Subject: (andri) check --- indoteknik_custom/models/account_move.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index b9315c43..53e5a8e8 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -158,6 +158,12 @@ class AccountMove(models.Model): ('email', '!=', False), ]) + _logger.info(f"Email Reminder Child {reminder_contacts}") + + if not reminder_contacts: + _logger.info(f"Partner {partner.name} tidak memiliki email yang sudah ceklis reminder") + continue + emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') if not emails: _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") @@ -205,7 +211,7 @@ class AccountMove(models.Model): ) if dtd > 0: - days_to_due_message = f"Kami ingin mengingatkan bahwa tagihan anda telah jatuh tempo selama {dtd}, dengan rincian sebagai berikut:" + days_to_due_message = f"Kami ingin mengingatkan bahwa tagihan anda telah jatuh tempo selama {dtd} hari, dengan rincian sebagai berikut:" closing_message = ( "Mohon kesediaan Bapak/Ibu untuk segera melakukan pembayaran guna menghindari keterlambatan " "dan menjaga kelancaran kerja sama yang telah terjalin dengan baik.
" -- cgit v1.2.3 From 519c18161bf658853908ddf7216aab504ac4c743 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 5 Aug 2025 10:53:05 +0700 Subject: add tracking on delivery amt --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 47018f52..94cfdc39 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -163,7 +163,7 @@ class SaleOrder(models.Model): carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method', tracking=3) have_visit_service = fields.Boolean(string='Have Visit Service', compute='_have_visit_service', help='To compute is customer get visit service') - delivery_amt = fields.Float(string='Delivery Amt', copy=False) + delivery_amt = fields.Float(string='Delivery Amt', copy=False, tracking=True) shipping_cost_covered = fields.Selection([ ('indoteknik', 'Indoteknik'), ('customer', 'Customer') -- cgit v1.2.3 From eb91fb8b9cf3ebc68f6c609acbc85015ce902cab Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 5 Aug 2025 11:24:34 +0700 Subject: add payment date on invoices --- indoteknik_custom/models/account_move.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 1a6fad1c..929af949 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -94,6 +94,18 @@ class AccountMove(models.Model): compute='_compute_has_refund_so', ) + payment_date = fields.Date(string="Payment Date", compute='_compute_payment_date') + + def _compute_payment_date(self): + for move in self: + accountPayment = self.env['account.payment'] + + payment = accountPayment.search([]).filtered( + lambda p: move.id in p.reconciled_invoice_ids.ids + ) + + move.payment_date = payment[0].date + # def name_get(self): # result = [] # for move in self: -- cgit v1.2.3 From d115f21b64e72af553d7c8965b9426b2802a0e3c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 5 Aug 2025 11:52:32 +0700 Subject: fix bug --- indoteknik_custom/models/account_move.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 929af949..4be6c984 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -104,7 +104,10 @@ class AccountMove(models.Model): lambda p: move.id in p.reconciled_invoice_ids.ids ) - move.payment_date = payment[0].date + if payment: + move.payment_date = payment[0].date + else: + move.payment_date = False # def name_get(self): # result = [] -- cgit v1.2.3 From 2d7aaf7fe387dd778731a2058dbe3210407ad803 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 5 Aug 2025 14:42:35 +0700 Subject: deactive redirect bu related --- indoteknik_custom/models/purchase_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 27aca0d1..103a9131 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1083,9 +1083,9 @@ class PurchaseOrder(models.Model): # Tambahan: redirect ke BU hanya untuk single PO yang berhasil dikonfirmasi _logger.info("Jumlah PO: %s | State: %s", len(self), self.state) - if len(self) == 1: - _logger.info("Redirecting ke BU") - return self.action_view_related_bu() + # if len(self) == 1: + # _logger.info("Redirecting ke BU") + # return self.action_view_related_bu() return res -- cgit v1.2.3 From c42bdba2996d85d328897e42e7a1d86001b3a14d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 5 Aug 2025 15:21:56 +0700 Subject: multi update receipt date --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/update_date_planned_po_wizard.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 indoteknik_custom/models/update_date_planned_po_wizard.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 51d25c1f..3a9f9312 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -156,3 +156,4 @@ from . import refund_sale_order # from . import patch from . import tukar_guling from . import tukar_guling_po +from . import update_date_planned_po_wizard \ No newline at end of file diff --git a/indoteknik_custom/models/update_date_planned_po_wizard.py b/indoteknik_custom/models/update_date_planned_po_wizard.py new file mode 100644 index 00000000..a0d241c8 --- /dev/null +++ b/indoteknik_custom/models/update_date_planned_po_wizard.py @@ -0,0 +1,14 @@ +from odoo import models, fields, api + +class PurchaseOrderUpdateDateWizard(models.TransientModel): + _name = 'purchase.order.update.date.wizard' + _description = 'Wizard to Update Receipt Date on Purchase Order Lines' + + date_planned = fields.Datetime(string="New Receipt Date", required=True) + + def action_update_date(self): + active_ids = self.env.context.get('active_ids', []) + orders = self.env['purchase.order'].browse(active_ids) + for order in orders: + order.write({'date_planned': self.date_planned}) + return {'type': 'ir.actions.act_window_close'} -- cgit v1.2.3 From 9f9081714356e87500ab05bc5a294e9ca9e526fe Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 6 Aug 2025 08:49:56 +0700 Subject: inv and bil return option --- indoteknik_custom/models/account_move.py | 1 + indoteknik_custom/models/tukar_guling.py | 41 ++++++++++++++++-- indoteknik_custom/models/tukar_guling_po.py | 65 ++++++++++++++++++++++------- 3 files changed, 87 insertions(+), 20 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 4be6c984..b03d0a80 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -18,6 +18,7 @@ _logger = logging.getLogger(__name__) class AccountMove(models.Model): _inherit = 'account.move' _description = 'Account Move' + tukar_guling_po_id = fields.Many2one('tukar.guling.po', string='Tukar Guling PO Ref') invoice_day_to_due = fields.Integer(string="Day to Due", compute="_compute_invoice_day_to_due") bill_day_to_due = fields.Date(string="Day to Due", compute="_compute_bill_day_to_due") date_send_fp = fields.Datetime(string="Tanggal Kirim Faktur Pajak") diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 3f81393a..d511779e 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -74,6 +74,38 @@ class TukarGuling(models.Model): date_sales = fields.Datetime('Approved Date Sales', tracking=3, readonly=True) date_logistic = fields.Datetime('Approved Date Logistic', tracking=3, readonly=True) + val_inv_opt = fields.Selection([ + ('tanpa_cancel', 'Tanpa Cancel Invoice'), + ('cancel_invoice', 'Cancel Invoice'), + ], tracking=3, string='Invoice Option') + + is_has_invoice = fields.Boolean('Has Invoice?', compute='_compute_is_has_invoice', readonly=True, default=False) + + invoice_id = fields.Many2one('account.move', string='Invoice Ref', readonly=True) + + @api.depends('origin') + def _compute_is_has_invoice(self): + for rec in self: + invoices = self.env['account.move'].search([ + ('invoice_origin', 'ilike', rec.origin), + ('move_type', '=', 'out_invoice'), # hanya invoice + ('state', 'not in', ['draft', 'cancel']) + ]) + if invoices: + rec.is_has_invoice = True + rec.invoice_id = invoices + else: + rec.is_has_invoice = False + + def set_opt(self): + if not self.val_inv_opt and self.is_has_invoice == True: + raise UserError("Kalau sudah ada invoice Return Invoice Option harus diisi!") + for rec in self: + if rec.val_inv_opt == 'cancel_invoice' and self.is_has_invoice == True: + raise UserError("Tidak bisa mengubah Return karena sudah ada invoice dan belum di cancel.") + elif rec.val_inv_opt == 'tanpa_cancel' and self.is_has_invoice == True: + continue + # @api.onchange('operations') # def get_partner_id(self): # if self.operations and self.operations.partner_id and self.operations.partner_id.name: @@ -288,7 +320,6 @@ class TukarGuling(models.Model): # ('state', '!=', 'cancel') # ]) > 0 - @api.constrains('return_type', 'operations') def _check_invoice_on_revisi_so(self): for record in self: if record.return_type == 'revisi_so' and record.origin: @@ -348,7 +379,7 @@ class TukarGuling(models.Model): self.ensure_one() if self.operations.picking_type_id.id not in [29, 30]: raise UserError("❌ Picking type harus BU/OUT atau BU/PICK") - self._check_invoice_on_revisi_so() + # self._check_invoice_on_revisi_so() operasi = self.operations.picking_type_id.id tipe = self.return_type pp = vals.get('return_type', tipe) @@ -455,7 +486,7 @@ class TukarGuling(models.Model): raise UserError( _("Qty di Koli tidak sesuai dengan qty retur untuk produk %s") % line.product_id.display_name) - self._check_invoice_on_revisi_so() + # self._check_invoice_on_revisi_so() self._validate_product_lines() if self.state != 'draft': @@ -506,7 +537,7 @@ class TukarGuling(models.Model): def action_approve(self): self.ensure_one() self._validate_product_lines() - self._check_invoice_on_revisi_so() + # self._check_invoice_on_revisi_so() self._check_not_allow_tukar_guling_on_bu_pick() operasi = self.operations.picking_type_id.id @@ -546,6 +577,8 @@ class TukarGuling(models.Model): elif rec.state == 'approval_finance': if not rec.env.user.has_group('indoteknik_custom.group_role_fat'): raise UserError("Hanya Finance Manager yang boleh approve tahap ini.") + rec._check_invoice_on_revisi_so() + rec.set_opt() rec.state = 'approval_logistic' rec.date_finance = now diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 467fff44..83aa49fe 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -54,6 +54,38 @@ class TukarGulingPO(models.Model): ('cancel', 'Cancel'), ], string='Status', default='draft', tracking=3) + val_bil_opt = fields.Selection([ + ('tanpa_cancel', 'Tanpa Cancel Bill'), + ('cancel_bill', 'Cancel Bill'), + ], tracking=3, string='Bill Option') + + is_has_bill = fields.Boolean('Has Bill?', compute='_compute_is_has_bill', readonly=True, default=False) + + bill_id = fields.Many2one('account.move', string='Bill Ref', readonly=True) + + @api.depends('origin') + def _compute_is_has_bill(self): + for rec in self: + bills = self.env['account.move'].search([ + ('invoice_origin', 'ilike', rec.origin), + ('move_type', '=', 'in_invoice'), # hanya vendor bill + ('state', 'not in', ['draft', 'cancel']) + ]) + if bills: + rec.is_has_bill = True + rec.bill_id = bills + else: + rec.is_has_bill = False + + def set_opt(self): + if not self.val_bil_opt and self.is_has_bill == True: + raise UserError("Kalau sudah ada bill Return Bill Option harus diisi!") + for rec in self: + if rec.val_bil_opt == 'cancel_bill' and self.is_has_bill == True: + raise UserError("Tidak bisa mengubah Return karena sudah ada bill dan belum di cancel.") + elif rec.val_bil_opt == 'tanpa_cancel' and self.is_has_bill == True: + continue + @api.model def create(self, vals): # Generate sequence number @@ -74,19 +106,18 @@ class TukarGulingPO(models.Model): return res - # @api.constrains('return_type', 'operations') - # def _check_bill_on_revisi_po(self): - # for record in self: - # if record.return_type == 'revisi_po' and record.origin: - # bills = self.env['account.move'].search([ - # ('invoice_origin', 'ilike', record.origin), - # ('move_type', '=', 'in_invoice'), # hanya vendor bill - # ('state', 'not in', ['draft', 'cancel']) - # ]) - # if bills: - # raise ValidationError( - # _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill.") % record.origin - # ) + def _check_bill_on_revisi_po(self): + for record in self: + if record.return_type == 'revisi_po' and record.origin: + bills = self.env['account.move'].search([ + ('invoice_origin', 'ilike', record.origin), + ('move_type', '=', 'in_invoice'), # hanya vendor bill + ('state', 'not in', ['draft', 'cancel']) + ]) + # if bills: + # raise ValidationError( + # _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill. Harus Cancel Jika ingin melanjutkan") % record.origin + # ) @api.onchange('operations') def _onchange_operations(self): @@ -400,19 +431,21 @@ class TukarGulingPO(models.Model): for rec in self: if rec.state == 'approval_purchase': if not rec.env.user.has_group('indoteknik_custom.group_role_sales'): - raise UserError("Hanya Sales Manager yang boleh approve tahap ini.") + raise UserError("Hanya Sales yang boleh approve tahap ini.") rec.state = 'approval_finance' rec.date_purchase = now elif rec.state == 'approval_finance': if not rec.env.user.has_group('indoteknik_custom.group_role_fat'): - raise UserError("Hanya Finance Manager yang boleh approve tahap ini.") + raise UserError("Hanya Finance yang boleh approve tahap ini.") + rec._check_bill_on_revisi_po() + rec.set_opt() rec.state = 'approval_logistic' rec.date_finance = now elif rec.state == 'approval_logistic': if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'): - raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.") + raise UserError("Hanya Logistic yang boleh approve tahap ini.") rec.state = 'approved' rec._create_pickings() rec.date_logistic = now -- cgit v1.2.3 From ef5652dc2c57ef2648ea3730898e03c1c00c35f2 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 6 Aug 2025 08:56:32 +0700 Subject: wkwkw --- indoteknik_custom/models/tukar_guling_po.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 83aa49fe..72fb1607 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -460,7 +460,7 @@ class TukarGulingPO(models.Model): ('state', '=', 'done'), ('picking_type_id.id', '=', 76) ]) - if self.state == 'aproved' and prt: + if self.state == 'approved' and prt: self.state = 'done' # bu put rev po elif self.operations.picking_type_id.id == 75 and self.return_type == 'revisi_po': @@ -473,7 +473,7 @@ class TukarGulingPO(models.Model): ('state', '=', 'done'), ('picking_type_id.id', '=', 76) ]) - if self.state == 'aproved' and total_prt > 0 and prt == total_prt: + if self.state == 'approved' and total_prt > 0 and prt == total_prt: self.state = 'done' # bu put tukar guling elif self.operations.picking_type_id.id == 75 and self.return_type == 'tukar_guling': -- cgit v1.2.3 From 1db0c2f6148e5c13454cc25e4d4d877756536a4b Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 6 Aug 2025 08:57:46 +0700 Subject: push --- indoteknik_custom/models/account_move.py | 1 - 1 file changed, 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index b03d0a80..4be6c984 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -18,7 +18,6 @@ _logger = logging.getLogger(__name__) class AccountMove(models.Model): _inherit = 'account.move' _description = 'Account Move' - tukar_guling_po_id = fields.Many2one('tukar.guling.po', string='Tukar Guling PO Ref') invoice_day_to_due = fields.Integer(string="Day to Due", compute="_compute_invoice_day_to_due") bill_day_to_due = fields.Date(string="Day to Due", compute="_compute_bill_day_to_due") date_send_fp = fields.Datetime(string="Tanggal Kirim Faktur Pajak") -- cgit v1.2.3 From 9fb81ccccb8f2735ac5811d81b644b0ae70c4d8e Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 6 Aug 2025 10:33:25 +0700 Subject: push --- indoteknik_custom/models/tukar_guling.py | 24 ++++++++++++------------ indoteknik_custom/models/tukar_guling_po.py | 26 +++++++++++++------------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index d511779e..3091acce 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -320,17 +320,17 @@ class TukarGuling(models.Model): # ('state', '!=', 'cancel') # ]) > 0 - def _check_invoice_on_revisi_so(self): - for record in self: - if record.return_type == 'revisi_so' and record.origin: - invoices = self.env['account.move'].search([ - ('invoice_origin', 'ilike', record.origin), - ('state', 'not in', ['draft', 'cancel']) - ]) - if invoices: - raise ValidationError( - _("Tidak bisa memilih Return Type 'Revisi SO' karena dokumen %s sudah dibuat invoice.") % record.origin - ) + # def _check_invoice_on_revisi_so(self): + # for record in self: + # if record.return_type == 'revisi_so' and record.origin: + # invoices = self.env['account.move'].search([ + # ('invoice_origin', 'ilike', record.origin), + # ('state', 'not in', ['draft', 'cancel']) + # ]) + # if invoices: + # raise ValidationError( + # _("Tidak bisa memilih Return Type 'Revisi SO' karena dokumen %s sudah dibuat invoice.") % record.origin + # ) @api.model def create(self, vals): @@ -577,7 +577,7 @@ class TukarGuling(models.Model): elif rec.state == 'approval_finance': if not rec.env.user.has_group('indoteknik_custom.group_role_fat'): raise UserError("Hanya Finance Manager yang boleh approve tahap ini.") - rec._check_invoice_on_revisi_so() + # rec._check_invoice_on_revisi_so() rec.set_opt() rec.state = 'approval_logistic' rec.date_finance = now diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 72fb1607..38afaac6 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -106,18 +106,18 @@ class TukarGulingPO(models.Model): return res - def _check_bill_on_revisi_po(self): - for record in self: - if record.return_type == 'revisi_po' and record.origin: - bills = self.env['account.move'].search([ - ('invoice_origin', 'ilike', record.origin), - ('move_type', '=', 'in_invoice'), # hanya vendor bill - ('state', 'not in', ['draft', 'cancel']) - ]) - # if bills: - # raise ValidationError( - # _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill. Harus Cancel Jika ingin melanjutkan") % record.origin - # ) + # def _check_bill_on_revisi_po(self): + # for record in self: + # if record.return_type == 'revisi_po' and record.origin: + # bills = self.env['account.move'].search([ + # ('invoice_origin', 'ilike', record.origin), + # ('move_type', '=', 'in_invoice'), # hanya vendor bill + # ('state', 'not in', ['draft', 'cancel']) + # ]) + # if bills: + # raise ValidationError( + # _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill. Harus Cancel Jika ingin melanjutkan") % record.origin + # ) @api.onchange('operations') def _onchange_operations(self): @@ -438,7 +438,7 @@ class TukarGulingPO(models.Model): elif rec.state == 'approval_finance': if not rec.env.user.has_group('indoteknik_custom.group_role_fat'): raise UserError("Hanya Finance yang boleh approve tahap ini.") - rec._check_bill_on_revisi_po() + # rec._check_bill_on_revisi_po() rec.set_opt() rec.state = 'approval_logistic' rec.date_finance = now -- cgit v1.2.3 From 837b7ba9f7118c6516ebad6b4022e1b449661c4d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 6 Aug 2025 11:01:45 +0700 Subject: fix payment date account move --- indoteknik_custom/models/account_move.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 4be6c984..595c5655 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -106,6 +106,8 @@ class AccountMove(models.Model): if payment: move.payment_date = payment[0].date + elif move.reklas_misc_id: + move.payment_date = move.reklas_misc_id.date else: move.payment_date = False -- cgit v1.2.3 From ab11c9455c6e125195ec5004adfd855058d46f5f Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 6 Aug 2025 12:56:35 +0700 Subject: fix error singleton --- indoteknik_custom/models/tukar_guling.py | 2 +- indoteknik_custom/models/tukar_guling_po.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 3091acce..8de5b671 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -81,7 +81,7 @@ class TukarGuling(models.Model): is_has_invoice = fields.Boolean('Has Invoice?', compute='_compute_is_has_invoice', readonly=True, default=False) - invoice_id = fields.Many2one('account.move', string='Invoice Ref', readonly=True) + invoice_id = fields.Many2many('account.move', string='Invoice Ref', readonly=True) @api.depends('origin') def _compute_is_has_invoice(self): diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 38afaac6..5d444472 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -61,7 +61,7 @@ class TukarGulingPO(models.Model): is_has_bill = fields.Boolean('Has Bill?', compute='_compute_is_has_bill', readonly=True, default=False) - bill_id = fields.Many2one('account.move', string='Bill Ref', readonly=True) + bill_id = fields.Many2many('account.move', string='Bill Ref', readonly=True) @api.depends('origin') def _compute_is_has_bill(self): -- cgit v1.2.3 From cad9851dc642c877dcb1913e5bb12dc6405d9652 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 6 Aug 2025 14:19:32 +0700 Subject: fix when no bu pick --- indoteknik_custom/models/tukar_guling.py | 45 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 8de5b671..881021ab 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -479,13 +479,22 @@ class TukarGuling(models.Model): # raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") if self.operations.picking_type_id.id == 29: - for line in self.line_ids: - mapping_lines = self.mapping_koli_ids.filtered(lambda x: x.product_id == line.product_id) - total_qty = sum(l.qty_return for l in mapping_lines) - if total_qty != line.product_uom_qty: - raise UserError( - _("Qty di Koli tidak sesuai dengan qty retur untuk produk %s") % line.product_id.display_name) - + # Cek apakah ada BU/PICK di origin + origin = self.operations.origin + has_bu_pick = self.env['stock.picking'].search_count([ + ('origin', '=', origin), + ('picking_type_id', '=', 30), + ('state', '!=', 'cancel') + ]) > 0 + + if has_bu_pick: + for line in self.line_ids: + mapping_lines = self.mapping_koli_ids.filtered(lambda x: x.product_id == line.product_id) + total_qty = sum(l.qty_return for l in mapping_lines) + if total_qty != line.product_uom_qty: + raise UserError( + _("Qty di Koli tidak sesuai dengan qty retur untuk produk %s") % line.product_id.display_name + ) # self._check_invoice_on_revisi_so() self._validate_product_lines() @@ -544,12 +553,22 @@ class TukarGuling(models.Model): tipe = self.return_type if self.operations.picking_type_id.id == 29: - for line in self.line_ids: - mapping_lines = self.mapping_koli_ids.filtered(lambda x: x.product_id == line.product_id) - total_qty = sum(l.qty_return for l in mapping_lines) - if total_qty != line.product_uom_qty: - raise UserError( - _("Qty di Koli tidak sesuai dengan qty retur untuk produk %s") % line.product_id.display_name) + # Cek apakah ada BU/PICK di origin + origin = self.operations.origin + has_bu_pick = self.env['stock.picking'].search_count([ + ('origin', '=', origin), + ('picking_type_id', '=', 30), + ('state', '!=', 'cancel') + ]) > 0 + + if has_bu_pick: + for line in self.line_ids: + mapping_lines = self.mapping_koli_ids.filtered(lambda x: x.product_id == line.product_id) + total_qty = sum(l.qty_return for l in mapping_lines) + if total_qty != line.product_uom_qty: + raise UserError( + _("Qty di Koli tidak sesuai dengan qty retur untuk produk %s") % line.product_id.display_name + ) if operasi == 30 and self.operations.linked_manual_bu_out.state == 'done': raise UserError("❌ Tidak bisa retur BU/PICK karena BU/OUT sudah done") -- cgit v1.2.3 From 3ea10365d477bba3e5565dc636824a2b42bc8fca Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 6 Aug 2025 14:49:35 +0700 Subject: refactor due extension --- indoteknik_custom/models/account_move_due_extension.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_due_extension.py b/indoteknik_custom/models/account_move_due_extension.py index 4a3f40e2..d354e3e3 100644 --- a/indoteknik_custom/models/account_move_due_extension.py +++ b/indoteknik_custom/models/account_move_due_extension.py @@ -33,6 +33,7 @@ class DueExtension(models.Model): counter = fields.Integer(string="Counter", compute='_compute_counter') approve_by = fields.Many2one('res.users', string="Approve By", readonly=True) date_approve = fields.Datetime(string="Date Approve", readonly=True) + def _compute_counter(self): for due in self: due.counter = due.partner_id.counter @@ -102,6 +103,14 @@ class DueExtension(models.Model): self.date_approve = datetime.utcnow() template = self.env.ref('indoteknik_custom.mail_template_due_extension_approve') template.send_mail(self.id, force_send=True) + return { + 'type': 'ir.actions.act_window', + 'res_model': 'sale.order', + 'view_mode': 'form', + 'res_id': self.order_id.id, + 'views': [(False, 'form')], + 'target': 'current', + } def generate_due_line(self): partners = self.partner_id.get_child_ids() -- cgit v1.2.3 From d1a6e4a2d63cf3dd82ede0f8906957675ca38934 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 7 Aug 2025 09:22:07 +0700 Subject: payment partial --- indoteknik_custom/models/account_move.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 595c5655..c5e01f0c 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -95,6 +95,14 @@ class AccountMove(models.Model): ) payment_date = fields.Date(string="Payment Date", compute='_compute_payment_date') + partial_payment = fields.Float(string="Partial Payment", compute='compute_partial_payment') + + 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': + move.partial_payment = move.amount_total_signed - move.amount_residual_signed + else: + move.partial_payment = 0 def _compute_payment_date(self): for move in self: -- cgit v1.2.3 From b223b752b43eb0aa8fd685d895d5649996473baf Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 7 Aug 2025 13:26:53 +0700 Subject: Fix role permission --- indoteknik_custom/models/tukar_guling_po.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 5d444472..cbbfb348 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -430,8 +430,8 @@ class TukarGulingPO(models.Model): # Cek hak akses berdasarkan state for rec in self: if rec.state == 'approval_purchase': - if not rec.env.user.has_group('indoteknik_custom.group_role_sales'): - raise UserError("Hanya Sales yang boleh approve tahap ini.") + if not rec.env.user.has_group('indoteknik_custom.group_role_purchasing'): + raise UserError("Hanya Purchasing yang boleh approve tahap ini.") rec.state = 'approval_finance' rec.date_purchase = now -- cgit v1.2.3 From 191674fade65d63c54807e30b569fc308688df9a Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Thu, 7 Aug 2025 16:22:02 +0700 Subject: (andri) rev approval --- indoteknik_custom/models/sale_order.py | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 94cfdc39..6dc1b4a2 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2159,7 +2159,9 @@ class SaleOrder(models.Model): # if order.validate_partner_invoice_due(): # return self._create_notification_action('Notification', # 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') - + + if not order._is_request_to_own_team_leader(): + raise UserError("Anda hanya dapat mengonfirmasi SO dari anggota tim Anda sendiri.") if order._requires_approval_margin_leader(): order.approval_status = 'pengajuan2' return self._create_approval_notification('Pimpinan') @@ -2490,10 +2492,37 @@ class SaleOrder(models.Model): def _requires_approval_margin_leader(self): return self.total_percent_margin <= 15 and not self.env.user.is_leader - def _requires_approval_margin_manager(self): - return 15 < self.total_percent_margin <= 24 and not self.env.user.is_sales_manager and not self.env.user.id == 375 and not self.env.user.is_leader + # def _requires_approval_margin_manager(self): + # return 15 < self.total_percent_margin <= 24 and not self.env.user.is_sales_manager and not self.env.user.id == 375 and not self.env.user.is_leader # return self.total_percent_margin >= 15 and not self.env.user.is_leader and not self.env.user.is_sales_manager + def _requires_approval_margin_manager(self): + margin = self.total_percent_margin + user = self.env.user + user_id = user.id + + if margin <= 15 or margin > 24: # Di luar range margin manager approval + return False + if (user.is_leader or (margin >= 17 and user.is_sales_manager) or (margin >= 18 and user_id in [11, 9, 375])): + return False + + return True # Butuh approval manager + + def _is_request_to_own_team_leader(self): + approver_id = self.env.user.id + salesperson_id = self.user_id.id + team_map = { + 11: [10406], # Eko : Firman + 9: [11314, 6609], # Ade : Boy, Mario + 375: [9928, 10], # Putra : Aro, Putri + } + + for lead_id, members in team_map.items(): + if salesperson_id in members: + return approver_id == lead_id + + return True + def _create_approval_notification(self, approval_role): title = 'Warning' message = f'SO butuh approval {approval_role}' -- cgit v1.2.3 From cad72ba8d36cff00190143a655c18765e93851fe Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Thu, 7 Aug 2025 16:34:25 +0700 Subject: (andri) use salesteam --- indoteknik_custom/models/sale_order.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6dc1b4a2..a2817ea6 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2509,17 +2509,15 @@ class SaleOrder(models.Model): return True # Butuh approval manager def _is_request_to_own_team_leader(self): - approver_id = self.env.user.id + if not self.team_id or not self.team_id.user_id: + return True + salesperson_id = self.user_id.id - team_map = { - 11: [10406], # Eko : Firman - 9: [11314, 6609], # Ade : Boy, Mario - 375: [9928, 10], # Putra : Aro, Putri - } + approver_id = self.env.user.id + team_leader_id = self.team_id.user_id.id - for lead_id, members in team_map.items(): - if salesperson_id in members: - return approver_id == lead_id + if salesperson_id != approver_id and approver_id != team_leader_id: + return False return True -- cgit v1.2.3 From 663b5280d5f9d940c99ccf34f0d88c520eaebeb7 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 7 Aug 2025 18:00:22 +0700 Subject: fix move line location not sync with stock picking --- indoteknik_custom/models/tukar_guling.py | 49 +++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 881021ab..394672d0 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -636,6 +636,23 @@ class TukarGuling(models.Model): def _create_pickings(self): _logger.info("🛠 Starting _create_pickings()") + + def _force_locations(picking, from_loc, to_loc): + picking.write({ + 'location_id': from_loc, + 'location_dest_id': to_loc, + }) + for move in picking.move_lines: + move.write({ + 'location_id': from_loc, + 'location_dest_id': to_loc, + }) + for move_line in move.move_line_ids: + move_line.write({ + 'location_id': from_loc, + 'location_dest_id': to_loc, + }) + for record in self: if not record.operations: raise UserError("BU/OUT dari field operations tidak ditemukan.") @@ -680,14 +697,13 @@ class TukarGuling(models.Model): }).create({ 'picking_id': bu_out.id, 'location_id': PARTNER_LOCATION_ID, - 'original_location_id': BU_OUTPUT_LOCATION_ID, 'product_return_moves': srt_return_lines }) srt_vals = srt_wizard.create_returns() srt_picking = self.env['stock.picking'].browse(srt_vals['res_id']) + _force_locations(srt_picking, PARTNER_LOCATION_ID, BU_OUTPUT_LOCATION_ID) + srt_picking.write({ - 'location_id': PARTNER_LOCATION_ID, - 'location_dest_id': BU_OUTPUT_LOCATION_ID, 'group_id': bu_out.group_id.id, 'tukar_guling_id': record.id, 'sale_order': record.origin @@ -700,13 +716,11 @@ class TukarGuling(models.Model): ### ======== ORT dari BU/PICK ========= ort_pickings = [] is_retur_from_bu_pick = record.operations.picking_type_id.id == 30 - picks_to_return = [record.operations] if is_retur_from_bu_pick else mapping_koli.mapped( - 'pick_id') or line.product_uom_qty + picks_to_return = [record.operations] if is_retur_from_bu_pick else mapping_koli.mapped('pick_id') for pick in picks_to_return: ort_return_lines = [] if is_retur_from_bu_pick: - # Ambil dari tukar.guling.line for line in record.line_ids: move = pick.move_lines.filtered(lambda m: m.product_id == line.product_id) if not move: @@ -720,7 +734,6 @@ class TukarGuling(models.Model): _logger.info( f"📟 ORT (BU/PICK langsung) | {pick.name} | {line.product_id.display_name} | qty={line.product_uom_qty}") else: - # Ambil dari mapping koli for mk in mapping_koli.filtered(lambda m: m.pick_id == pick): move = pick.move_lines.filtered(lambda m: m.product_id == mk.product_id) if not move: @@ -743,27 +756,27 @@ class TukarGuling(models.Model): }).create({ 'picking_id': pick.id, 'location_id': BU_OUTPUT_LOCATION_ID, - 'original_location_id': BU_STOCK_LOCATION_ID, 'product_return_moves': ort_return_lines }) + ort_vals = ort_wizard.create_returns() ort_picking = self.env['stock.picking'].browse(ort_vals['res_id']) + _force_locations(ort_picking, BU_OUTPUT_LOCATION_ID, BU_STOCK_LOCATION_ID) + ort_picking.write({ - 'location_id': BU_OUTPUT_LOCATION_ID, - 'location_dest_id': BU_STOCK_LOCATION_ID, 'group_id': bu_out.group_id.id, 'tukar_guling_id': record.id, 'sale_order': record.origin }) + created_returns.append(ort_picking) ort_pickings.append(ort_picking) _logger.info(f"✅ ORT created: {ort_picking.name}") record.message_post( body=f"📦 {ort_picking.name} created by {self.env.user.name} (state: {ort_picking.state})") - ### ======== Tukar Guling: BU/OUT dan BU/PICK baru ======== + ### ======== BU/PICK & BU/OUT Baru dari SRT/ORT ======== if record.return_type == 'tukar_guling': - # BU/PICK Baru dari ORT for ort_p in ort_pickings: return_lines = [] @@ -789,19 +802,18 @@ class TukarGuling(models.Model): }).create({ 'picking_id': ort_p.id, 'location_id': BU_STOCK_LOCATION_ID, - 'original_location_id': BU_OUTPUT_LOCATION_ID, 'product_return_moves': return_lines }) bu_pick_vals = bu_pick_wizard.create_returns() new_pick = self.env['stock.picking'].browse(bu_pick_vals['res_id']) + _force_locations(new_pick, BU_STOCK_LOCATION_ID, BU_OUTPUT_LOCATION_ID) + new_pick.write({ - 'location_id': BU_STOCK_LOCATION_ID, - 'location_dest_id': BU_OUTPUT_LOCATION_ID, 'group_id': bu_out.group_id.id, 'tukar_guling_id': record.id, 'sale_order': record.origin }) - new_pick.action_assign() # Penting agar bisa trigger check koli + new_pick.action_assign() new_pick.action_confirm() created_returns.append(new_pick) _logger.info(f"✅ BU/PICK Baru dari ORT created: {new_pick.name}") @@ -829,14 +841,13 @@ class TukarGuling(models.Model): }).create({ 'picking_id': srt_picking.id, 'location_id': BU_OUTPUT_LOCATION_ID, - 'original_location_id': PARTNER_LOCATION_ID, 'product_return_moves': return_lines }) bu_out_vals = bu_out_wizard.create_returns() new_out = self.env['stock.picking'].browse(bu_out_vals['res_id']) + _force_locations(new_out, BU_OUTPUT_LOCATION_ID, PARTNER_LOCATION_ID) + new_out.write({ - 'location_id': BU_OUTPUT_LOCATION_ID, - 'location_dest_id': PARTNER_LOCATION_ID, 'group_id': bu_out.group_id.id, 'tukar_guling_id': record.id, 'sale_order': record.origin -- cgit v1.2.3 From 26b1df8d150a46297d84f24283687c56b81e4e65 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 7 Aug 2025 20:12:49 +0700 Subject: fix for SO lama, where it doesnt have bu pick. srt set to partner loc to stcok --- indoteknik_custom/models/tukar_guling.py | 44 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 394672d0..4c7722d5 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -675,33 +675,51 @@ class TukarGuling(models.Model): ### ======== SRT dari BU/OUT ========= srt_return_lines = [] - for prod in mapping_koli.mapped('product_id'): - qty_total = sum(mk.qty_return for mk in mapping_koli.filtered(lambda m: m.product_id == prod)) - move = bu_out.move_lines.filtered(lambda m: m.product_id == prod) - if not move: - raise UserError(f"Move BU/OUT tidak ditemukan untuk produk {prod.display_name}") - srt_return_lines.append((0, 0, { - 'product_id': prod.id, - 'quantity': qty_total, - 'move_id': move.id, - })) - _logger.info(f"📟 SRT line: {prod.display_name} | qty={qty_total}") + if mapping_koli: + for prod in mapping_koli.mapped('product_id'): + qty_total = sum(mk.qty_return for mk in mapping_koli.filtered(lambda m: m.product_id == prod)) + move = bu_out.move_lines.filtered(lambda m: m.product_id == prod) + if not move: + raise UserError(f"Move BU/OUT tidak ditemukan untuk produk {prod.display_name}") + srt_return_lines.append((0, 0, { + 'product_id': prod.id, + 'quantity': qty_total, + 'move_id': move.id, + })) + _logger.info(f"📟 SRT line: {prod.display_name} | qty={qty_total}") + + elif not mapping_koli: + for line in record.line_ids: + move = bu_out.move_lines.filtered(lambda m: m.product_id == line.product_id) + if not move: + raise UserError(f"Move BU/OUT tidak ditemukan untuk produk {line.product_id.display_name}") + srt_return_lines.append((0, 0, { + 'product_id': line.product_id.id, + 'quantity': line.product_uom_qty, + 'move_id': move.id, + })) + _logger.info( + f"📟 SRT line (fallback line_ids): {line.product_id.display_name} | qty={line.product_uom_qty}") srt_picking = None if srt_return_lines: + # Tentukan tujuan lokasi berdasarkan ada/tidaknya mapping_koli + dest_location_id = BU_OUTPUT_LOCATION_ID if mapping_koli else BU_STOCK_LOCATION_ID + srt_wizard = self.env['stock.return.picking'].with_context({ 'active_id': bu_out.id, 'default_location_id': PARTNER_LOCATION_ID, - 'default_location_dest_id': BU_OUTPUT_LOCATION_ID, + 'default_location_dest_id': dest_location_id, 'from_ui': False, }).create({ 'picking_id': bu_out.id, 'location_id': PARTNER_LOCATION_ID, 'product_return_moves': srt_return_lines }) + srt_vals = srt_wizard.create_returns() srt_picking = self.env['stock.picking'].browse(srt_vals['res_id']) - _force_locations(srt_picking, PARTNER_LOCATION_ID, BU_OUTPUT_LOCATION_ID) + _force_locations(srt_picking, PARTNER_LOCATION_ID, dest_location_id) srt_picking.write({ 'group_id': bu_out.group_id.id, -- cgit v1.2.3 From 176dd85c3d809c035128847378bf78d96aa0896a Mon Sep 17 00:00:00 2001 From: Miqdad Date: Fri, 8 Aug 2025 09:16:15 +0700 Subject: handle duplicate prod in stock move line --- indoteknik_custom/models/tukar_guling.py | 87 ++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 20 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 4c7722d5..eadb164c 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -2,6 +2,7 @@ from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError import logging from datetime import datetime +from collections import defaultdict _logger = logging.getLogger(__name__) @@ -540,7 +541,7 @@ class TukarGuling(models.Model): ]) if self.state == 'approved' and done_ort: self.state = 'done' - else: + elif self.operations.picking_type_id.id == 30 and self.return_type == 'revisi_so' and not has_bu_pick: raise UserError("Tidak bisa menentukan jenis retur.") def action_approve(self): @@ -676,30 +677,47 @@ class TukarGuling(models.Model): ### ======== SRT dari BU/OUT ========= srt_return_lines = [] if mapping_koli: - for prod in mapping_koli.mapped('product_id'): - qty_total = sum(mk.qty_return for mk in mapping_koli.filtered(lambda m: m.product_id == prod)) - move = bu_out.move_lines.filtered(lambda m: m.product_id == prod) - if not move: - raise UserError(f"Move BU/OUT tidak ditemukan untuk produk {prod.display_name}") + move_per_product = defaultdict(list) + for move in bu_out.move_lines: + move_per_product[move.product_id.id].append(move) + + mapped_product_ids = set(mapping_koli.mapped('product_id').ids) + + for product_id in mapped_product_ids: + qty_ret = sum( + line.qty_return for line in mapping_koli.filtered(lambda l: l.product_id.id == product_id)) + if qty_ret <= 0: + continue + + product_moves = move_per_product[product_id] + if not product_moves: + raise UserError(f"❌ Move BU/OUT tidak ditemukan untuk product ID {product_id}") + + if len(product_moves) > 1: + _logger.warning(f"🟠 Detected duplicate moves for product {product_id}, picking {bu_out.name}") + chosen_move = product_moves[0] + else: + chosen_move = product_moves[0] + srt_return_lines.append((0, 0, { - 'product_id': prod.id, - 'quantity': qty_total, - 'move_id': move.id, + 'product_id': product_id, + 'quantity': qty_ret, + 'move_id': chosen_move.id, })) - _logger.info(f"📟 SRT line: {prod.display_name} | qty={qty_total}") + _logger.info(f"📟 SRT line: {chosen_move.product_id.display_name} | qty={qty_ret}") - elif not mapping_koli: + else: + # --- Fallback ke line_ids jika tidak ada mapping_koli --- for line in record.line_ids: move = bu_out.move_lines.filtered(lambda m: m.product_id == line.product_id) if not move: - raise UserError(f"Move BU/OUT tidak ditemukan untuk produk {line.product_id.display_name}") + raise UserError(f"❌ Move BU/OUT tidak ditemukan untuk produk {line.product_id.display_name}") srt_return_lines.append((0, 0, { 'product_id': line.product_id.id, 'quantity': line.product_uom_qty, 'move_id': move.id, })) - _logger.info( - f"📟 SRT line (fallback line_ids): {line.product_id.display_name} | qty={line.product_uom_qty}") + _logger.info(f"📟 SRT line (fallback): {line.product_id.display_name} | qty={line.product_uom_qty}") srt_picking = None if srt_return_lines: @@ -738,33 +756,62 @@ class TukarGuling(models.Model): for pick in picks_to_return: ort_return_lines = [] + if is_retur_from_bu_pick: + # Build map produk -> move list + move_map = defaultdict(list) + for move in pick.move_lines: + move_map[move.product_id.id].append(move) + for line in record.line_ids: - move = pick.move_lines.filtered(lambda m: m.product_id == line.product_id) - if not move: + moves = move_map.get(line.product_id.id) + if not moves: raise UserError( f"Move tidak ditemukan di BU/PICK {pick.name} untuk {line.product_id.display_name}") + + chosen_move = moves[0] + if len(moves) > 1: + _logger.warning( + f"🟠 Duplicate move detected for {line.product_id.display_name} in {pick.name}. Using the first move only.") + pick.message_post( + body=f"🟠 Duplicate move ditemukan untuk produk {line.product_id.display_name}. Hanya 1 move yang dipakai.") + ort_return_lines.append((0, 0, { 'product_id': line.product_id.id, 'quantity': line.product_uom_qty, - 'move_id': move.id, + 'move_id': chosen_move.id, })) _logger.info( f"📟 ORT (BU/PICK langsung) | {pick.name} | {line.product_id.display_name} | qty={line.product_uom_qty}") + else: + # Mapping koli case + move_map = defaultdict(list) + for move in pick.move_lines: + move_map[move.product_id.id].append(move) + for mk in mapping_koli.filtered(lambda m: m.pick_id == pick): - move = pick.move_lines.filtered(lambda m: m.product_id == mk.product_id) - if not move: + moves = move_map.get(mk.product_id.id) + if not moves: raise UserError( f"Move tidak ditemukan di BU/PICK {pick.name} untuk {mk.product_id.display_name}") + + chosen_move = moves[0] + if len(moves) > 1: + _logger.warning( + f"🟠 Duplicate move detected for {mk.product_id.display_name} in {pick.name}. Using the first move only.") + pick.message_post( + body=f"🟠 Duplicate move ditemukan untuk produk {mk.product_id.display_name}. Hanya 1 move yang dipakai.") + ort_return_lines.append((0, 0, { 'product_id': mk.product_id.id, 'quantity': mk.qty_return, - 'move_id': move.id, + 'move_id': chosen_move.id, })) _logger.info( f"📟 ORT (mapping koli) | {pick.name} | {mk.product_id.display_name} | qty={mk.qty_return}") + # Buat retur jika ada return line if ort_return_lines: ort_wizard = self.env['stock.return.picking'].with_context({ 'active_id': pick.id, -- cgit v1.2.3 From 00cb2b4dcf1e6892a6b4943b08c3bd3f5810432b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 8 Aug 2025 10:09:25 +0700 Subject: fix hold outgoing reserve --- indoteknik_custom/models/approval_payment_term.py | 2 +- indoteknik_custom/models/stock_picking.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py index 6c857b45..a2ecd27f 100644 --- a/indoteknik_custom/models/approval_payment_term.py +++ b/indoteknik_custom/models/approval_payment_term.py @@ -38,7 +38,7 @@ class ApprovalPaymentTerm(models.Model): ('approved', 'Approved'), ('rejected', 'Rejected')], default='waiting_approval_sales_manager', tracking=True) - reason_reject = fields.Selection([('reason1', 'Reason 1'), ('reason2', 'Reason 2'), ('reason3', 'Reason 3')], string='Reason Reject', tracking=True) + reason_reject = fields.Text(string='Reason Reject', tracking=True) sale_order_ids = fields.Many2many( 'sale.order', string='Sale Orders', diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index f2f5f52a..46bb6cee 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1059,17 +1059,21 @@ class StockPicking(models.Model): return self.sale_id.date_doc_kirim = self.date_doc_kirim + from odoo import fields + def action_assign(self): - res = super(StockPicking, self).action_assign() - for move in self: - # if not move.sale_id.hold_outgoing and move.location_id.id != 57 and move.location_dest_id.id != 60: - # TODO cant skip hold outgoing cause of not singleton method - current_time = datetime.datetime.utcnow() - move.real_shipping_id = move.sale_id.real_shipping_id - move.date_availability = current_time - # self.check_state_reserve() + pickings_to_assign = self.filtered(lambda p: not (p.sale_id and p.sale_id.hold_outgoing)) + + res = super(StockPicking, pickings_to_assign).action_assign() + + current_time = datetime.datetime.utcnow() + for picking in pickings_to_assign: + picking.real_shipping_id = picking.sale_id.real_shipping_id + picking.date_availability = current_time + return res + def ask_approval(self): if self.env.user.is_accounting: raise UserError("Bisa langsung Validate") -- cgit v1.2.3 From 84bc1b36415d2f8baecaf6d5acdd4bf77d4187e0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 8 Aug 2025 10:17:52 +0700 Subject: fix bug apt --- indoteknik_custom/models/approval_payment_term.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py index a2ecd27f..4cf9a4c8 100644 --- a/indoteknik_custom/models/approval_payment_term.py +++ b/indoteknik_custom/models/approval_payment_term.py @@ -38,7 +38,8 @@ class ApprovalPaymentTerm(models.Model): ('approved', 'Approved'), ('rejected', 'Rejected')], default='waiting_approval_sales_manager', tracking=True) - reason_reject = fields.Text(string='Reason Reject', tracking=True) + reason_reject = fields.Selection([('reason1', 'Reason 1'), ('reason2', 'Reason 2'), ('reason3', 'Reason 3')], string='Reason Reject', tracking=True) + reject_reason = fields.Text('Reject Reason', tracking=True) sale_order_ids = fields.Many2many( 'sale.order', string='Sale Orders', -- cgit v1.2.3 From ccdebe1c144323569efa2a9eecbcb4ca7849960e Mon Sep 17 00:00:00 2001 From: Miqdad Date: Fri, 8 Aug 2025 13:13:31 +0700 Subject: cancel permission --- indoteknik_custom/models/tukar_guling_po.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index cbbfb348..0badc117 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -497,7 +497,7 @@ class TukarGulingPO(models.Model): user = self.env.user if not ( - user.has_group('indoteknik_custom.group_role_sales') or + user.has_group('indoteknik_custom.group_role_purchasing') or user.has_group('indoteknik_custom.group_role_fat') or user.has_group('indoteknik_custom.group_role_logistic') ): -- cgit v1.2.3 From 678f0a55a4e340ed8fb448a528cb738e10ed84bd Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Fri, 8 Aug 2025 14:37:10 +0700 Subject: (andri) fix --- indoteknik_custom/models/sale_order.py | 53 ++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index a2817ea6..5e3f8965 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2161,7 +2161,10 @@ class SaleOrder(models.Model): # 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') if not order._is_request_to_own_team_leader(): - raise UserError("Anda hanya dapat mengonfirmasi SO dari anggota tim Anda sendiri.") + return self._create_notification_action( + 'Peringatan', + 'Hanya bisa konfirmasi SO tim Anda.' + ) if order._requires_approval_margin_leader(): order.approval_status = 'pengajuan2' return self._create_approval_notification('Pimpinan') @@ -2171,6 +2174,12 @@ class SaleOrder(models.Model): self.check_limit_so_to_invoice() order.approval_status = 'pengajuan1' return self._create_approval_notification('Sales Manager') + elif order._requires_approval_team_sales(): + self.check_product_bom() + self.check_credit_limit() + self.check_limit_so_to_invoice() + order.approval_status = 'pengajuan1' + return self._create_approval_notification('Team Sales') raise UserError("Bisa langsung Confirm") @@ -2387,12 +2396,20 @@ class SaleOrder(models.Model): return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') + if not order._is_request_to_own_team_leader(): + return self._create_notification_action( + 'Warning', + 'Hanya bisa konfirmasi SO tim Anda.' + ) if order._requires_approval_margin_leader(): order.approval_status = 'pengajuan2' return self._create_approval_notification('Pimpinan') elif order._requires_approval_margin_manager(): order.approval_status = 'pengajuan1' return self._create_approval_notification('Sales Manager') + elif order._requires_approval_team_sales(): + order.approval_status = 'pengajuan1' + return self._create_approval_notification('Team Sales') order.approval_status = 'approved' order._set_sppkp_npwp_contact() @@ -2492,34 +2509,34 @@ class SaleOrder(models.Model): def _requires_approval_margin_leader(self): return self.total_percent_margin <= 15 and not self.env.user.is_leader - # def _requires_approval_margin_manager(self): - # return 15 < self.total_percent_margin <= 24 and not self.env.user.is_sales_manager and not self.env.user.id == 375 and not self.env.user.is_leader - # return self.total_percent_margin >= 15 and not self.env.user.is_leader and not self.env.user.is_sales_manager - def _requires_approval_margin_manager(self): - margin = self.total_percent_margin - user = self.env.user - user_id = user.id + return 15 < self.total_percent_margin < 18 and not self.env.user.is_sales_manager and not self.env.user.id == 375 and not self.env.user.is_leader + + def _requires_approval_team_sales(self): + return ( + 18 <= self.total_percent_margin <= 24 + and self.env.user.id not in [11, 9, 375] # Eko, Ade, Putra + and not self.env.user.is_sales_manager + and not self.env.user.is_leader + ) - if margin <= 15 or margin > 24: # Di luar range margin manager approval - return False - if (user.is_leader or (margin >= 17 and user.is_sales_manager) or (margin >= 18 and user_id in [11, 9, 375])): - return False - - return True # Butuh approval manager def _is_request_to_own_team_leader(self): + user = self.env.user + + # Pengecualian Pak Akbar & Darren + if user.is_leader or user.is_sales_manager: + return True + if not self.team_id or not self.team_id.user_id: return True salesperson_id = self.user_id.id - approver_id = self.env.user.id + approver_id = user.id team_leader_id = self.team_id.user_id.id - if salesperson_id != approver_id and approver_id != team_leader_id: - return False + return salesperson_id == approver_id or approver_id == team_leader_id - return True def _create_approval_notification(self, approval_role): title = 'Warning' -- cgit v1.2.3 From 9951cd96e968f0e3b934dd97838f4825e6d27c6b Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Fri, 8 Aug 2025 14:44:07 +0700 Subject: (andri) fix --- indoteknik_custom/models/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5e3f8965..5eb90d83 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2178,7 +2178,7 @@ class SaleOrder(models.Model): self.check_product_bom() self.check_credit_limit() self.check_limit_so_to_invoice() - order.approval_status = 'pengajuan1' + order.approval_status = 'approved' return self._create_approval_notification('Team Sales') raise UserError("Bisa langsung Confirm") @@ -2408,7 +2408,7 @@ class SaleOrder(models.Model): order.approval_status = 'pengajuan1' return self._create_approval_notification('Sales Manager') elif order._requires_approval_team_sales(): - order.approval_status = 'pengajuan1' + order.approval_status = 'approved' return self._create_approval_notification('Team Sales') order.approval_status = 'approved' -- cgit v1.2.3 From 181646555a2d7467acf0595544f5a533342563e5 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Fri, 8 Aug 2025 15:53:46 +0700 Subject: revert to last good commit --- indoteknik_custom/models/tukar_guling.py | 87 ++++++++------------------------ 1 file changed, 20 insertions(+), 67 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index eadb164c..4c7722d5 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -2,7 +2,6 @@ from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError import logging from datetime import datetime -from collections import defaultdict _logger = logging.getLogger(__name__) @@ -541,7 +540,7 @@ class TukarGuling(models.Model): ]) if self.state == 'approved' and done_ort: self.state = 'done' - elif self.operations.picking_type_id.id == 30 and self.return_type == 'revisi_so' and not has_bu_pick: + else: raise UserError("Tidak bisa menentukan jenis retur.") def action_approve(self): @@ -677,47 +676,30 @@ class TukarGuling(models.Model): ### ======== SRT dari BU/OUT ========= srt_return_lines = [] if mapping_koli: - move_per_product = defaultdict(list) - for move in bu_out.move_lines: - move_per_product[move.product_id.id].append(move) - - mapped_product_ids = set(mapping_koli.mapped('product_id').ids) - - for product_id in mapped_product_ids: - qty_ret = sum( - line.qty_return for line in mapping_koli.filtered(lambda l: l.product_id.id == product_id)) - if qty_ret <= 0: - continue - - product_moves = move_per_product[product_id] - if not product_moves: - raise UserError(f"❌ Move BU/OUT tidak ditemukan untuk product ID {product_id}") - - if len(product_moves) > 1: - _logger.warning(f"🟠 Detected duplicate moves for product {product_id}, picking {bu_out.name}") - chosen_move = product_moves[0] - else: - chosen_move = product_moves[0] - + for prod in mapping_koli.mapped('product_id'): + qty_total = sum(mk.qty_return for mk in mapping_koli.filtered(lambda m: m.product_id == prod)) + move = bu_out.move_lines.filtered(lambda m: m.product_id == prod) + if not move: + raise UserError(f"Move BU/OUT tidak ditemukan untuk produk {prod.display_name}") srt_return_lines.append((0, 0, { - 'product_id': product_id, - 'quantity': qty_ret, - 'move_id': chosen_move.id, + 'product_id': prod.id, + 'quantity': qty_total, + 'move_id': move.id, })) - _logger.info(f"📟 SRT line: {chosen_move.product_id.display_name} | qty={qty_ret}") + _logger.info(f"📟 SRT line: {prod.display_name} | qty={qty_total}") - else: - # --- Fallback ke line_ids jika tidak ada mapping_koli --- + elif not mapping_koli: for line in record.line_ids: move = bu_out.move_lines.filtered(lambda m: m.product_id == line.product_id) if not move: - raise UserError(f"❌ Move BU/OUT tidak ditemukan untuk produk {line.product_id.display_name}") + raise UserError(f"Move BU/OUT tidak ditemukan untuk produk {line.product_id.display_name}") srt_return_lines.append((0, 0, { 'product_id': line.product_id.id, 'quantity': line.product_uom_qty, 'move_id': move.id, })) - _logger.info(f"📟 SRT line (fallback): {line.product_id.display_name} | qty={line.product_uom_qty}") + _logger.info( + f"📟 SRT line (fallback line_ids): {line.product_id.display_name} | qty={line.product_uom_qty}") srt_picking = None if srt_return_lines: @@ -756,62 +738,33 @@ class TukarGuling(models.Model): for pick in picks_to_return: ort_return_lines = [] - if is_retur_from_bu_pick: - # Build map produk -> move list - move_map = defaultdict(list) - for move in pick.move_lines: - move_map[move.product_id.id].append(move) - for line in record.line_ids: - moves = move_map.get(line.product_id.id) - if not moves: + move = pick.move_lines.filtered(lambda m: m.product_id == line.product_id) + if not move: raise UserError( f"Move tidak ditemukan di BU/PICK {pick.name} untuk {line.product_id.display_name}") - - chosen_move = moves[0] - if len(moves) > 1: - _logger.warning( - f"🟠 Duplicate move detected for {line.product_id.display_name} in {pick.name}. Using the first move only.") - pick.message_post( - body=f"🟠 Duplicate move ditemukan untuk produk {line.product_id.display_name}. Hanya 1 move yang dipakai.") - ort_return_lines.append((0, 0, { 'product_id': line.product_id.id, 'quantity': line.product_uom_qty, - 'move_id': chosen_move.id, + 'move_id': move.id, })) _logger.info( f"📟 ORT (BU/PICK langsung) | {pick.name} | {line.product_id.display_name} | qty={line.product_uom_qty}") - else: - # Mapping koli case - move_map = defaultdict(list) - for move in pick.move_lines: - move_map[move.product_id.id].append(move) - for mk in mapping_koli.filtered(lambda m: m.pick_id == pick): - moves = move_map.get(mk.product_id.id) - if not moves: + move = pick.move_lines.filtered(lambda m: m.product_id == mk.product_id) + if not move: raise UserError( f"Move tidak ditemukan di BU/PICK {pick.name} untuk {mk.product_id.display_name}") - - chosen_move = moves[0] - if len(moves) > 1: - _logger.warning( - f"🟠 Duplicate move detected for {mk.product_id.display_name} in {pick.name}. Using the first move only.") - pick.message_post( - body=f"🟠 Duplicate move ditemukan untuk produk {mk.product_id.display_name}. Hanya 1 move yang dipakai.") - ort_return_lines.append((0, 0, { 'product_id': mk.product_id.id, 'quantity': mk.qty_return, - 'move_id': chosen_move.id, + 'move_id': move.id, })) _logger.info( f"📟 ORT (mapping koli) | {pick.name} | {mk.product_id.display_name} | qty={mk.qty_return}") - # Buat retur jika ada return line if ort_return_lines: ort_wizard = self.env['stock.return.picking'].with_context({ 'active_id': pick.id, -- cgit v1.2.3 From abbf20da12e9f9cdcb24b9018eecc6d52812f92e Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Fri, 8 Aug 2025 16:03:46 +0700 Subject: (andri) add email salesperson inv di CC --- indoteknik_custom/models/account_move.py | 66 ++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 12978a2f..fd08ed60 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -144,17 +144,24 @@ class AccountMove(models.Model): today + timedelta(days=7), ] - partner = self.env['res.partner'].search([('name', 'ilike', 'DIRGANTARA YUDHA ARTHA')], limit=1) - if not partner: - _logger.info("Partner tidak ditemukan.") - return + # --- TESTING --- + # partner = self.env['res.partner'].search([('name', 'ilike', 'DIRGANTARA YUDHA ARTHA')], limit=1) + # if not partner: + # _logger.info("Partner tidak ditemukan.") + # return + # invoices = self.env['account.move'].search([ + # ('move_type', '=', 'out_invoice'), + # ('state', '=', 'posted'), + # ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), + # ('invoice_date_due', 'in', target_dates), + # ('partner_id', '=', partner.id), + # ]) invoices = self.env['account.move'].search([ ('move_type', '=', 'out_invoice'), ('state', '=', 'posted'), ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), ('invoice_date_due', 'in', target_dates), - ('partner_id', '=', partner.id), ]) _logger.info(f"Invoices tahap 1: {invoices}") @@ -164,10 +171,9 @@ class AccountMove(models.Model): _logger.info(f"Invoices tahap 2: {invoices}") if not invoices: - _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") + _logger.info("Tidak ada invoice yang due") return - # Kelompokkan invoice berdasarkan partner & days_to_due invoice_group = {} for inv in invoices: dtd = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 @@ -176,13 +182,12 @@ class AccountMove(models.Model): template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') for (partner, dtd), invs in invoice_group.items(): - # Cari semua kontak anak yang reminder_invoices = True dan punya email + # Ambil child contact yang di-checklist reminder_invoices reminder_contacts = self.env['res.partner'].search([ ('parent_id', '=', partner.id), ('reminder_invoices', '=', True), ('email', '!=', False), ]) - _logger.info(f"Email Reminder Child {reminder_contacts}") if not reminder_contacts: @@ -197,7 +202,6 @@ class AccountMove(models.Model): email_to = ",".join(emails) _logger.info(f"Email tujuan: {email_to}") - # Generate tabel invoice invoice_table_rows = "" for inv in invs: days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 @@ -213,12 +217,14 @@ class AccountMove(models.Model): {days_to_due} """ - dadada = self.partner_id.name - # Tentukan pesan berdasarkan sisa hari + days_to_due_message = "" closing_message = "" if dtd < 0: - days_to_due_message = f"Kami ingin mengingatkan bahwa tagihan anda akan jatuh tempo dalam {abs(dtd)} hari ke depan, dengan rincian sebagai berikut:" + days_to_due_message = ( + f"Kami ingin mengingatkan bahwa tagihan anda akan jatuh tempo dalam {abs(dtd)} hari ke depan, " + "dengan rincian sebagai berikut:" + ) closing_message = ( "Kami mengharapkan pembayaran dapat dilakukan tepat waktu untuk mendukung kelancaran " "hubungan kerja sama yang baik antara kedua belah pihak.
" @@ -227,7 +233,10 @@ class AccountMove(models.Model): ) if dtd == 0: - days_to_due_message = "Kami ingin mengingatkan bahwa tagihan anda telah memasuki tanggal jatuh tempo pada hari ini, dengan rincian sebagai berikut:" + days_to_due_message = ( + "Kami ingin mengingatkan bahwa tagihan anda telah memasuki tanggal jatuh tempo pada hari ini, " + "dengan rincian sebagai berikut:" + ) closing_message = ( "Mohon kesediaannya untuk segera melakukan pembayaran tepat waktu guna menghindari status " "keterlambatan dan menjaga kelancaran hubungan kerja sama yang telah terjalin dengan baik.
" @@ -236,7 +245,10 @@ class AccountMove(models.Model): ) if dtd > 0: - days_to_due_message = f"Kami ingin mengingatkan bahwa tagihan anda telah jatuh tempo selama {dtd} hari, dengan rincian sebagai berikut:" + days_to_due_message = ( + f"Kami ingin mengingatkan bahwa tagihan anda telah jatuh tempo selama {dtd} hari, " + "dengan rincian sebagai berikut:" + ) closing_message = ( "Mohon kesediaan Bapak/Ibu untuk segera melakukan pembayaran guna menghindari keterlambatan " "dan menjaga kelancaran kerja sama yang telah terjalin dengan baik.
" @@ -244,7 +256,6 @@ class AccountMove(models.Model): "Terima kasih atas perhatian dan kerja samanya." ) - subject = f"Reminder Invoice Due - {partner.name}" body_html = re.sub( r"]*>.*?", f"{invoice_table_rows}", @@ -255,15 +266,28 @@ class AccountMove(models.Model): .replace('${days_to_due_message}', days_to_due_message) \ .replace('${closing_message}', closing_message) + cc_list = [ + 'finance@indoteknik.co.id', + 'akbar@indoteknik.co.id', + 'stephan@indoteknik.co.id', + 'darren@indoteknik.co.id' + ] + sales_email = invs[0].invoice_user_id.partner_id.email if invs[0].invoice_user_id else None + if sales_email and sales_email not in cc_list: + cc_list.append(sales_email) + + # Siapkan email values values = { - 'subject': subject, - 'email_to': 'andrifebriyadiputra@gmail.com', + 'subject': f"Reminder Invoice Due - {partner.name}", + # 'email_to': 'andrifebriyadiputra@gmail.com', + 'email_to': email_to, 'email_from': 'finance@indoteknik.co.id', + 'email_cc': ",".join(cc_list), 'body_html': body_html, 'reply_to': 'finance@indoteknik.co.id', } - _logger.info(f"Mengirim email ke: {email_to}") + _logger.info(f"Mengirim email ke: {values['email_to']} CC: {values['email_cc']}") template.send_mail(invs[0].id, force_send=True, email_values=values) # Post ke chatter @@ -272,13 +296,13 @@ class AccountMove(models.Model): for inv in invs: inv.message_post( - subject=subject, + subject=values['subject'], body=body_html, subtype_id=self.env.ref('mail.mt_note').id, author_id=system_id, ) - _logger.info(f"Reminder terkirim ke {partner.name} ({email_to}) → {len(invs)} invoice (dtd = {dtd})") + _logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice (dtd = {dtd})") @api.onchange('invoice_date') -- cgit v1.2.3 From be4952c12d51106b4cffd6b7de1be09562829331 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Fri, 8 Aug 2025 16:55:59 +0700 Subject: (andri) fix approval --- indoteknik_custom/models/sale_order.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5eb90d83..125a049b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2528,6 +2528,9 @@ class SaleOrder(models.Model): if user.is_leader or user.is_sales_manager: return True + if user.id in (3401, 20, 3988): # admin (fida, nabila, ninda) + return True + if not self.team_id or not self.team_id.user_id: return True -- cgit v1.2.3 From 4303bc704835a48a3005d409f564030a2d53befc Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Fri, 8 Aug 2025 17:19:02 +0700 Subject: (andri) fix --- indoteknik_custom/models/sale_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 125a049b..e71e3830 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2160,9 +2160,9 @@ class SaleOrder(models.Model): # return self._create_notification_action('Notification', # 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') - if not order._is_request_to_own_team_leader(): + if not order.with_context(ask_approval=True)._is_request_to_own_team_leader(): return self._create_notification_action( - 'Peringatan', + 'Peringatan', 'Hanya bisa konfirmasi SO tim Anda.' ) if order._requires_approval_margin_leader(): @@ -2531,7 +2531,7 @@ class SaleOrder(models.Model): if user.id in (3401, 20, 3988): # admin (fida, nabila, ninda) return True - if not self.team_id or not self.team_id.user_id: + if self.env.context.get("ask_approval") and user.id in (3401, 20, 3988): return True salesperson_id = self.user_id.id -- cgit v1.2.3 From 06b661f2fa9e07e4b3d1d2b5c7aa9f16f057a3a3 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 9 Aug 2025 11:57:27 +0700 Subject: fix bug --- indoteknik_custom/models/stock_picking.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 46bb6cee..82f81642 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1059,10 +1059,13 @@ class StockPicking(models.Model): return self.sale_id.date_doc_kirim = self.date_doc_kirim - from odoo import fields - def action_assign(self): - pickings_to_assign = self.filtered(lambda p: not (p.sale_id and p.sale_id.hold_outgoing)) + if self.env.context.get('default_picking_type_id'): + pickings_to_assign = self.filtered( + lambda p: not (p.sale_id and p.sale_id.hold_outgoing) + ) + else: + pickings_to_assign = self res = super(StockPicking, pickings_to_assign).action_assign() -- cgit v1.2.3 From b6ae7b2c9f1c564f3bf2a471f4871fda745d215d Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 9 Aug 2025 13:59:11 +0700 Subject: origin so can be clicked --- indoteknik_custom/models/tukar_guling.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 4c7722d5..6aedb70e 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -32,7 +32,7 @@ class TukarGuling(models.Model): 'tukar_guling_id', string='Transfers' ) - # origin_so = fields.Many2one('sale.order', string='Origin SO') + origin_so = fields.Many2one('sale.order', string='Origin SO', compute='_compute_origin_so') name = fields.Char('Number', required=True, copy=False, readonly=True, default='New') date = fields.Datetime('Date', default=fields.Datetime.now, required=True) operations = fields.Many2one( @@ -83,6 +83,15 @@ class TukarGuling(models.Model): invoice_id = fields.Many2many('account.move', string='Invoice Ref', readonly=True) + @api.depends('origin', 'operations') + def _compute_origin_so(self): + for rec in self: + rec.origin_so = False + origin_str = rec.origin or rec.operations.origin + if origin_str: + so = self.env['sale.order'].search([('name', '=', origin_str)], limit=1) + rec.origin_so = so.id if so else False + @api.depends('origin') def _compute_is_has_invoice(self): for rec in self: @@ -144,8 +153,6 @@ class TukarGuling(models.Model): if self.line_ids and from_return_picking: # Hanya update origin, jangan ubah lines - if self.operations.origin: - self.origin = self.operations.origin _logger.info("📌 Menggunakan product lines dari return wizard, tidak populate ulang.") # 🚀 Tapi tetap populate mapping koli jika BU/OUT @@ -177,6 +184,7 @@ class TukarGuling(models.Model): # Set origin dari operations if self.operations.origin: self.origin = self.operations.origin + self.origin_so = self.operations.group_id.id # Auto-populate lines dari move_ids operations lines_data = [] @@ -332,17 +340,20 @@ class TukarGuling(models.Model): # _("Tidak bisa memilih Return Type 'Revisi SO' karena dokumen %s sudah dibuat invoice.") % record.origin # ) + @api.model def create(self, vals): - # Generate sequence number if not vals.get('name') or vals['name'] == 'New': vals['name'] = self.env['ir.sequence'].next_by_code('tukar.guling') - # Auto-fill origin from operations - if not vals.get('origin') and vals.get('operations'): + if vals.get('operations'): picking = self.env['stock.picking'].browse(vals['operations']) if picking.origin: vals['origin'] = picking.origin + # Find matching SO + so = self.env['sale.order'].search([('name', '=', picking.origin)], limit=1) + if so: + vals['origin_so'] = so.id if picking.partner_id: vals['partner_id'] = picking.partner_id.id @@ -350,6 +361,10 @@ class TukarGuling(models.Model): res.message_post(body=_("CCM Created By %s") % self.env.user.name) return res + res = super(TukarGuling, self).create(vals) + res.message_post(body=_("CCM Created By %s") % self.env.user.name) + return res + def copy(self, default=None): if default is None: default = {} -- cgit v1.2.3 From ba20997c842be46b6759aad7d4dfa3736c522982 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 9 Aug 2025 14:35:00 +0700 Subject: origin po can be clicked --- indoteknik_custom/models/tukar_guling_po.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 0badc117..03d7668f 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -62,6 +62,16 @@ class TukarGulingPO(models.Model): is_has_bill = fields.Boolean('Has Bill?', compute='_compute_is_has_bill', readonly=True, default=False) bill_id = fields.Many2many('account.move', string='Bill Ref', readonly=True) + origin_po = fields.Many2one('purchase.order', string='Origin PO', compute='_compute_origin_po') + + @api.depends('origin', 'operations') + def _compute_origin_po(self): + for rec in self: + rec.origin_po = False + origin_str = rec.origin or rec.operations.origin + if origin_str: + so = self.env['purchase.order'].search([('name', '=', origin_str)], limit=1) + rec.origin_po = so.id if so else False @api.depends('origin') def _compute_is_has_bill(self): @@ -133,6 +143,7 @@ class TukarGulingPO(models.Model): # Hanya update origin, jangan ubah lines if self.operations.origin: self.origin = self.operations.origin + self.origin_po = self.operations.group_id.id return if from_return_picking: -- cgit v1.2.3