# -*- coding: utf-8 -*- from odoo import models, fields, api, _ class AccountPayment(models.Model): _inherit = "account.payment" # Add expense account field to payment lines 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_id', 'partner_type', 'payment_type', '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 _prepare_move_line_default_vals(self, write_off_line_vals=None, force_balance=None): ''' Override to use expense account if defined ''' line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance) # If we have an expense account, replace the destination account if self.expense_account_id and len(line_vals_list) >= 2: # The second line is typically the counterpart line (payable/receivable) line_vals_list[1]['account_id'] = self.expense_account_id.id return line_vals_list