diff options
| author | FIN-IT_AndriFP <it@fixcomart.co.id> | 2025-11-17 12:02:52 +0700 |
|---|---|---|
| committer | FIN-IT_AndriFP <it@fixcomart.co.id> | 2025-11-17 12:02:52 +0700 |
| commit | 41c678e8483109bfd89f98f6e0be7d6325f7546f (patch) | |
| tree | 40ac2a5b2739a4eca20b074d9919630ae3576a65 | |
| parent | 6f254e896a0a788ac7f3a8c1668be5f31f70b640 (diff) | |
| parent | ff1e1392679e784aa0ed4380d87672f2f01a68bb (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into odoo-backup
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 106 |
1 files changed, 72 insertions, 34 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 9eae5b32..c6db2174 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -326,8 +326,23 @@ class RefundSaleOrder(models.Model): domain.append(('ref', 'ilike', n)) moves2 = self.env['account.move'].search(domain) + moves3 = self.env['account.move'] + if so_ids: + so_names = self.env['sale.order'].browse(so_ids).mapped('name') + domain = [ + ('journal_id', '=', 11), + ('state', '=', 'posted'), + ('ref', 'ilike', 'uang muka penjualan') + ] + if so_names: + domain += ['|'] * (len(so_names) - 1) + for n in so_names: + domain.append(('ref', 'ilike', n)) + moves3 = self.env['account.move'].search(domain) + has_moves = bool(moves) has_moves2 = bool(moves2) + has_moves3 = bool(moves3) has_piutangmdr = bool(piutangmdr) has_piutangbca = bool(piutangbca) has_misc = bool(misc) @@ -349,6 +364,8 @@ class RefundSaleOrder(models.Model): # sisanya bisa dijumlahkan tanpa konflik if has_moves2: amounts.append(sum(moves2.mapped('amount_total_signed'))) + if has_moves3: + amounts.append(sum(moves3.mapped('amount_total_signed'))) if has_piutangbca: amounts.append(sum(piutangbca.mapped('amount_total_signed'))) if has_piutangmdr: @@ -573,9 +590,10 @@ class RefundSaleOrder(models.Model): domain = [ ('journal_id', '=', 11), ('state', '=', 'posted'), - '|', + '|', '|', ('ref', 'ilike', 'dp'), ('ref', 'ilike', 'payment'), + ('ref', 'ilike', 'uang muka penjualan'), ] domain += ['|'] * (len(so_names) - 1) for n in so_names: @@ -653,6 +671,7 @@ class RefundSaleOrder(models.Model): ('journal_id', '=', 13), ('state', '=', 'posted'), ]) + moves2 = self.env['account.move'] if so_ids: so_records = self.env['sale.order'].browse(so_ids) @@ -668,9 +687,26 @@ class RefundSaleOrder(models.Model): domain.append(('ref', 'ilike', n)) moves2 = self.env['account.move'].search(domain) + + moves3 = self.env['account.move'] + if so_ids: + so_records = self.env['sale.order'].browse(so_ids) + so_names = so_records.mapped('name') + + domain = [ + ('journal_id', '=', 11), + ('state', '=', 'posted'), + ('ref', 'ilike', 'uang muka penjualan') + ] + domain += ['|'] * (len(so_names) - 1) + for n in so_names: + domain.append(('ref', 'ilike', n)) + + moves3 = self.env['account.move'].search(domain) has_moves = bool(moves) has_moves2 = bool(moves2) + has_moves3 = bool(moves3) has_piutangmdr = bool(piutangmdr) has_piutangbca = bool(piutangbca) has_misc = bool(misc) @@ -685,6 +721,8 @@ class RefundSaleOrder(models.Model): amounts.append(sum(moves.mapped('amount_total_signed'))) if has_moves2: amounts.append(sum(moves2.mapped('amount_total_signed'))) + if has_moves3: + amounts.append(sum(moves3.mapped('amount_total_signed'))) if has_piutangbca: amounts.append(sum(piutangbca.mapped('amount_total_signed'))) if has_piutangmdr: @@ -712,39 +750,39 @@ class RefundSaleOrder(models.Model): if self.sale_order_ids: self.partner_id = self.sale_order_ids[0].partner_id - @api.constrains('sale_order_ids') - def _check_sale_orders_payment(self): - """ Validasi SO harus punya uang masuk (Journal Uang Muka / Midtrans) """ - for rec in self: - invalid_orders = [] - - for so in rec.sale_order_ids: - # cari journal uang muka - moves = self.env['account.move'].search([ - ('sale_id', '=', so.id), - ('journal_id', '=', 11), # Journal Uang Muka - ('state', '=', 'posted'), - ]) - piutangbca = self.env['account.move'].search([ - ('ref', 'in', rec.invoice_ids.mapped('name')), - ('journal_id', '=', 4), - ('state', '=', 'posted'), - ]) - piutangmdr = self.env['account.move'].search([ - ('ref', 'in', rec.invoice_ids.mapped('name')), - ('journal_id', '=', 7), - ('state', '=', 'posted'), - ]) - - if not moves and so.payment_status != 'settlement' and not piutangbca and not piutangmdr: - invalid_orders.append(so.name) - - if invalid_orders: - raise ValidationError( - f"Tidak dapat membuat refund untuk SO {', '.join(invalid_orders)} " - "karena tidak memiliki Record Uang Masuk (Journal Uang Muka/Payment Invoice/Midtrans).\n" - "Pastikan semua SO yang dipilih sudah memiliki Record pembayaran yang valid." - ) + # @api.constrains('sale_order_ids') + # def _check_sale_orders_payment(self): + # """ Validasi SO harus punya uang masuk (Journal Uang Muka / Midtrans) """ + # for rec in self: + # invalid_orders = [] + + # for so in rec.sale_order_ids: + # # cari journal uang muka + # moves = self.env['account.move'].search([ + # ('sale_id', '=', so.id), + # ('journal_id', '=', 11), # Journal Uang Muka + # ('state', '=', 'posted'), + # ]) + # piutangbca = self.env['account.move'].search([ + # ('ref', 'in', rec.invoice_ids.mapped('name')), + # ('journal_id', '=', 4), + # ('state', '=', 'posted'), + # ]) + # piutangmdr = self.env['account.move'].search([ + # ('ref', 'in', rec.invoice_ids.mapped('name')), + # ('journal_id', '=', 7), + # ('state', '=', 'posted'), + # ]) + + # if not moves and so.payment_status != 'settlement' and not piutangbca and not piutangmdr: + # invalid_orders.append(so.name) + + # if invalid_orders: + # raise ValidationError( + # f"Tidak dapat membuat refund untuk SO {', '.join(invalid_orders)} " + # "karena tidak memiliki Record Uang Masuk (Journal Uang Muka/Payment Invoice/Midtrans).\n" + # "Pastikan semua SO yang dipilih sudah memiliki Record pembayaran yang valid." + # ) @api.onchange('refund_type') def _onchange_refund_type(self): |
