[FIX] account: fix bank_account_id field in account.journal
* In account.journal model, the domain of bank_account_id field was incorrectly comparing the partner_id with a res.company object * When modifying the company of a bank journal, the company of the related res.partner.bank was changed without checking if it had a company and also its partner (account holder) was not changed. Was PR #23480. Courtesy of Miquel Raich (Eficent)
This commit is contained in:
@@ -378,7 +378,7 @@ class AccountJournal(models.Model):
|
||||
belongs_to_company = fields.Boolean('Belong to the user\'s current company', compute="_belong_to_company", search="_search_company_journals",)
|
||||
|
||||
# Bank journals fields
|
||||
bank_account_id = fields.Many2one('res.partner.bank', string="Bank Account", ondelete='restrict', copy=False, domain="[('partner_id','=', company_id)]")
|
||||
bank_account_id = fields.Many2one('res.partner.bank', string="Bank Account", ondelete='restrict', copy=False)
|
||||
bank_statements_source = fields.Selection([('undefined', 'Undefined Yet'),('manual', 'Record Manually')], string='Bank Feeds', default='undefined')
|
||||
bank_acc_number = fields.Char(related='bank_account_id.acc_number')
|
||||
bank_id = fields.Many2one('res.bank', related='bank_account_id.bank_id')
|
||||
@@ -488,11 +488,16 @@ class AccountJournal(models.Model):
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
for journal in self:
|
||||
company = journal.company_id
|
||||
if ('company_id' in vals and journal.company_id.id != vals['company_id']):
|
||||
if self.env['account.move'].search([('journal_id', 'in', self.ids)], limit=1):
|
||||
raise UserError(_('This journal already contains items, therefore you cannot modify its company.'))
|
||||
if self.bank_account_id:
|
||||
self.bank_account_id.company_id = vals['company_id']
|
||||
company = self.env['res.company'].browse(vals['company_id'])
|
||||
if self.bank_account_id.company_id and self.bank_account_id.company_id != company:
|
||||
self.bank_account_id.write({
|
||||
'company_id': company.id,
|
||||
'partner_id': company.partner_id.id,
|
||||
})
|
||||
if ('code' in vals and journal.code != vals['code']):
|
||||
if self.env['account.move'].search([('journal_id', 'in', self.ids)], limit=1):
|
||||
raise UserError(_('This journal already contains items, therefore you cannot modify its short name.'))
|
||||
@@ -508,8 +513,14 @@ class AccountJournal(models.Model):
|
||||
self.default_credit_account_id.currency_id = vals['currency_id']
|
||||
if self.bank_account_id:
|
||||
self.bank_account_id.currency_id = vals['currency_id']
|
||||
if 'bank_account_id' in vals and not vals.get('bank_account_id'):
|
||||
raise UserError(_('You cannot empty the bank account once set.'))
|
||||
if 'bank_account_id' in vals:
|
||||
if not vals.get('bank_account_id'):
|
||||
raise UserError(_('You cannot empty the bank account once set.'))
|
||||
else:
|
||||
bank_account = self.env['res.partner.bank'].browse(vals['bank_account_id'])
|
||||
if bank_account.partner_id != company.partner_id:
|
||||
raise UserError(_("The partners of the journal's company and the related bank account mismatch."))
|
||||
|
||||
result = super(AccountJournal, self).write(vals)
|
||||
|
||||
# Create the bank_account_id if necessary
|
||||
|
||||
Reference in New Issue
Block a user