# -*- coding: utf-8 -*- from odoo import models, api, fields, _ from odoo.exceptions import UserError class AccountPayment(models.Model): _inherit = 'account.payment' def _prepare_move_line_default_vals(self, write_off_line_vals=None, force_balance=None): """ Override to use the Branch RK account for the liquidity line when the payment is centralized. """ res = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance) journal_sudo = self.journal_id.sudo() if journal_sudo.is_centralized and self.company_id != journal_sudo.parent_company_id: # The first line is usually the liquidity line in outbound payments # or the counterpart line. Odoo 17+ uses _seek_for_lines to identify them. # But here we can just update the account if it matches the journal's default. for line_vals in res: if line_vals.get('account_id') == journal_sudo.default_account_id.id: line_vals['account_id'] = journal_sudo.branch_intercompany_account_id.id return res