[FIX] account: When modifying the currency or company of a bank journal, also set it on the related res.partner.bank (if set)

See issue https://github.com/odoo/odoo/issues/22980
This commit is contained in:
Olivier Colson
2018-02-28 11:39:05 +01:00
parent b6d4cd5deb
commit 239f4fec29
+5 -1
View File
@@ -100,7 +100,7 @@ class AccountAccount(models.Model):
help="Forces all moves for this account to have this account currency.")
code = fields.Char(size=64, required=True, index=True)
deprecated = fields.Boolean(index=True, default=False)
user_type_id = fields.Many2one('account.account.type', string='Type', required=True, oldname="user_type",
user_type_id = fields.Many2one('account.account.type', string='Type', required=True, oldname="user_type",
help="Account Type is used for information purpose, to generate country-specific legal reports, and set the rules to close a fiscal year and generate opening entries.")
internal_type = fields.Selection(related='user_type_id.type', store=True, readonly=True)
#has_unreconciled_entries = fields.Boolean(compute='_compute_has_unreconciled_entries',
@@ -323,6 +323,8 @@ class AccountJournal(models.Model):
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']
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.'))
@@ -336,6 +338,8 @@ class AccountJournal(models.Model):
self.default_debit_account_id.currency_id = vals['currency_id']
if not 'default_credit_account_id' in vals and self.default_credit_account_id:
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_acc_number' in vals and not vals.get('bank_acc_number') and journal.bank_account_id:
raise UserError(_('You cannot empty the account number once set.\nIf you would like to delete the account number, you can do it from the Bank Accounts list.'))
result = super(AccountJournal, self).write(vals)