diff --git a/__manifest__.py b/__manifest__.py index 4c75178..b0fec18 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -19,6 +19,7 @@ account payable. 'data/account_payment_method_data.xml', 'views/account_batch_payment_views.xml', 'views/account_payment_views.xml', + 'views/account_payment_register_views.xml', ], 'installable': True, 'application': False, diff --git a/models/__init__.py b/models/__init__.py index 3ad91c3..18ebd68 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import account_batch_payment -from . import account_payment \ No newline at end of file +from . import account_payment +from . import account_payment_register \ No newline at end of file diff --git a/models/account_payment_register.py b/models/account_payment_register.py new file mode 100644 index 0000000..bf4694b --- /dev/null +++ b/models/account_payment_register.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields, api, _ + + +class AccountPaymentRegister(models.TransientModel): + _inherit = "account.payment.register" + + # Add expense account field to payment register wizard + expense_account_id = fields.Many2one( + 'account.account', + string='Expense Account', + domain="[('account_type', 'not in', ('asset_receivable', 'liability_payable'))]", + help="Account used for expense instead of the default payable/receivable account" + ) + + @api.depends('journal_id', 'partner_type', 'is_internal_transfer', 'destination_journal_id', 'expense_account_id') + def _compute_destination_account_id(self): + ''' Override to use expense account if defined ''' + super()._compute_destination_account_id() + for pay in self: + # If we have an expense account, use it instead of the default payable/receivable account + if pay.expense_account_id and ((pay.payment_type == 'outbound' and pay.partner_type == 'supplier') or + (pay.payment_type == 'inbound' and pay.partner_type == 'customer')): + pay.destination_account_id = pay.expense_account_id + + def _create_payment_vals_from_wizard(self, batch_result): + ''' Override to use expense account if defined ''' + payment_vals = super()._create_payment_vals_from_wizard(batch_result) + + # If we have an expense account, replace the destination account + if self.expense_account_id and len(payment_vals.get('line_ids', [])) >= 2: + # The second line is typically the counterpart line (payable/receivable) + payment_vals['line_ids'][1]['account_id'] = self.expense_account_id.id + + return payment_vals + + def _create_payment_vals_from_batch(self, batch_result): + ''' Override to use expense account if defined ''' + payment_vals = super()._create_payment_vals_from_batch(batch_result) + + # If we have an expense account, replace the destination account + if self.expense_account_id: + payment_vals['destination_account_id'] = self.expense_account_id.id + + return payment_vals \ No newline at end of file diff --git a/views/__init__.py b/views/__init__.py index 7c68785..428156a 100644 --- a/views/__init__.py +++ b/views/__init__.py @@ -1 +1,4 @@ -# -*- coding: utf-8 -*- \ No newline at end of file +# -*- coding: utf-8 -*- +from . import account_batch_payment_views +from . import account_payment_views +from . import account_payment_register_views \ No newline at end of file diff --git a/views/account_payment_register_views.xml b/views/account_payment_register_views.xml new file mode 100644 index 0000000..168d8da --- /dev/null +++ b/views/account_payment_register_views.xml @@ -0,0 +1,15 @@ + + + + account.payment.register.form.inherit + account.payment.register + + + + + + + + \ No newline at end of file