Skip to content

Commit 7335d8e

Browse files
committed
[IMP] account_payment_mode_auto_reconcile: Allows to reconcile with same payment mode
1 parent 17386a6 commit 7335d8e

File tree

6 files changed

+150
-27
lines changed

6 files changed

+150
-27
lines changed

account_payment_mode_auto_reconcile/README.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Account Payment Mode Auto Reconcile
33
===================================
44

5-
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67
!! This file is generated by oca-gen-addon-readme !!
78
!! changes will be overwritten. !!
89
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:902d568e59e5a39571d93111bf87a096fdc41ff0866a796d2a15b339d3b0fc85
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
912
1013
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1114
:target: https://odoo-community.org/page/development-status
@@ -20,10 +23,10 @@ Account Payment Mode Auto Reconcile
2023
:target: https://translation.odoo-community.org/projects/account-reconcile-16-0/account-reconcile-16-0-account_payment_mode_auto_reconcile
2124
:alt: Translate me on Weblate
2225
.. |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
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-reconcile&target_branch=16.0
2427
:alt: Try me on Runboat
2528

26-
|badge1| |badge2| |badge3| |badge4| |badge5|
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
2730

2831
This module adds a checkbox `auto_reconcile_outstanding_credits` on account
2932
payment modes to allow automatic reconciliation on account invoices if it is
@@ -47,7 +50,7 @@ Bug Tracker
4750

