Skip to content

Commit 3241887

Browse files
author
sonhd91
committed
[IMP] account_payment_mode_auto_reconcile: black, isort, prettier
1 parent 8becfc5 commit 3241887

File tree

12 files changed

+281
-213
lines changed

12 files changed

+281
-213
lines changed

account_payment_mode_auto_reconcile/__manifest__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2019 Camptocamp SA
32
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
43
{
54
"name": "Account Payment Mode Auto Reconcile",
65
"summary": "Reconcile outstanding credits according to payment mode",
76
"version": "10.0.1.0.0",
87
"category": "Banking addons",
9-
"website": "https://github.com/OCA/bank-payment",
8+
"website": "https://github.com/OCA/account-reconcile",
109
"author": "Camptocamp, Odoo Community Association (OCA)",
1110
"license": "AGPL-3",
1211
"installable": True,
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22
<odoo>
3-
<record id="account_payment_mode.payment_mode_inbound_dd1" model="account.payment.mode">
4-
<field name="auto_reconcile_outstanding_credits" eval="True"/>
3+
<record
4+
id="account_payment_mode.payment_mode_inbound_dd1"
5+
model="account.payment.mode"
6+
>
7+
<field name="auto_reconcile_outstanding_credits" eval="True" />
58
</record>
69
</odoo>
Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2019 Camptocamp SA
32
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
43
import json
54
from operator import itemgetter
65

7-
from odoo import api, fields, models, _
6+
from odoo import _, api, fields, models
87

98

109
class AccountInvoice(models.Model):
@@ -14,20 +13,20 @@ class AccountInvoice(models.Model):
1413
# Allow changing payment mode in open state
1514
# TODO: Check if must be done in account_payment_partner instead
1615
payment_mode_id = fields.Many2one(
17-
states={'draft': [('readonly', False)], 'open': [('readonly', False)]}
16+
states={"draft": [("readonly", False)], "open": [("readonly", False)]}
1817
)
1918
payment_mode_warning = fields.Char(
20-
compute='_compute_payment_mode_warning',
19+
compute="_compute_payment_mode_warning",
2120
)
2221
display_payment_mode_warning = fields.Boolean(
23-
compute='_compute_payment_mode_warning',
22+
compute="_compute_payment_mode_warning",
2423
)
2524

2625
@api.multi
2726
def invoice_validate(self):
2827
res = super(AccountInvoice, self).invoice_validate()
2928
for invoice in self:
30-
if invoice.type != 'out_invoice':
29+
if invoice.type != "out_invoice":
3130
continue
3231
if not invoice.payment_mode_id.auto_reconcile_outstanding_credits:
3332
continue
@@ -40,23 +39,18 @@ def invoice_validate(self):
4039
@api.multi
4140
def write(self, vals):
4241
res = super(AccountInvoice, self).write(vals)
43-
if 'payment_mode_id' in vals:
42+
if "payment_mode_id" in vals:
4443
for invoice in self:
4544
# Do not auto reconcile anything else than open customer inv
46-
if invoice.state != 'open' or invoice.type != 'out_invoice':
45+
if invoice.state != "open" or invoice.type != "out_invoice":
4746
continue
4847
payment_mode = invoice.payment_mode_id
4948
# Auto reconcile if payment mode sets it
50-
if (
51-
payment_mode
52-
and payment_mode.auto_reconcile_outstanding_credits
53-
):
49+
if payment_mode and payment_mode.auto_reconcile_outstanding_credits:
5450
partial = payment_mode.auto_reconcile_allow_partial
5551
invoice.with_context(
5652
_payment_mode_auto_reconcile=True
57-
).auto_reconcile_credits(
58-
partial_allowed=partial
59-
)
53+
).auto_reconcile_credits(partial_allowed=partial)
6054
# If the payment mode is not using auto reconcile we remove
6155
# the existing reconciliations
6256
elif invoice.payment_move_line_ids:
@@ -68,98 +62,90 @@ def auto_reconcile_credits(self, partial_allowed=True):
6862
for invoice in self:
6963
if not invoice.has_outstanding:
7064
continue
71-
credits_info = json.loads(
72-
invoice.outstanding_credits_debits_widget
73-
)
65+
credits_info = json.loads(invoice.outstanding_credits_debits_widget)
7466
# Get outstanding credits in chronological order
7567
# (using reverse because aml is sorted by date desc as default)
76-
credits_dict = credits_info.get('content')
68+
credits_dict = credits_info.get("content")
7769
if invoice.payment_mode_id.auto_reconcile_same_journal:
78-
credits_dict = invoice._filter_payment_same_journal(
79-
credits_dict
80-
)
70+
credits_dict = invoice._filter_payment_same_journal(credits_dict)
8171
sorted_credits = self._sort_credits_dict(credits_dict)
8272
for credit in sorted_credits:
83-
if (
84-
not partial_allowed
85-
and credit.get('amount') > invoice.residual
86-
):
73+
if not partial_allowed and credit.get("amount") > invoice.residual:
8774
continue
88-
invoice.assign_outstanding_credit(credit.get('id'))
75+
invoice.assign_outstanding_credit(credit.get("id"))
8976

9077
@api.model
9178
def _sort_credits_dict(self, credits_dict):
9279
"""Sort credits dict according to their id (oldest recs first)"""
93-
return sorted(credits_dict, key=itemgetter('id'))
80+
return sorted(credits_dict, key=itemgetter("id"))
9481

