diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-11-19 14:49:01 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-11-19 14:49:01 +0700 |
| commit | bb2be920076aabc49b4f9fdd896d14e096e633eb (patch) | |
| tree | 588196ba53fb7e41d96a61272bdb74b4821fe661 /indoteknik_custom/models/refund_sale_order.py | |
| parent | 9c4f131ffaf37ca47a78b320a68f7de4e846ecfb (diff) | |
| parent | 58623e9509789381dbe334969de647b4ad0302a4 (diff) | |
Merge branch 'odoo-backup' into locatorlocator
# Conflicts:
# indoteknik_custom/models/__init__.py
# indoteknik_custom/models/stock_move.py
# indoteknik_custom/security/ir.model.access.csv
# indoteknik_custom/views/stock_picking.xml
Diffstat (limited to 'indoteknik_custom/models/refund_sale_order.py')
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 115 |
1 files changed, 78 insertions, 37 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 47565dfc..cbc0b717 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -326,8 +326,24 @@ 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'), + ('ref', 'not ilike', 'reklas'), + ] + 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 +365,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 +591,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 +672,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 +688,27 @@ 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'), + ('ref', 'not ilike', 'reklas'), + ] + 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 +723,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 +752,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): @@ -753,10 +793,11 @@ class RefundSaleOrder(models.Model): line_vals = [] for so in self.sale_order_ids: for line in so.order_line: - if line.qty_delivered == 0: + barang_kurang = line.product_uom_qty - line.qty_delivered + if line.qty_delivered == 0 or barang_kurang > 0: line_vals.append((0, 0, { 'product_id': line.product_id.id, - 'quantity': line.product_uom_qty, + 'quantity': barang_kurang, 'from_name': so.name, 'prod_id': so.id, 'reason': '', @@ -988,7 +1029,7 @@ class RefundSaleOrder(models.Model): for rec in self: if self.env.uid not in allowed_user_ids and not is_fat: raise UserError("❌ Hanya user yang bersangkutan atau Finance (FAT) yang bisa melakukan penolakan.") - if rec.status not in ['refund', 'reject']: + if rec.status != 'reject': rec.status = 'reject' rec.status_payment = 'reject' |
