Skip to content

Commit 55d8f93

Browse files
committed
[IMP] account_financial_discount: black, isort, prettier
1 parent 24b2eea commit 55d8f93

23 files changed

+886
-905
lines changed

account_financial_discount/__manifest__.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@
55
"version": "13.0.1.0.0",
66
"category": "Account",
77
"website": "camptocamp.com",
8-
"author": "Camptocamp",
8+
"author": "Camptocamp, Odoo Community Association (OCA)",
99
"license": "AGPL-3",
1010
"installable": True,
11-
"depends": [
12-
"account",
13-
"account_reconcile_model_strict_match_amount",
14-
],
11+
"depends": ["account", "account_reconcile_model_strict_match_amount"],
1512
"data": [
1613
"views/assets.xml",
1714
"views/payment_term_form.xml",
1815
"views/account_move.xml",
1916
"views/account_payment.xml",
2017
"views/account_reconcile_model.xml",
2118
"views/res_config_settings.xml",
22-
"views/payment_receipt.xml"
23-
],
24-
"qweb": [
25-
"static/src/xml/reconciliation_templates.xml",
19+
"views/payment_receipt.xml",
2620
],
21+
"qweb": ["static/src/xml/reconciliation_templates.xml"],
2722
}

account_financial_discount/models/account_move.py

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@
66

77

88
class AccountMove(models.Model):
9-
_inherit = 'account.move'
9+
_inherit = "account.move"
1010

1111
has_discount_available = fields.Boolean(
12-
'Has discount available',
13-
compute='_compute_financial_discount_data',
12+
"Has discount available",
13+
compute="_compute_financial_discount_data",
1414
# TODO implement read_group + search because we cannot store the field
1515
# as it depends on actual date
1616
)
1717
display_force_financial_discount = fields.Boolean(
18-
compute='_compute_financial_discount_data'
18+
compute="_compute_financial_discount_data"
1919
)
2020
force_financial_discount = fields.Boolean(
21-
'Force financial discount?',
21+
"Force financial discount?",
2222
default=False,
2323
help="If marked, financial discount will be applied even if the "
2424
"discount date is passed",
2525
)
2626
payment_blocked = fields.Boolean(
27-
'Is payment blocked',
27+
"Is payment blocked",
2828
default=False,
2929
help="Allows group-by but has no logic linked to it",
3030
)
3131

3232
# TODO refactor the two functions below together
3333
def _get_discount_available(self):
3434
self.ensure_one()
35-
if self.state == 'draft':
35+
if self.state == "draft":
3636
if (
3737
self.invoice_payment_term_id.days_discount
3838
and self.invoice_payment_term_id.percent_discount
@@ -48,25 +48,21 @@ def _get_discount_available(self):
4848
)
4949
):
5050
return True
51-
elif self.state == 'posted':
51+
elif self.state == "posted":
5252
disc_date = self._get_first_payment_term_line().date_discount
53-
if (
54-
disc_date
55-
and disc_date >= date.today()
56-
or self.force_financial_discount
57-
):
53+
if disc_date and disc_date >= date.today() or self.force_financial_discount:
5854
return True
5955
return False
6056

