From bb49da69c2af4d32c6bbc99cbc74e86e1f695424 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 12 Sep 2025 15:00:12 +0700 Subject: schema sisa uang muka --- fixco_custom/models/account_move.py | 29 ++++++++++++++++++++++++++- fixco_custom/models/invoice_reklas.py | 33 +++++++++++++++++++++++++------ fixco_custom/models/purchase_order.py | 12 ++++++----- fixco_custom/models/sale.py | 31 +++++++++++++++++++++++++++++ fixco_custom/models/stock_picking.py | 9 +++++++++ fixco_custom/models/uangmuka_penjualan.py | 1 + fixco_custom/views/account_move.xml | 24 ++++++++++++++++++++-- fixco_custom/views/sale_order.xml | 16 +++++++++++++++ 8 files changed, 141 insertions(+), 14 deletions(-) (limited to 'fixco_custom') diff --git a/fixco_custom/models/account_move.py b/fixco_custom/models/account_move.py index d095eeb..836b878 100644 --- a/fixco_custom/models/account_move.py +++ b/fixco_custom/models/account_move.py @@ -37,6 +37,34 @@ class AccountMove(models.Model): purchase_order_id = fields.Many2one('purchase.order', string='Purchase Order') bill_id = fields.Many2one('account.move', string='Vendor Bill', domain=[('move_type', '=', 'in_invoice')], help='Bill asal dari proses reklas ini') count_reverse = fields.Integer('Count Reverse', compute='_compute_count_reverse') + uangmuka = fields.Boolean('Uang Muka?') + reklas = fields.Boolean('Reklas?') + reklas_used = fields.Boolean('Reklas Used?', compute='_compute_reklas_used') + reklas_used_by = fields.Many2one('account.move', string='Reklas Used By', compute='_compute_reklas_used') + + @api.depends('line_ids.reconciled', 'line_ids.matching_number') + def _compute_reklas_used(self): + for move in self: + move.reklas_used = False + move.reklas_used_by = None + + if move.move_type != 'entry': + continue + + matching_numbers = move.line_ids.filtered(lambda l: l.reconciled and l.matching_number).mapped('matching_number') + + if not matching_numbers: + continue + + invoice_lines = self.env['account.move.line'].search([ + ('reconciled', '=', True), + ('matching_number', 'in', matching_numbers), + ('move_id.move_type', '=', 'out_invoice'), + ], limit=1) + + if invoice_lines: + move.reklas_used = True + move.reklas_used_by = invoice_lines.move_id def _compute_count_reverse(self): for move in self: @@ -46,7 +74,6 @@ class AccountMove(models.Model): lambda p: move.id in p.reversed_entry_id.ids ) - move.count_reverse = len(reverse) def action_view_related_reverse(self): diff --git a/fixco_custom/models/invoice_reklas.py b/fixco_custom/models/invoice_reklas.py index d97d868..584d357 100644 --- a/fixco_custom/models/invoice_reklas.py +++ b/fixco_custom/models/invoice_reklas.py @@ -73,16 +73,35 @@ class InvoiceReklas(models.TransientModel): # invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) # self.pay_amt = invoices.amount_total + def compare_amount_uangmuka_reklas(self): + if self.reklas_type == 'penjualan': + invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) + if invoices.uangmuka == True: + uangmuka = invoices.amount_total + reklas = self.env['account.move'].search([ + ('sale_id', '=', invoices.sale_id.id), + ('move_type', '=', 'entry'), + ('reklas', '=', True), + ('state', '=', 'posted') + ]) + + reklas_uangmuka = sum(reklas.mapped('amount_total_signed')) or 0 + total_reklas = reklas_uangmuka + self.pay_amt + if total_reklas > uangmuka: + raise UserError('Total reklas tidak boleh melebihi total uang muka') + def create_reklas(self): if not self.reklas_type: raise UserError('Reklas Tipe harus diisi') if not self.reklas_id: raise UserError('Nomor CAB harus diisi') + + self.compare_amount_uangmuka_reklas() invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) current_time = datetime.now() - for invoice in invoices: + for invoice in invoices: # Ambil nama PO jika ada po_name = invoice.purchase_id.name if invoice.purchase_id else '' @@ -99,7 +118,9 @@ class InvoiceReklas(models.TransientModel): parameters_header = { 'ref': ref_name, 'date': current_time, - 'journal_id': 19 + 'journal_id': 19, + 'sale_id': invoice.sale_id.id, + 'reklas': True, } if invoice.purchase_id: @@ -123,7 +144,7 @@ class InvoiceReklas(models.TransientModel): parameter_debit = { 'move_id': account_move.id, 'account_id': 578, # penerimaan belum alokasi - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': self.pay_amt, 'credit': 0, @@ -132,7 +153,7 @@ class InvoiceReklas(models.TransientModel): parameter_credit = { 'move_id': account_move.id, 'account_id': 347, - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt, @@ -142,7 +163,7 @@ class InvoiceReklas(models.TransientModel): parameter_debit = { 'move_id': account_move.id, 'account_id': 388, - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': self.pay_amt, 'credit': 0, @@ -151,7 +172,7 @@ class InvoiceReklas(models.TransientModel): parameter_credit = { 'move_id': account_move.id, 'account_id': 579, - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt, diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py index 0869cc8..8c84215 100644 --- a/fixco_custom/models/purchase_order.py +++ b/fixco_custom/models/purchase_order.py @@ -21,10 +21,11 @@ class PurchaseOrder(models.Model): 'automatic.purchase', string='Automatic Purchase Reference', ondelete='set null', - index=True + index=True, + copy=False ) - sale_order_id = fields.Many2one('sale.order', string='Sales Order') - move_entry_id = fields.Many2one('account.move', string='Journal Entries') + sale_order_id = fields.Many2one('sale.order', string='Sales Order', copy=False) + move_entry_id = fields.Many2one('account.move', string='Journal Entries', copy=False) amount_discount = fields.Monetary( string='Total Discount', compute='_compute_amount_discount', @@ -34,7 +35,8 @@ class PurchaseOrder(models.Model): biaya_lain_lain = fields.Float( 'Biaya Lain Lain', default=0.0, - tracking=True + tracking=True, + copy=False ) source = fields.Selection([ @@ -42,7 +44,7 @@ class PurchaseOrder(models.Model): ('reordering', 'Reordering'), ('purchasing_job', 'Purchasing Job'), ('manual', 'Manual') - ], string='Source', default='manual') + ], string='Source', default='manual', copy=False) count_journals = fields.Integer('Count Payment', compute='_compute_count_journals') def _compute_count_journals(self): diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py index 9943376..c6e9ccb 100755 --- a/fixco_custom/models/sale.py +++ b/fixco_custom/models/sale.py @@ -15,6 +15,37 @@ class SaleOrder(models.Model): count_journals = fields.Integer('Count Payment', compute='_compute_count_journals') + remaining_down_payment = fields.Float('Remaining Down Payment', compute='_compute_remaining_down_payment') + + def _compute_remaining_down_payment(self): + for order in self: + down_payments = self.env['account.move'].search([ + ('sale_id', '=', order.id), + ('move_type', '=', 'entry'), + ('state', '=', 'posted'), + ('uangmuka', '=', True) + ]) + + reklas = self.env['account.move'].search([ + ('sale_id', '=', order.id), + ('move_type', '=', 'entry'), + ('state', '=', 'posted'), + ('reklas', '=', True) + ]) + + def check_reklas_used(reklas): + for line in reklas.line_ids: + if line.reconciled and line.matching_number: + return True + return False + + reklas = reklas.filtered(check_reklas_used) + + nominal_down_payment = sum(down_payments.mapped('amount_total_signed')) if down_payments else 0 + nominal_reklas = sum(reklas.mapped('amount_total_signed')) if reklas else 0 + + order.remaining_down_payment = nominal_down_payment - nominal_reklas + def _compute_count_journals(self): for order in self: journals = self.env['account.move'].search([ diff --git a/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py index 408e055..73f4175 100755 --- a/fixco_custom/models/stock_picking.py +++ b/fixco_custom/models/stock_picking.py @@ -45,6 +45,15 @@ class StockPicking(models.Model): ) is_printed = fields.Boolean(string="Sudah Dicetak", default=False) + def action_cancel(self): + for picking in self: + if not self.env.user.id == 13: + if picking.purchase_id.move_entry_id: + raise UserError( + 'Hanya Accounting yang bisa melakukan cancel karena di po nya sudah ada uang muka' + ) + super(StockPicking, self).action_cancel() + def action_create_invoice_from_mr(self): """Create the invoice associated to the PO. """ diff --git a/fixco_custom/models/uangmuka_penjualan.py b/fixco_custom/models/uangmuka_penjualan.py index f099b16..a08b030 100644 --- a/fixco_custom/models/uangmuka_penjualan.py +++ b/fixco_custom/models/uangmuka_penjualan.py @@ -64,6 +64,7 @@ class UangmukaPenjualan(models.TransientModel): 'date': current_time, 'journal_id': 24, 'sale_id': order.id, + 'uangmuka': True, } account_move = request.env['account.move'].create([param_header]) diff --git a/fixco_custom/views/account_move.xml b/fixco_custom/views/account_move.xml index 0e0b381..88d3b46 100644 --- a/fixco_custom/views/account_move.xml +++ b/fixco_custom/views/account_move.xml @@ -9,7 +9,7 @@