Skip to content

Commit 681858b

Browse files
committed
[FIX] sale_invoice_plan: Pre-commit fixes
1 parent 1c7e895 commit 681858b

File tree

5 files changed

+29
-45
lines changed

5 files changed

+29
-45
lines changed

sale_invoice_plan/models/sale.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _compute_invoice_plan_total(self):
4444
def _compute_invoice_plan_process(self):
4545
for rec in self:
4646
has_invoice_plan = rec.use_invoice_plan and rec.invoice_plan_ids
47-
to_invoice = rec.invoice_plan_ids.filtered(lambda l: not l.invoiced)
47+
to_invoice = rec.invoice_plan_ids.filtered(lambda plan: not plan.invoiced)
4848
inv_or_adv = rec.invoice_status == "to invoice" or (
4949
rec.invoice_status == "no"
5050
and "advance" in to_invoice.mapped("invoice_type")
@@ -65,7 +65,7 @@ def _check_invoice_plan_total_percent(self):
6565
def _check_invoice_plan(self):
6666
for rec in self:
6767
if rec.state != "draft":
68-
if rec.invoice_plan_ids.filtered(lambda l: not l.percent):
68+
if rec.invoice_plan_ids.filtered(lambda plan: not plan.percent):
6969
raise ValidationError(
7070
_("Please fill percentage for all invoice plan lines")
7171
)

sale_invoice_plan/models/sale_invoice_plan.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _compute_amount(self):
102102
# For last line, amount is the left over
103103
if rec.last:
104104
installments = rec.sale_id.invoice_plan_ids.filtered(
105-
lambda l: l.invoice_type == "installment"
105+
lambda plan: plan.invoice_type == "installment"
106106
)
107107
prev_amount = sum((installments - rec).mapped("amount"))
108108
rec.amount = amount_untaxed - prev_amount
@@ -115,7 +115,7 @@ def _inverse_amount(self):
115115
if rec.sale_id.amount_untaxed != 0:
116116
if rec.last:
117117
installments = rec.sale_id.invoice_plan_ids.filtered(
118-
lambda l: l.invoice_type == "installment"
118+
lambda plan: plan.invoice_type == "installment"
119119
)
120120
prev_percent = sum((installments - rec).mapped("percent"))
121121
rec.percent = 100 - prev_percent
@@ -147,7 +147,7 @@ def _get_amount_invoice(self, invoices):
147147
)
148148
if deposit_product_id:
149149
lines = invoices.mapped("invoice_line_ids").filtered(
150-
lambda l: l.product_id.id != int(deposit_product_id)
150+
lambda line: line.product_id.id != int(deposit_product_id)
151151
)
152152
amount_invoiced = sum(lines.mapped("price_subtotal"))
153153
return amount_invoiced
@@ -156,7 +156,7 @@ def _get_amount_invoice(self, invoices):
156156
def _compute_invoiced(self):
157157
for rec in self:
158158
invoiced = rec.invoice_move_ids.filtered(
159-
lambda l: l.state in ("draft", "posted")
159+
lambda invoice: invoice.state in ("draft", "posted")
160160
)
161161
rec.invoiced = True if invoiced else False
162162
rec.amount_invoiced = (

sale_invoice_plan/tests/test_sale_invoice_plan.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ def setUpClass(cls):
5959
"code": "SJT0",
6060
}
6161
)
62-
cls.default_pricelist = cls.env['product.pricelist'].create({
63-
'name': 'Default Pricelist',
64-
})
62+
cls.default_pricelist = cls.env["product.pricelist"].create(
63+
{
64+
"name": "Default Pricelist",
65+
}
66+
)
6567

6668
cls.setUpClassicProducts()
6769

