Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0] [REF] Account payment return: invoice returned vals #310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 additions & 1 deletion account_payment_return/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2016 Carlos Dauden <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


class AccountPartialReconcile(models.Model):
Expand All @@ -24,3 +24,7 @@ class AccountMoveLine(models.Model):
column1='move_line_id',
column2='partial_reconcile_id',
)

@api.multi
def _payment_returned(self, return_line):
self.mapped('invoice_id')._payment_returned(return_line)
8 changes: 4 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,8 @@ 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._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 +246,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 +416,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