Skip to content

Commit f440e10

Browse files
author
sonhd91
committed
[16.0][MIG]account_payment_mode_auto_reconcile: Migrate to version 16.0
1 parent ef40ad7 commit f440e10

File tree

10 files changed

+222
-197
lines changed

10 files changed

+222
-197
lines changed

account_payment_mode_auto_reconcile/README.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Account Payment Mode Auto Reconcile
1414
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1515
:alt: License: AGPL-3
1616
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github
17-
:target: https://github.com/OCA/account-reconcile/tree/10.0/account_payment_mode_auto_reconcile
17+
:target: https://github.com/OCA/account-reconcile/tree/16.0/account_payment_mode_auto_reconcile
1818
:alt: OCA/account-reconcile
1919
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20-
:target: https://translation.odoo-community.org/projects/account-reconcile-10-0/account-reconcile-10-0-account_payment_mode_auto_reconcile
20+
:target: https://translation.odoo-community.org/projects/account-reconcile-16-0/account-reconcile-16-0-account_payment_mode_auto_reconcile
2121
:alt: Translate me on Weblate
22-
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/98/10.0
24-
:alt: Try me on Runbot
22+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
23+
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/account-reconcile&target_branch=16.0
24+
:alt: Try me on Runboat
2525

2626
|badge1| |badge2| |badge3| |badge4| |badge5|
2727