4851
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/issues>`_.
4952
In case of trouble, please check there if your issue has already been reported.
50-
If you spotted it first, help us smashing it by providing a detailed and welcomed
53+
If you spotted it first, help us to smash it by providing a detailed and welcomed
5154
`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**>`_.
5255

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

account_payment_mode_auto_reconcile/models/account_move.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from operator import itemgetter
44

55
from odoo import _, api, fields, models
6+
from odoo.osv.expression import AND
67

78

89
class AccountMove(models.Model):
@@ -62,6 +63,35 @@ def write(self, vals):
6263
invoice.auto_unreconcile_credits()
6364
return res
6465

66+
def _get_auto_reconcile_credits_domain(self, credits_dict) -> list:
67+
"""
68+
Get the domain to filter outstanding credit lines
69+
70+
Depends on:
71+
72+
- auto_reconcile_same_journal
73+
- auto_reconcile_same_payment_mode
74+
75+
Override this to add some filter criteria
76+
"""
77+
self.ensure_one()
78+
line_ids = [credit["id"] for credit in credits_dict]
79+
domain = [("id", "in", line_ids)]
80+
if self.payment_mode_id.auto_reconcile_same_journal:
81+
domain = AND([domain, [("journal_id", "=", self.journal_id.id)]])
82+
if self.payment_mode_id.auto_reconcile_same_payment_mode:
83+
domain = AND(
84+
[
85+
domain,
86+
[
87+
"|",
88+
("payment_mode_id", "=", False),
89+
("payment_mode_id", "=", self.payment_mode_id.id),
90+
],
91+
]
92+
)
93+
return domain
94+
6595
def auto_reconcile_credits(self, partial_allowed=True):
6696
for invoice in self:
6797
invoice._compute_payments_widget_to_reconcile_info()
@@ -72,8 +102,7 @@ def auto_reconcile_credits(self, partial_allowed=True):
72102
# Get outstanding credits in chronological order
73103
# (using reverse because aml is sorted by date desc as default)
74104
credits_dict = credits_info.get("content", False)
75-
if invoice.payment_mode_id.auto_reconcile_same_journal:
76-
credits_dict = invoice._filter_payment_same_journal(credits_dict)
105+
credits_dict = self._get_auto_reconcile_credit_lines(credits_dict)
77106
sorted_credits = self._sort_credits_dict(credits_dict)
78107
for credit in sorted_credits:
79108
if (
@@ -88,12 +117,9 @@ def _sort_credits_dict(self, credits_dict):
88117
"""Sort credits dict according to their id (oldest recs first)"""
89118
return sorted(credits_dict, key=itemgetter("id"))
90119

91-
def _filter_payment_same_journal(self, credits_dict):
92-
"""Keep only credits on the same journal than the invoice."""
93-
self.ensure_one()
94-
line_ids = [credit["id"] for credit in credits_dict]
120+
def _get_auto_reconcile_credit_lines(self, credits_dict):
95121
lines = self.env["account.move.line"].search(
96-
[("id", "in", line_ids), ("journal_id", "=", self.journal_id.id)]
122+
self._get_auto_reconcile_credits_domain(credits_dict=credits_dict)
97123
)
98124
return [credit for credit in credits_dict if credit["id"] in lines.ids]
99125

account_payment_mode_auto_reconcile/models/account_payment_mode.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ class AccountPaymentMode(models.Model):
2323
string="Only same journal",
2424
help="Only reconcile payment in the same journal than the invoice",
2525
)
26+
auto_reconcile_same_payment_mode = fields.Boolean(
27+
string="Only same payment mode",
28+
help="Only reconcile counterparts that have the same payment mode "
29+
"(e.g. Credit notes) if defined.",
30+
)

account_payment_mode_auto_reconcile/static/description/index.html

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
54
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
5+
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
76
<title>Account Payment Mode Auto Reconcile</title>
87
<style type="text/css">
98

109
/*
1110
:Author: David Goodger (goodger@python.org)
12-
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
1615
17-
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
16+
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
1918
*/
2019

@@ -366,8 +365,10 @@ <h1 class="title">Account Payment Mode Auto Reconcile</h1>
366365
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367366
!! This file is generated by oca-gen-addon-readme !!
368367
!! changes will be overwritten. !!
368+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369+
!! source digest: sha256:902d568e59e5a39571d93111bf87a096fdc41ff0866a796d2a15b339d3b0fc85
369370
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
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>
371+
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" 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 image-reference" 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 image-reference" href="https://runboat.odoo-community.org/builds?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>
371372
<p>This module adds a checkbox <cite>auto_reconcile_outstanding_credits</cite> on account
372373
payment modes to allow automatic reconciliation on account invoices if it is
373374
checked.</p>
@@ -380,39 +381,39 @@ <h1 class="title">Account Payment Mode Auto Reconcile</h1>
380381
<p><strong>Table of contents</strong></p>
381382
<div class="contents local topic" id="contents">
382383
<ul class="simple">
383-
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
384-
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
385-
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
386-
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
387-
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
384+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
385+
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
386+
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
387+
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
388+
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
388389
</ul>
389390
</li>
390391
</ul>
391392
</div>
392393
<div class="section" id="bug-tracker">
393-
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
394+
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
394395
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-reconcile/issues">GitHub Issues</a>.
395396
In case of trouble, please check there if your issue has already been reported.
396-
If you spotted it first, help us smashing it by providing a detailed and welcomed
397+
If you spotted it first, help us to smash it by providing a detailed and welcomed
397398
<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>
398399
<p>Do not contact contributors directly about support or help with technical issues.</p>
399400
</div>
400401
<div class="section" id="credits">
401-
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
402+
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
402403
<div class="section" id="authors">
403-
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
404+
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
404405
<ul class="simple">
405406
<li>Camptocamp</li>
406407
</ul>
407408
</div>
408409
<div class="section" id="contributors">
409-
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
410+
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
410411
<ul class="simple">
411412
<li>Akim Juillerat &lt;<a class="reference external" href="mailto:akim.juillerat&#64;camptocamp.com">akim.juillerat&#64;camptocamp.com</a>&gt;</li>
412413
</ul>
413414
</div>
414415
<div class="section" id="maintainers">
415-
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
416+
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
416417
<p>This module is maintained by the OCA.</p>
417418
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
418419
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose

account_payment_mode_auto_reconcile/tests/test_partner_auto_reconcile.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,87 @@ def test_invoice_auto_reconcile_different_journal(self):
297297
self.assertTrue(self.payment_mode.auto_reconcile_outstanding_credits)
298298
self.assertEqual(self.invoice_copy.amount_residual, 1725.0)
299299
self.assertEqual(auto_rec_invoice.amount_residual, 1150.0)
300+
301+
def test_invoice_auto_reconcile_same_journal_different_method(self):
302+
"""
303+
Create an invoice with a different partner
304+
Create a credit note with a different payment mode for that partner
305+
306+
Validate the credit note
307+
Validate the invoice
308+
309+
Check that the credit note has not been reconciled with invoice
310+
"""
311+
self.payment_mode.auto_reconcile_same_journal = True
312+
self.payment_mode.auto_reconcile_same_payment_mode = True
313+
314+
partner = self.env["res.partner"].create(
315+
{
316+
"name": "Partner no reconcile",
317+
}
318+
)
319+
320+
invoice = self.invoice.copy(
321+
{
322+
"payment_mode_id": self.payment_mode.id,
323+
"journal_id": self.sale_journal.id,
324+
"partner_id": partner.id,
325+
}
326+
)
327+
328+
credit_note = self.invoice.copy(
329+
{
330+
"move_type": "out_refund",
331+
"payment_mode_id": self.env.ref(
332+
"account_payment_mode.payment_mode_inbound_ct2"
333+
).id,
334+
"journal_id": self.sale_journal.id,
335+
"partner_id": partner.id,
336+
}
337+
)
338+
339+
credit_note.action_post()
340+
invoice.action_post()
341+
self.assertTrue(self.payment_mode.auto_reconcile_outstanding_credits)
342+
self.assertEqual(invoice.amount_residual, 1150.0)
343+
344+
def test_invoice_auto_reconcile_same_journal_same_method(self):
345+
"""
346+
Create an invoice with a different partner
347+
Create a credit note with a same payment mode for that partner
348+
349+
Validate the credit note
350+
Validate the invoice
351+
352+
Check that the credit note has been reconciled with invoice
353+
"""
354+
self.payment_mode.auto_reconcile_same_journal = True
355+
self.payment_mode.auto_reconcile_same_payment_mode = True
356+
357+
partner = self.env["res.partner"].create(
358+
{
359+
"name": "Partner no reconcile",
360+
}
361+
)
362+
363+
invoice = self.invoice.copy(
364+
{
365+
"payment_mode_id": self.payment_mode.id,
366+
"journal_id": self.sale_journal.id,
367+
"partner_id": partner.id,
368+
}
369+
)
370+
371+
credit_note = self.invoice.copy(
372+
{
373+
"move_type": "out_refund",
374+
"payment_mode_id": self.payment_mode.id,
375+
"journal_id": self.sale_journal.id,
376+
"partner_id": partner.id,
377+
}
378+
)
379+
380+
credit_note.action_post()
381+
invoice.action_post()
382+
self.assertTrue(self.payment_mode.auto_reconcile_outstanding_credits)
383+
self.assertEqual(invoice.amount_residual, 0.0)

account_payment_mode_auto_reconcile/views/account_payment_mode.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
name="auto_reconcile_same_journal"
2020
attrs="{'invisible': [('auto_reconcile_outstanding_credits', '=', False)]}"
2121
/>
22+
<field
23+
name="auto_reconcile_same_payment_mode"
24+
attrs="{'invisible': [('auto_reconcile_outstanding_credits', '=', False)]}"
25+
/>
2226
</group>
2327
</group>
2428
</field>

0 commit comments

Comments
 (0)