Skip to content

Commit

Permalink
[12.0] [REF] Account payment return invoice returned vals
Browse files Browse the repository at this point in the history
  • Loading branch information
qgroulard committed Feb 6, 2020
1 parent b84c214 commit df567a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions account_payment_return/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def check_payment_return(self):
(self - returned_invoices).filtered('returned_payment').write(
{'returned_payment': False})

@api.multi
def _payment_returned(self, return_line):
vals = return_line._prepare_invoice_returned_vals()
if vals:
self.write(vals)

@api.one
@api.depends('payment_move_line_ids.amount_residual')
def _get_payment_info_JSON(self):
Expand Down
10 changes: 6 additions & 4 deletions account_payment_return/models/payment_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def action_confirm(self):
raise UserError(
_("You must input all moves references in the payment "
"return."))
invoices = self.env['account.invoice']
move_line_model = self.env['account.move.line']
move = self.env['account.move'].create(
self._prepare_return_move_vals())
Expand All @@ -228,8 +227,10 @@ def action_confirm(self):
# returned_moves: debit on customer account (from invoice move)
returned_moves = move_line.matched_debit_ids.mapped(
'debit_move_id')
returned_moves.mapped('invoice_id')._payment_returned(
return_line
)
all_move_lines |= move_line
invoices |= returned_moves.mapped('invoice_id')
move_line.remove_move_reconcile()
(move_line | move_line2).reconcile()
return_line.move_line_ids.mapped('matched_debit_ids').write(
Expand All @@ -247,8 +248,6 @@ def action_confirm(self):
# Reconcile (if option enabled)
self._auto_reconcile(
credit_move_line, all_move_lines, total_amount)
# Write directly because we returned payments just now
invoices.write(self._prepare_invoice_returned_vals())
move.post()
self.write({'state': 'done', 'move_id': move.id})
return True
Expand Down Expand Up @@ -419,6 +418,9 @@ def _find_match(self):
self._get_partner_from_move()
self.filtered(lambda x: not x.amount)._compute_amount()

def _prepare_invoice_returned_vals(self):
return self.return_id._prepare_invoice_returned_vals()

@api.multi
def _prepare_return_move_line_vals(self, move):
self.ensure_one()
Expand Down

0 comments on commit df567a2

Please sign in to comment.