@@ -244,7 +246,7 @@ def test_02_invoice_plan_with_advance(self):
244246
with self.assertRaises(ValidationError):
245247
self.so_service.action_confirm()
246248
advance_line = self.so_service.invoice_plan_ids.filtered(
247-
lambda l: l.invoice_type == "advance"
249+
lambda plan: plan.invoice_type == "advance"
248250
)
249251
self.assertEqual(len(advance_line), 1, "No one advance line")
250252
# Add 10% to advance
@@ -262,7 +264,7 @@ def test_02_invoice_plan_with_advance(self):
262264
# Valid total quantity of invoices (exclude Advance line)
263265
quantity = sum(
264266
invoices.mapped("invoice_line_ids")
265-
.filtered(lambda l: l.product_id == self.product_order)
267+
.filtered(lambda line: line.product_id == self.product_order)
266268
.mapped("quantity")
267269
)
268270
self.assertEqual(quantity, 1, "Wrong number of total invoice quantity")
@@ -326,7 +328,8 @@ def test_invoice_plan_so_edit(self):
326328
],
327329
}
328330
)
329-
# Overall amount changed to 3080, install amount not changed, only percent changed.
331+
# Overall amount changed to 3080, install amount not
332+
# changed, only percent changed.
330333
self.assertEqual(self.so_service.amount_total, 3080.0)
331334
self.so_service.invoice_plan_ids._compute_amount()
332335
self.assertEqual(first_install.amount, 280.0)

sale_invoice_plan/views/sale_view.xml

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,11 @@
77
<tree editable="bottom">
88
<field name="no_edit" column_invisible="1" />
99
<field name="analytic_account_id" />
10-
<field
11-
name="installment"
12-
readonly="no_edit"
13-
/>
14-
<field
15-
name="plan_date"
16-
readonly="no_edit"
17-
/>
18-
<field
19-
name="invoice_type"
20-
readonly="no_edit"
21-
/>
22-
<field
23-
name="percent"
24-
optional="show"
25-
readonly="no_edit"
26-
/>
27-
<field
28-
name="amount"
29-
optional="show"
30-
readonly="no_edit"
31-
/>
10+
<field name="installment" readonly="no_edit" />
11+
<field name="plan_date" readonly="no_edit" />
12+
<field name="invoice_type" readonly="no_edit" />
13+
<field name="percent" optional="show" readonly="no_edit" />
14+
<field name="amount" optional="show" readonly="no_edit" />
3215
<field name="amount_invoiced" optional="hide" sum="Amount" />
3316
<field name="to_invoice" />
3417
<field name="invoiced" />
@@ -58,14 +41,15 @@
5841
<field name="percent" />
5942
<field name="amount" />
6043
<field name="invoiced" />
61-
<field name="invoice_move_ids" widget="many2many_tags" readonly="1"/>
44+
<field
45+
name="invoice_move_ids"
46+
widget="many2many_tags"
47+
readonly="1"
48+
/>
6249
</group>
6350
</group>
64-
<separator
65-
string="Related Invoices"
66-
invisible="not invoice_move_ids"
67-
/>
68-
<field name="invoice_move_ids" widget="many2many_tags" readonly="1"/>
51+
<separator string="Related Invoices" invisible="not invoice_move_ids" />
52+
<field name="invoice_move_ids" widget="many2many_tags" readonly="1" />
6953
</form>
7054
</field>
7155
</record>
@@ -107,10 +91,7 @@
10791
>invoice_plan_process or invoice_status != 'no' or state != 'sale'</attribute>
10892
</xpath>
10993
<xpath expr="/form/sheet/notebook/page" position="after">
110-
<page
111-
string="Invoice Plan"
112-
invisible="not use_invoice_plan"
113-
>
94+
<page string="Invoice Plan" invisible="not use_invoice_plan">
11495
<button
11596
name="%(action_sale_create_invoice_plan)d"
11697
string="⇒ Create Invoice Plan"

sale_invoice_plan/wizard/sale_make_planned_invoice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def create_invoices_by_plan(self):
1313
MakeInvoice = self.env["sale.advance.payment.inv"]
1414
invoice_plans = (
1515
self._context.get("all_remain_invoices")
16-
and sale.invoice_plan_ids.filtered(lambda l: not l.invoiced)
16+
and sale.invoice_plan_ids.filtered(lambda plan: not plan.invoiced)
1717
or sale.invoice_plan_ids.filtered("to_invoice")
1818
)
1919
for plan in invoice_plans.sorted("installment"):

0 commit comments

Comments
 (0)