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/tukar_guling.py') 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 b3cd6aeb021259b4004a58270a2a7b6b0d82ba1d Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sun, 10 Aug 2025 19:42:25 +0700 Subject: show invoice rev --- indoteknik_custom/models/tukar_guling.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling.py') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 6aedb70e..624de7a9 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -92,19 +92,35 @@ class TukarGuling(models.Model): so = self.env['sale.order'].search([('name', '=', origin_str)], limit=1) rec.origin_so = so.id if so else False - @api.depends('origin') + @api.depends('origin_so', 'mapping_koli_ids.product_id', 'line_ids.product_id') 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']) - ]) + rec.is_has_invoice = False + rec.invoice_id = False + + if not rec.origin_so: + continue + + # Ambil produk dari mapping_koli kalau ada, kalau kosong pakai line_ids + if rec.mapping_koli_ids: + retur_products = rec.mapping_koli_ids.mapped('product_id') + else: + retur_products = rec.line_ids.mapped('product_id') + + # Semua invoice dari SO asal + invoices = rec.origin_so.invoice_ids.filtered( + lambda inv: inv.state not in ('draft', 'cancel') + and inv.move_type in ('out_invoice', 'out_refund') + ) + + # Filter invoice yang punya produk yang diretur + invoices = invoices.filtered( + lambda inv: any(line.product_id in retur_products for line in inv.invoice_line_ids) + ) + 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: -- cgit v1.2.3 From 356e53b85511c98cf4c942c32f2f370f58c9d849 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sun, 10 Aug 2025 20:16:09 +0700 Subject: pengajuan return so revert --- indoteknik_custom/models/tukar_guling.py | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling.py') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 624de7a9..6aedb70e 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -92,35 +92,19 @@ class TukarGuling(models.Model): so = self.env['sale.order'].search([('name', '=', origin_str)], limit=1) rec.origin_so = so.id if so else False - @api.depends('origin_so', 'mapping_koli_ids.product_id', 'line_ids.product_id') + @api.depends('origin') def _compute_is_has_invoice(self): for rec in self: - rec.is_has_invoice = False - rec.invoice_id = False - - if not rec.origin_so: - continue - - # Ambil produk dari mapping_koli kalau ada, kalau kosong pakai line_ids - if rec.mapping_koli_ids: - retur_products = rec.mapping_koli_ids.mapped('product_id') - else: - retur_products = rec.line_ids.mapped('product_id') - - # Semua invoice dari SO asal - invoices = rec.origin_so.invoice_ids.filtered( - lambda inv: inv.state not in ('draft', 'cancel') - and inv.move_type in ('out_invoice', 'out_refund') - ) - - # Filter invoice yang punya produk yang diretur - invoices = invoices.filtered( - lambda inv: any(line.product_id in retur_products for line in inv.invoice_line_ids) - ) - + 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: -- cgit v1.2.3 From d896d5cb51437d366c10e854616faee46736688c Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 12 Aug 2025 15:10:16 +0700 Subject: get bill based on product --- indoteknik_custom/models/tukar_guling.py | 37 ++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling.py') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 6aedb70e..ff641f34 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -92,19 +92,38 @@ class TukarGuling(models.Model): so = self.env['sale.order'].search([('name', '=', origin_str)], limit=1) rec.origin_so = so.id if so else False - @api.depends('origin') + @api.depends('origin', 'origin_so', 'partner_id', 'line_ids.product_id') def _compute_is_has_invoice(self): + Move = self.env['account.move'] 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']) - ]) + rec.is_has_invoice = False + rec.invoice_id = [(5, 0, 0)] + + product_ids = rec.line_ids.mapped('product_id').ids + if not product_ids: + continue + + domain = [ + ('move_type', 'in', ['out_invoice', 'in_invoice']), + ('state', 'not in', ['draft', 'cancel']), + ('invoice_line_ids.product_id', 'in', product_ids), + ] + + if rec.partner_id: + domain.append(('partner_id', '=', rec.partner_id.id)) + + extra = [] + if rec.origin: + extra.append(('invoice_origin', 'ilike', rec.origin)) + if rec.origin_so: + extra.append(('invoice_line_ids.sale_line_ids.order_id', '=', rec.origin_so.id)) + if extra: + domain = domain + ['|'] * (len(extra) - 1) + extra + + invoices = Move.search(domain).with_context(active_test=False) if invoices: + rec.invoice_id = [(6, 0, invoices.ids)] 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: -- cgit v1.2.3 From bbc1f241fb12e8a1115fdbc90ab5846bcfd47ee3 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 13 Aug 2025 08:34:12 +0700 Subject: Remove duplicate return --- indoteknik_custom/models/tukar_guling.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling.py') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index ff641f34..4b03d4b0 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -380,10 +380,6 @@ 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