mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Merge pull request #266 from acsone/8.0-reversal-fix265
[FIX] account_reversal: allow reversing move in closed periods, fixes #265
This commit is contained in:
@@ -39,6 +39,14 @@ class account_move(models.Model):
|
||||
ondelete='set null',
|
||||
readonly=True)
|
||||
|
||||
@api.multi
|
||||
def validate(self):
|
||||
# TODO: remove this method if and when
|
||||
# https://github.com/odoo/odoo/pull/7735 is merged
|
||||
if self.env.context.get('novalidate'):
|
||||
return
|
||||
return super(account_move, self).validate()
|
||||
|
||||
@api.multi
|
||||
def _move_reversal(self, reversal_date,
|
||||
reversal_period_id=False, reversal_journal_id=False,
|
||||
@@ -85,7 +93,7 @@ class account_move(models.Model):
|
||||
'to_be_reversed': False,
|
||||
})
|
||||
|
||||
self.write({
|
||||
self.with_context(novalidate=True).write({
|
||||
'reversal_id': reversal_move.id,
|
||||
'to_be_reversed': False,
|
||||
})
|
||||
|
||||
@@ -34,12 +34,10 @@ class test_account_reversal(common.TransactionCase):
|
||||
self.move_obj = self.env['account.move']
|
||||
self.move_line_obj = self.env['account.move.line']
|
||||
|
||||
def _create_move(self, with_partner, amount=100):
|
||||
def _create_move(self, with_partner, amount=100, period=None):
|
||||
date = datetime.now()
|
||||
company_id = self.env.ref('base.main_company').id
|
||||
period_id = self.env['account.period'].with_context(
|
||||
account_period_prefer_normal=True,
|
||||
company_id=self.env.ref('base.main_company').id).find(date)[0]
|
||||
period = period or self.env.ref('account.period_0')
|
||||
|
||||
journal = self.env['account.journal'].create({
|
||||
'name': 'Test journal',
|
||||
@@ -50,7 +48,7 @@ class test_account_reversal(common.TransactionCase):
|
||||
|
||||
move_vals = {
|
||||
'journal_id': journal.id,
|
||||
'period_id': period_id.id,
|
||||
'period_id': period.id,
|
||||
'date': date,
|
||||
'company_id': company_id,
|
||||
}
|
||||
@@ -82,6 +80,15 @@ class test_account_reversal(common.TransactionCase):
|
||||
)
|
||||
return move_line_id.move_id
|
||||
|
||||
def _close_period(self, period_id):
|
||||
self.env.cr.execute('update account_journal_period '
|
||||
'set state=%s where period_id=%s',
|
||||
('done', period_id))
|
||||
self.env.cr.execute('update account_period '
|
||||
'set state=%s where id=%s',
|
||||
('done', period_id))
|
||||
self.env.invalidate_all()
|
||||
|
||||
def test_reverse(self):
|
||||
move = self._create_move(with_partner=False)
|
||||
company_id = self.env.ref('base.main_company').id
|
||||
@@ -103,3 +110,11 @@ class test_account_reversal(common.TransactionCase):
|
||||
x.account_id == account1 and 'aaaa' or 'bbbb')
|
||||
for x in reversed_moves.line_id])
|
||||
self.assertEqual(movestr_reversed, '0.00100.00bbbb100.000.00aaaa')
|
||||
|
||||
def test_reverse_closed_period(self):
|
||||
move_period = self.env.ref('account.period_0')
|
||||
move = self._create_move(with_partner=False, period=move_period)
|
||||
self._close_period(move_period.id)
|
||||
reversal_period = self.env.ref('account.period_1')
|
||||
move.create_reversals(reversal_date=reversal_period.date_start,
|
||||
reversal_period_id=reversal_period)
|
||||
|
||||
Reference in New Issue
Block a user