[FIX] account: import balances with unaffected earnings
If we try to load a csv file with opening values for the anuaffected earnings account, there will be errors because when trying to balance the move, we filter the lines on that account and we don't expect there to be multiple lines in it. closes odoo/odoo#51401 X-original-commit: ad4277219fe078712916e91c1be566a9b412fe1f Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com> Signed-off-by: wan <william-andre@users.noreply.github.com>
This commit is contained in:
@@ -140,7 +140,7 @@ class AccountAccount(models.Model):
|
||||
AND journal.type IN ('bank', 'cash')
|
||||
AND journal.currency_id IS NOT NULL
|
||||
AND journal.currency_id != company.currency_id
|
||||
AND account.currency_id != journal.currency_id
|
||||
AND account.currency_id != journal.currency_id
|
||||
''', [tuple(self.ids)])
|
||||
res = self._cr.fetchone()
|
||||
if res:
|
||||
@@ -244,11 +244,9 @@ class AccountAccount(models.Model):
|
||||
either 'debit' or 'credit', depending on which one of these two fields
|
||||
got assigned.
|
||||
"""
|
||||
self.company_id.create_op_move_if_non_existant()
|
||||
opening_move = self.company_id.account_opening_move_id
|
||||
|
||||
if not opening_move:
|
||||
raise UserError(_("You must first define an opening move."))
|
||||
|
||||
if opening_move.state == 'draft':
|
||||
# check whether we should create a new move line or modify an existing one
|
||||
account_op_lines = self.env['account.move.line'].search([('account_id', '=', self.id),
|
||||
|
||||
@@ -405,10 +405,16 @@ class ResCompany(models.Model):
|
||||
current year earnings account.
|
||||
"""
|
||||
if self.account_opening_move_id and self.account_opening_move_id.state == 'draft':
|
||||
debit_diff, credit_diff = self.get_opening_move_differences(self.account_opening_move_id.line_ids)
|
||||
|
||||
balancing_account = self.get_unaffected_earnings_account()
|
||||
currency = self.currency_id
|
||||
balancing_move_line = self.account_opening_move_id.line_ids.filtered(lambda x: x.account_id == self.get_unaffected_earnings_account())
|
||||
|
||||
balancing_move_line = self.account_opening_move_id.line_ids.filtered(lambda x: x.account_id == balancing_account)
|
||||
# There could be multiple lines if we imported the balance from unaffected earnings account too
|
||||
if len(balancing_move_line) > 1:
|
||||
self.with_context(check_move_validity=False).account_opening_move_id.line_ids -= balancing_move_line[1:]
|
||||
balancing_move_line = balancing_move_line[0]
|
||||
|
||||
debit_diff, credit_diff = self.get_opening_move_differences(self.account_opening_move_id.line_ids)
|
||||
|
||||
if float_is_zero(debit_diff + credit_diff, precision_rounding=currency.rounding):
|
||||
if balancing_move_line:
|
||||
@@ -420,7 +426,6 @@ class ResCompany(models.Model):
|
||||
balancing_move_line.write({'debit': credit_diff, 'credit': debit_diff})
|
||||
else:
|
||||
# Non-zero difference and no existing line : create a new line
|
||||
balancing_account = self.get_unaffected_earnings_account()
|
||||
self.env['account.move.line'].create({
|
||||
'name': _('Automatic Balancing Line'),
|
||||
'move_id': self.account_opening_move_id.id,
|
||||
|
||||
Reference in New Issue
Block a user