Exclude the move which defer the invoice line amount
The move to defer amount must be created before creating the period move in case we need to compute the remainder amount on the first run. Closes #13547 (grafted from e4758cb22bff649346d546ff0645c165b4b3c2b8) --HG-- branch : 6.0
This commit is contained in:
1 parent
dc70c2cd28
commit
dbd1749154
1 file changed
+7
-6
@@ -205,10 +205,8 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
|
||||
Period.find(deferral.company.id, deferral.start_date)
|
||||
# Set state before create moves and defer amount to pass assert
|
||||
cls.write(deferrals, {'state': 'running'})
|
||||
cls.create_moves(deferrals)
|
||||
# defer_amount is called after create_moves to be sure that
|
||||
# create_moves call get_move with the invoice period if needed.
|
||||
cls.defer_amount(deferrals)
|
||||
deferred_moves = cls.defer_amount(deferrals)
|
||||
cls.create_moves(deferrals, _exclude=deferred_moves)
|
||||
cls.close_try(deferrals)
|
||||
|
||||
@classmethod
|
||||
@@ -249,12 +247,14 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
|
||||
moves.append(deferral.get_move())
|
||||
Move.save(moves)
|
||||
Move.post(moves)
|
||||
return moves
|
||||
|
||||
@classmethod
|
||||
def create_moves(cls, deferrals):
|
||||
def create_moves(cls, deferrals, _exclude=None):
|
||||
pool = Pool()
|
||||
Period = pool.get('account.period')
|
||||
Move = pool.get('account.move')
|
||||
exclude = set(_exclude or [])
|
||||
moves = []
|
||||
for deferral in deferrals:
|
||||
assert deferral.state == 'running'
|
||||
@@ -265,7 +265,8 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
|
||||
('end_date', '>=', deferral.start_date),
|
||||
])
|
||||
for period in sorted(
|
||||
set(periods) - {m.period for m in deferral.moves},
|
||||
set(periods) - {
|
||||
m.period for m in deferral.moves if m not in exclude},
|
||||
key=lambda p: p.start_date):
|
||||
moves.append(deferral.get_move(period))
|
||||
Move.save(moves)
|
||||
|
||||
Reference in new issue
Block a user