[FIX] account: Prevent reset draft an exchange journal entry
An exchange journal entry must not be reset to draft manually. It's done by odoo itself automatically when breaking an existing reconciliation. closes odoo/odoo#112472 X-original-commit: ad9d53c8976ed78f3f6fdd65795c582d533de436 Related: odoo/enterprise#36999 Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
committed by
Brice bib Bartoletti
parent
1899db8fa5
commit
b79863a62e
@@ -3581,8 +3581,31 @@ class AccountMove(models.Model):
|
||||
move.to_check = False
|
||||
|
||||
def button_draft(self):
|
||||
exchange_move_ids = set()
|
||||
if self:
|
||||
self.env['account.full.reconcile'].flush_model(['exchange_move_id'])
|
||||
self.env['account.partial.reconcile'].flush_model(['exchange_move_id'])
|
||||
self._cr.execute(
|
||||
"""
|
||||
SELECT DISTINCT sub.exchange_move_id
|
||||
FROM (
|
||||
SELECT exchange_move_id
|
||||
FROM account_full_reconcile
|
||||
WHERE exchange_move_id IN %s
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT exchange_move_id
|
||||
FROM account_partial_reconcile
|
||||
WHERE exchange_move_id IN %s
|
||||
) AS sub
|
||||
""",
|
||||
[tuple(self.ids), tuple(self.ids)],
|
||||
)
|
||||
exchange_move_ids = set([row[0] for row in self._cr.fetchall()])
|
||||
|
||||
for move in self:
|
||||
if move in move.line_ids.mapped('full_reconcile_id.exchange_move_id'):
|
||||
if move.id in exchange_move_ids:
|
||||
raise UserError(_('You cannot reset to draft an exchange difference journal entry.'))
|
||||
if move.tax_cash_basis_rec_id or move.tax_cash_basis_origin_move_id:
|
||||
# If the reconciliation was undone, move.tax_cash_basis_rec_id will be empty;
|
||||
|
||||
@@ -857,3 +857,53 @@ class TestAccountMove(AccountTestInvoicingCommon):
|
||||
}),
|
||||
]
|
||||
})
|
||||
|
||||
def test_reset_draft_exchange_move(self):
|
||||
""" Ensure you can't reset to draft an exchange journal entry """
|
||||
moves = self.env['account.move'].create([
|
||||
{
|
||||
'date': '2016-01-01',
|
||||
'line_ids': [
|
||||
Command.create({
|
||||
'name': "line1",
|
||||
'account_id': self.company_data['default_account_receivable'].id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'balance': 400.0,
|
||||
'amount_currency': 1200.0,
|
||||
}),
|
||||
Command.create({
|
||||
'name': "line2",
|
||||
'account_id': self.company_data['default_account_expense'].id,
|
||||
'balance': -400.0,
|
||||
}),
|
||||
]
|
||||
},
|
||||
{
|
||||
'date': '2017-01-01',
|
||||
'line_ids': [
|
||||
Command.create({
|
||||
'name': "line1",
|
||||
'account_id': self.company_data['default_account_receivable'].id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'balance': -600.0,
|
||||
'amount_currency': -1200.0,
|
||||
}),
|
||||
Command.create({
|
||||
'name': "line2",
|
||||
'account_id': self.company_data['default_account_expense'].id,
|
||||
'balance': 600.0,
|
||||
}),
|
||||
]
|
||||
},
|
||||
])
|
||||
moves.action_post()
|
||||
|
||||
res = moves.line_ids\
|
||||
.filtered(lambda x: x.account_id == self.company_data['default_account_receivable'])\
|
||||
.reconcile()
|
||||
|
||||
self.assertTrue(res.get('partials'))
|
||||
exchange_diff = res['partials'].exchange_move_id
|
||||
self.assertTrue(exchange_diff)
|
||||
with self.assertRaises(UserError), self.cr.savepoint():
|
||||
exchange_diff.button_draft()
|
||||
|
||||
Reference in New Issue
Block a user