@@ -48,7 +48,7 @@ Bug Tracker
4848
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/issues>`_.
4949
In case of trouble, please check there if your issue has already been reported.
5050
If you spotted it first, help us smashing it by providing a detailed and welcomed
51-
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_payment_mode_auto_reconcile%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
51+
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_payment_mode_auto_reconcile%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
5252

5353
Do not contact contributors directly about support or help with technical issues.
5454

@@ -78,6 +78,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
7878
mission is to support the collaborative development of Odoo features and
7979
promote its widespread use.
8080

81-
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/10.0/account_payment_mode_auto_reconcile>`_ project on GitHub.
81+
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/16.0/account_payment_mode_auto_reconcile>`_ project on GitHub.
8282

8383
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

account_payment_mode_auto_reconcile/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Account Payment Mode Auto Reconcile",
55
"summary": "Reconcile outstanding credits according to payment mode",
6-
"version": "10.0.1.0.0",
6+
"version": "16.0.1.0.0",
77
"category": "Banking addons",
88
"website": "https://github.com/OCA/account-reconcile",
99
"author": "Camptocamp, Odoo Community Association (OCA)",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from . import account_invoice
1+
from . import account_move
22
from . import account_partial_reconcile
33
from . import account_payment_mode

account_payment_mode_auto_reconcile/models/account_invoice.py renamed to account_payment_mode_auto_reconcile/models/account_move.py

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# Copyright 2019 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3-
import json
43
from operator import itemgetter
54

65
from odoo import _, api, fields, models
76

87

9-
class AccountInvoice(models.Model):
8+
class AccountMove(models.Model):
109

11-
_inherit = "account.invoice"
10+
_inherit = "account.move"
1211

1312
# Allow changing payment mode in open state
1413
# TODO: Check if must be done in account_payment_partner instead
1514
payment_mode_id = fields.Many2one(
16-
states={"draft": [("readonly", False)], "open": [("readonly", False)]}
15+
states={"draft": [("readonly", False)], "posted": [("readonly", False)]}
1716
)
1817
payment_mode_warning = fields.Char(
1918
compute="_compute_payment_mode_warning",
@@ -22,11 +21,10 @@ class AccountInvoice(models.Model):
2221
compute="_compute_payment_mode_warning",
2322
)
2423

25-
@api.multi
26-
def invoice_validate(self):
27-
res = super(AccountInvoice, self).invoice_validate()
24+
def action_post(self):
25+
res = super(AccountMove, self).action_post()
2826
for invoice in self:
29-
if invoice.type != "out_invoice":
27+
if invoice.move_type != "out_invoice":
3028
continue
3129
if not invoice.payment_mode_id.auto_reconcile_outstanding_credits:
3230
continue
@@ -36,50 +34,60 @@ def invoice_validate(self):
3634
).auto_reconcile_credits(partial_allowed=partial)
3735
return res
3836

39-
@api.multi
4037
def write(self, vals):
41-
res = super(AccountInvoice, self).write(vals)
42-
if "payment_mode_id" in vals:
38+
res = super(AccountMove, self).write(vals)
39+
if "payment_mode_id" in vals or "state" in vals:
4340
for invoice in self:
4441
# Do not auto reconcile anything else than open customer inv
45-
if invoice.state != "open" or invoice.type != "out_invoice":
42+
if invoice.state != "posted" or invoice.move_type != "out_invoice":
4643
continue
47-
payment_mode = invoice.payment_mode_id
44+
invoice_lines = invoice.line_ids.filtered(
45+
lambda line: line.account_type == "asset_receivable"
46+
)
4847
# Auto reconcile if payment mode sets it
48+
payment_mode = invoice.payment_mode_id
4949
if payment_mode and payment_mode.auto_reconcile_outstanding_credits:
5050
partial = payment_mode.auto_reconcile_allow_partial
5151
invoice.with_context(
5252
_payment_mode_auto_reconcile=True
5353
).auto_reconcile_credits(partial_allowed=partial)
5454
# If the payment mode is not using auto reconcile we remove
5555
# the existing reconciliations
56-
elif invoice.payment_move_line_ids:
56+
elif any(
57+
[
58+
invoice_lines.mapped("matched_credit_ids"),
59+
invoice_lines.mapped("matched_debit_ids"),
60+
]
61+
):
5762
invoice.auto_unreconcile_credits()
5863
return res
5964

60-
@api.multi
6165
def auto_reconcile_credits(self, partial_allowed=True):
6266
for invoice in self:
63-
if not invoice.has_outstanding:
67+
invoice._compute_payments_widget_to_reconcile_info()
68+
69+
if not invoice.invoice_has_outstanding:
6470
continue
65-
credits_info = json.loads(invoice.outstanding_credits_debits_widget)
71+
credits_info = invoice.invoice_outstanding_credits_debits_widget
6672
# Get outstanding credits in chronological order
6773
# (using reverse because aml is sorted by date desc as default)
68-
credits_dict = credits_info.get("content")
74+
credits_dict = credits_info.get("content", False)
6975
if invoice.payment_mode_id.auto_reconcile_same_journal:
7076
credits_dict = invoice._filter_payment_same_journal(credits_dict)
7177
sorted_credits = self._sort_credits_dict(credits_dict)
7278
for credit in sorted_credits:
73-
if not partial_allowed and credit.get("amount") > invoice.residual:
79+
if (
80+
not partial_allowed
81+
and credit.get("amount") > invoice.amount_residual
82+
):
7483
continue
75-
invoice.assign_outstanding_credit(credit.get("id"))
84+
invoice.js_assign_outstanding_line(credit.get("id"))
7685

7786
@api.model
7887
def _sort_credits_dict(self, credits_dict):
7988
"""Sort credits dict according to their id (oldest recs first)"""
8089
return sorted(credits_dict, key=itemgetter("id"))
8190

82-
@api.multi
8391
def _filter_payment_same_journal(self, credits_dict):
8492
"""Keep only credits on the same journal than the invoice."""
8593
self.ensure_one()
@@ -89,34 +97,47 @@ def _filter_payment_same_journal(self, credits_dict):
8997
)
9098
return [credit for credit in credits_dict if credit["id"] in lines.ids]
9199

92-
@api.multi
93100
def auto_unreconcile_credits(self):
94101
for invoice in self:
95-
payments_info = json.loads(invoice.payments_widget or "{}")
102+
payments_info = invoice.invoice_payments_widget
96103
for payment in payments_info.get("content", []):
97-
aml = self.env["account.move.line"].browse(payment.get("payment_id"))
104+
payment_aml = (
105+
self.env["account.payment"]
106+
.browse(payment.get("account_payment_id"))
107+
.line_ids
108+
)
109+
110+
aml = payment_aml.filtered(lambda l: l.matched_debit_ids)
98111
for apr in aml.matched_debit_ids:
99112
if apr.amount != payment.get("amount"):
100113
continue
101114
if (
102115
apr.payment_mode_auto_reconcile
103-
and apr.debit_move_id.invoice_id == invoice
116+
and apr.debit_move_id.move_id == invoice
104117
):
105-
aml.with_context(invoice_id=invoice.id).remove_move_reconcile()
118+
aml.remove_move_reconcile()
106119

107120
@api.depends(
108-
"type", "payment_mode_id", "payment_move_line_ids", "state", "has_outstanding"
121+
"move_type", "payment_mode_id", "payment_id", "state", "invoice_has_outstanding"
109122
)
110123
def _compute_payment_mode_warning(self):
111124
# TODO Improve me but watch out
112125
for invoice in self:
113-
if invoice.type != "out_invoice" or invoice.state == "paid":
126+
existed_reconciliations = any(
127+
[
128+
invoice.line_ids.mapped("matched_credit_ids"),
129+
invoice.line_ids.mapped("matched_debit_ids"),
130+
]
131+
)
132+
if invoice.move_type != "out_invoice" or (
133+
invoice.state == "posted" and invoice.payment_state != "paid"
134+
):
114135
invoice.payment_mode_warning = ""
115136
invoice.display_payment_mode_warning = False
116137
continue
117138
invoice.display_payment_mode_warning = True
118139
if (
119-
invoice.state != "open"
140+
invoice.state != "posted"
120141
and invoice.payment_mode_id
121142
and invoice.payment_mode_id.auto_reconcile_outstanding_credits
122143
):
@@ -125,8 +146,9 @@ def _compute_payment_mode_warning(self):
125146
" any outstanding credits."
126147
)
127148
elif (
128-
invoice.state == "open"
129-
and invoice.payment_move_line_ids
149+
invoice.state == "posted"
150+
and invoice.payment_state != "paid"
151+
and existed_reconciliations
130152
and (
131153
not invoice.payment_mode_id
132154
or not invoice.payment_mode_id.auto_reconcile_outstanding_credits
@@ -137,11 +159,12 @@ def _compute_payment_mode_warning(self):
137159
"reconciled payments."
138160
)
139161
elif (
140-
invoice.state == "open"
141-
and not invoice.payment_move_line_ids
162+
invoice.state == "posted"
163+
and invoice.payment_state != "paid"
164+
and not existed_reconciliations
142165
and invoice.payment_mode_id
143166
and invoice.payment_mode_id.auto_reconcile_outstanding_credits
144-
and invoice.has_outstanding
167+
and invoice.invoice_has_outstanding
145168
):
146169
invoice.payment_mode_warning = _(
147170
"Changing payment mode will reconcile outstanding credits."
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright 2019 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3-
from odoo import api, fields, models
3+
from odoo import fields, models
44

55

66
class AccountPartialReconcile(models.Model):
@@ -9,8 +9,8 @@ class AccountPartialReconcile(models.Model):
99

1010
payment_mode_auto_reconcile = fields.Boolean()
1111

12-
@api.model
1312
def create(self, vals):
1413
if self.env.context.get("_payment_mode_auto_reconcile"):
15-
vals["payment_mode_auto_reconcile"] = True
14+
for val in vals:
15+
val["payment_mode_auto_reconcile"] = True
1616
return super(AccountPartialReconcile, self).create(vals)

account_payment_mode_auto_reconcile/static/description/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
6+
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
77
<title>Account Payment Mode Auto Reconcile</title>
88
<style type="text/css">
99

@@ -367,7 +367,7 @@ <h1 class="title">Account Payment Mode Auto Reconcile</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/10.0/account_payment_mode_auto_reconcile"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-reconcile-10-0/account-reconcile-10-0-account_payment_mode_auto_reconcile"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/98/10.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
370+
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/16.0/account_payment_mode_auto_reconcile"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-reconcile-16-0/account-reconcile-16-0-account_payment_mode_auto_reconcile"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/account-reconcile&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
371371
<p>This module adds a checkbox <cite>auto_reconcile_outstanding_credits</cite> on account
372372
payment modes to allow automatic reconciliation on account invoices if it is
373373
checked.</p>
@@ -394,7 +394,7 @@ <h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
394394
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-reconcile/issues">GitHub Issues</a>.
395395
In case of trouble, please check there if your issue has already been reported.
396396
If you spotted it first, help us smashing it by providing a detailed and welcomed
397-
<a class="reference external" href="https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_payment_mode_auto_reconcile%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
397+
<a class="reference external" href="https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_payment_mode_auto_reconcile%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
398398
<p>Do not contact contributors directly about support or help with technical issues.</p>
399399
</div>
400400
<div class="section" id="credits">
@@ -418,7 +418,7 @@ <h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
418418
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
419419
mission is to support the collaborative development of Odoo features and
420420
promote its widespread use.</p>
421-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/10.0/account_payment_mode_auto_reconcile">OCA/account-reconcile</a> project on GitHub.</p>
421+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/16.0/account_payment_mode_auto_reconcile">OCA/account-reconcile</a> project on GitHub.</p>
422422
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
423423
</div>
424424
</div>

0 commit comments

Comments
 (0)