9582
@api.multi
9683
def _filter_payment_same_journal(self, credits_dict):
9784
"""Keep only credits on the same journal than the invoice."""
9885
self.ensure_one()
99-
line_ids = [credit['id'] for credit in credits_dict]
100-
lines = self.env['account.move.line'].search([
101-
('id', 'in', line_ids), ('journal_id', '=', self.journal_id.id)
102-
])
103-
return [credit for credit in credits_dict if credit['id'] in lines.ids]
86+
line_ids = [credit["id"] for credit in credits_dict]
87+
lines = self.env["account.move.line"].search(
88+
[("id", "in", line_ids), ("journal_id", "=", self.journal_id.id)]
89+
)
90+
return [credit for credit in credits_dict if credit["id"] in lines.ids]
10491

10592
@api.multi
10693
def auto_unreconcile_credits(self):
10794
for invoice in self:
108-
payments_info = json.loads(invoice.payments_widget or '{}')
109-
for payment in payments_info.get('content', []):
110-
aml = self.env['account.move.line'].browse(
111-
payment.get('payment_id')
112-
)
95+
payments_info = json.loads(invoice.payments_widget or "{}")
96+
for payment in payments_info.get("content", []):
97+
aml = self.env["account.move.line"].browse(payment.get("payment_id"))
11398
for apr in aml.matched_debit_ids:
114-
if apr.amount != payment.get('amount'):
99+
if apr.amount != payment.get("amount"):
115100
continue
116101
if (
117102
apr.payment_mode_auto_reconcile
118103
and apr.debit_move_id.invoice_id == invoice
119104
):
120-
aml.with_context(
121-
invoice_id=invoice.id
122-
).remove_move_reconcile()
105+
aml.with_context(invoice_id=invoice.id).remove_move_reconcile()
123106

124107
@api.depends(
125-
'type', 'payment_mode_id', 'payment_move_line_ids', 'state',
126-
'has_outstanding'
108+
"type", "payment_mode_id", "payment_move_line_ids", "state", "has_outstanding"
127109
)
128110
def _compute_payment_mode_warning(self):
129111
# TODO Improve me but watch out
130112
for invoice in self:
131-
if invoice.type != 'out_invoice' or invoice.state == 'paid':
132-
invoice.payment_mode_warning = ''
113+
if invoice.type != "out_invoice" or invoice.state == "paid":
114+
invoice.payment_mode_warning = ""
133115
invoice.display_payment_mode_warning = False
134116
continue
135117
invoice.display_payment_mode_warning = True
136118
if (
137-
invoice.state != 'open' and invoice.payment_mode_id and
138-
invoice.payment_mode_id.auto_reconcile_outstanding_credits
119+
invoice.state != "open"
120+
and invoice.payment_mode_id
121+
and invoice.payment_mode_id.auto_reconcile_outstanding_credits
139122
):
140123
invoice.payment_mode_warning = _(
141-
'Validating invoices with this payment mode will reconcile'
142-
' any outstanding credits.'
124+
"Validating invoices with this payment mode will reconcile"
125+
" any outstanding credits."
143126
)
144127
elif (
145-
invoice.state == 'open' and invoice.payment_move_line_ids and (
146-
not invoice.payment_mode_id or not
147-
invoice.payment_mode_id.auto_reconcile_outstanding_credits
128+
invoice.state == "open"
129+
and invoice.payment_move_line_ids
130+
and (
131+
not invoice.payment_mode_id
132+
or not invoice.payment_mode_id.auto_reconcile_outstanding_credits
148133
)
149134
):
150135
invoice.payment_mode_warning = _(
151-
'Changing payment mode will unreconcile existing auto '
152-
'reconciled payments.'
136+
"Changing payment mode will unreconcile existing auto "
137+
"reconciled payments."
153138
)
154139
elif (
155-
invoice.state == 'open' and not invoice.payment_move_line_ids
140+
invoice.state == "open"
141+
and not invoice.payment_move_line_ids
156142
and invoice.payment_mode_id
157143
and invoice.payment_mode_id.auto_reconcile_outstanding_credits
158144
and invoice.has_outstanding
159145
):
160146
invoice.payment_mode_warning = _(
161-
'Changing payment mode will reconcile outstanding credits.'
147+
"Changing payment mode will reconcile outstanding credits."
162148
)
163149
else:
164-
invoice.payment_mode_warning = ''
150+
invoice.payment_mode_warning = ""
165151
invoice.display_payment_mode_warning = False
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2019 Camptocamp SA
32
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
4-
from odoo import models, fields, api
3+
from odoo import api, fields, models
54

65

76
class AccountPartialReconcile(models.Model):
87

9-
_inherit = 'account.partial.reconcile'
8+
_inherit = "account.partial.reconcile"
109

1110
payment_mode_auto_reconcile = fields.Boolean()
1211

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

account_payment_mode_auto_reconcile/models/account_payment_mode.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2019 Camptocamp SA
32
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
4-
from odoo import models, fields
3+
from odoo import fields, models
54

65

76
class AccountPaymentMode(models.Model):
@@ -11,8 +10,8 @@ class AccountPaymentMode(models.Model):
1110
auto_reconcile_outstanding_credits = fields.Boolean(
1211
string="Auto reconcile",
1312
help="Reconcile automatically outstanding credits when an invoice "
14-
"using this payment mode is validated, or when this payment mode "
15-
"is defined on an open invoice."
13+
"using this payment mode is validated, or when this payment mode "
14+
"is defined on an open invoice.",
1615
)
1716
auto_reconcile_allow_partial = fields.Boolean(
1817
default=True,

0 commit comments

Comments
 (0)