6157
def _get_display_force_financial_discount(self):
6258
self.ensure_one()
63-
if self.state == 'draft':
59+
if self.state == "draft":
6460
if (
6561
self.invoice_payment_term_id.days_discount
6662
and self.invoice_payment_term_id.percent_discount
6763
):
6864
return True
69-
elif self.state == 'posted':
65+
elif self.state == "posted":
7066
first_payment_term_line = self._get_first_payment_term_line()
7167
if (
7268
first_payment_term_line.date_discount
@@ -87,11 +83,11 @@ def _get_discount_amount(self, amount=None):
8783
return discount_amount
8884

8985
@api.depends(
90-
'invoice_date',
91-
'invoice_payment_term_id',
92-
'invoice_payment_term_id.days_discount',
93-
'invoice_payment_term_id.percent_discount',
94-
'force_financial_discount',
86+
"invoice_date",
87+
"invoice_payment_term_id",
88+
"invoice_payment_term_id.days_discount",
89+
"invoice_payment_term_id.percent_discount",
90+
"force_financial_discount",
9591
)
9692
def _compute_financial_discount_data(self):
9793
"""Compute discount financial discount fields"""
@@ -109,14 +105,13 @@ def post(self):
109105
def _get_first_payment_term_line(self):
110106
self.ensure_one()
111107
payment_term_lines = self.line_ids.filtered(
112-
lambda line: line.account_id.user_type_id.type
113-
in ('receivable', 'payable')
108+
lambda line: line.account_id.user_type_id.type in ("receivable", "payable")
114109
)
115-
return fields.first(payment_term_lines.sorted('date_maturity'))
110+
return fields.first(payment_term_lines.sorted("date_maturity"))
116111

117112
def _get_taxes_lines(self):
118113
self.ensure_one()
119-
taxes_applied = self.line_ids.mapped('tax_ids')
114+
taxes_applied = self.line_ids.mapped("tax_ids")
120115
taxes_lines = self.line_ids.filtered(
121116
lambda line: line.tax_line_id in taxes_applied
122117
)
@@ -134,21 +129,21 @@ def _store_financial_discount(self):
134129
and payment_term.percent_discount
135130
and len(tax_line) <= 1
136131
and (
137-
(move.type == 'out_invoice' and payment_term_line.debit)
138-
or (move.type == 'in_invoice' and payment_term_line.credit)
132+
(move.type == "out_invoice" and payment_term_line.debit)
133+
or (move.type == "in_invoice" and payment_term_line.credit)
139134
)
140135
):
141136
pay_term_vals = move._prepare_discount_vals(payment_term)
142137
if tax_line:
143138
tax_discount_amount = move._get_discount_amount(
144139
tax_line.debit or tax_line.credit
145140
)
146-
if move.type == 'in_invoice':
141+
if move.type == "in_invoice":
147142
tax_discount_amount = -tax_discount_amount
148143
pay_term_vals.update(
149144
{
150-
'discount_tax_line_id': tax_line.id,
151-
'amount_discount_tax': tax_discount_amount,
145+
"discount_tax_line_id": tax_line.id,
146+
"amount_discount_tax": tax_discount_amount,
152147
}
153148
)
154149
payment_term_line.write(pay_term_vals)
@@ -159,22 +154,20 @@ def _prepare_discount_vals(self, payment_term):
159154
if not payment_term.days_discount or not payment_term.percent_discount:
160155
vals.update(
161156
{
162-
'amount_discount': 0,
163-
'amount_discount_currency': 0,
164-
'date_discount': False,
157+
"amount_discount": 0,
158+
"amount_discount_currency": 0,
159+
"date_discount": False,
165160
}
166161
)
167162
else:
168163
company_currency = self.company_id.currency_id
169164
diff_currency = self.currency_id != company_currency
170-
date_invoice = (
171-
self.date or self.invoice_date or fields.Date.today()
172-
)
165+
date_invoice = self.date or self.invoice_date or fields.Date.today()
173166
date_discount = payment_term.calc_discount_date(date_invoice)
174167
# if there is a discount defined we always want the amount
175168
# the date is enough to lock it down.
176169
amount_discount_invoice_currency = self._get_discount_amount()
177-
vals['date_discount'] = date_discount
170+
vals["date_discount"] = date_discount
178171
amount_discount_company_currency = False
179172
if diff_currency:
180173
amount_discount_company_currency = self.currency_id._convert(
@@ -183,20 +176,16 @@ def _prepare_discount_vals(self, payment_term):
183176
self.company_id,
184177
date_invoice,
185178
)
186-
if self.type == 'out_invoice':
179+
if self.type == "out_invoice":
187180
if diff_currency:
188-
vals['amount_discount'] = amount_discount_company_currency
189-
vals[
190-
'amount_discount_currency'
191-
] = amount_discount_invoice_currency
181+
vals["amount_discount"] = amount_discount_company_currency
182+
vals["amount_discount_currency"] = amount_discount_invoice_currency
192183
else:
193-
vals['amount_discount'] = amount_discount_invoice_currency
194-
elif self.type == 'in_invoice':
184+
vals["amount_discount"] = amount_discount_invoice_currency
185+
elif self.type == "in_invoice":
195186
if diff_currency:
196-
vals['amount_discount'] = -amount_discount_company_currency
197-
vals[
198-
'amount_discount_currency'
199-
] = -amount_discount_invoice_currency
187+
vals["amount_discount"] = -amount_discount_company_currency
188+
vals["amount_discount_currency"] = -amount_discount_invoice_currency
200189
else:
201-
vals['amount_discount'] = -amount_discount_invoice_currency
190+
vals["amount_discount"] = -amount_discount_invoice_currency
202191
return vals

account_financial_discount/models/account_move_line.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66

77
class AccountMoveLine(models.Model):
8-
_inherit = 'account.move.line'
8+
_inherit = "account.move.line"
99

1010
amount_discount = fields.Monetary(
11-
'Financial Discount amount in company currency',
12-
currency_field='company_currency_id',
11+
"Financial Discount amount in company currency",
12+
currency_field="company_currency_id",
1313
)
1414
amount_discount_currency = fields.Monetary(
15-
'Financial Discount amount in an optional other currency if it is a '
16-
'multi-currency entry.'
15+
"Financial Discount amount in an optional other currency if it is a "
16+
"multi-currency entry."
1717
)
18-
date_discount = fields.Date('Financial Discount date')
19-
discount_tax_line_id = fields.Many2one('account.move.line')
20-
amount_discount_tax = fields.Monetary(currency_field='company_currency_id')
18+
date_discount = fields.Date("Financial Discount date")
19+
discount_tax_line_id = fields.Many2one("account.move.line")
20+
amount_discount_tax = fields.Monetary(currency_field="company_currency_id")

0 commit comments

Comments
 (0)