Skip to content

Commit

Permalink
[MIG] sale_invoice_plan: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmen Rondon Regalado committed Jan 31, 2025
1 parent ebc4851 commit a0827ba
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 50 deletions.
2 changes: 1 addition & 1 deletion sale_invoice_plan/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Sales Invoice Plan",
"summary": "Add to sales order, ability to manage future invoice plan",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/sale-workflow",
Expand Down
4 changes: 2 additions & 2 deletions sale_invoice_plan/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _compute_invoice_plan_total(self):
def _compute_invoice_plan_process(self):
for rec in self:
has_invoice_plan = rec.use_invoice_plan and rec.invoice_plan_ids
to_invoice = rec.invoice_plan_ids.filtered(lambda l: not l.invoiced)
to_invoice = rec.invoice_plan_ids.filtered(lambda line: not line.invoiced)
inv_or_adv = rec.invoice_status == "to invoice" or (
rec.invoice_status == "no"
and "advance" in to_invoice.mapped("invoice_type")
Expand All @@ -65,7 +65,7 @@ def _check_invoice_plan_total_percent(self):
def _check_invoice_plan(self):
for rec in self:
if rec.state != "draft":
if rec.invoice_plan_ids.filtered(lambda l: not l.percent):
if rec.invoice_plan_ids.filtered(lambda line: not line.percent):
raise ValidationError(
_("Please fill percentage for all invoice plan lines")
)
Expand Down
8 changes: 4 additions & 4 deletions sale_invoice_plan/models/sale_invoice_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _compute_amount(self):
# For last line, amount is the left over
if rec.last:
installments = rec.sale_id.invoice_plan_ids.filtered(
lambda l: l.invoice_type == "installment"
lambda line: line.invoice_type == "installment"
)
prev_amount = sum((installments - rec).mapped("amount"))
rec.amount = amount_untaxed - prev_amount
Expand All @@ -117,7 +117,7 @@ def _inverse_amount(self):
if rec.sale_id.amount_untaxed != 0:
if rec.last:
installments = rec.sale_id.invoice_plan_ids.filtered(
lambda l: l.invoice_type == "installment"
lambda line: line.invoice_type == "installment"
)
prev_percent = sum((installments - rec).mapped("percent"))
rec.percent = 100 - prev_percent
Expand Down Expand Up @@ -149,7 +149,7 @@ def _get_amount_invoice(self, invoices):
)
if deposit_product_id:
lines = invoices.mapped("invoice_line_ids").filtered(
lambda l: l.product_id.id != int(deposit_product_id)
lambda line: line.product_id.id != int(deposit_product_id)
)
amount_invoiced = sum(lines.mapped("price_subtotal"))
return amount_invoiced
Expand All @@ -158,7 +158,7 @@ def _get_amount_invoice(self, invoices):
def _compute_invoiced(self):
for rec in self:
invoiced = rec.invoice_move_ids.filtered(
lambda l: l.state in ("draft", "posted")
lambda line: line.state in ("draft", "posted")
)
rec.invoiced = True if invoiced else False
rec.amount_invoiced = (
Expand Down
9 changes: 5 additions & 4 deletions sale_invoice_plan/tests/test_sale_invoice_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TestSaleInvoicePlan(common.TestSaleCommon):
@classmethod
def setUpClass(cls):
super(TestSaleInvoicePlan, cls).setUpClass()
super().setUpClass()
context_no_mail = {
"no_reset_password": True,
"mail_create_nosubscribe": True,
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_02_invoice_plan_with_advance(self):
with self.assertRaises(ValidationError):
self.so_service.action_confirm()
advance_line = self.so_service.invoice_plan_ids.filtered(
lambda l: l.invoice_type == "advance"
lambda line: line.invoice_type == "advance"
)
self.assertEqual(len(advance_line), 1, "No one advance line")
# Add 10% to advance
Expand All @@ -259,7 +259,7 @@ def test_02_invoice_plan_with_advance(self):
# Valid total quantity of invoices (exclude Advance line)
quantity = sum(
invoices.mapped("invoice_line_ids")
.filtered(lambda l: l.product_id == self.product_order)
.filtered(lambda line: line.product_id == self.product_order)
.mapped("quantity")
)
self.assertEqual(quantity, 1, "Wrong number of total invoice quantity")
Expand Down Expand Up @@ -323,7 +323,8 @@ def test_invoice_plan_so_edit(self):
],
}
)
# Overall amount changed to 3080, install amount not changed, only percent changed.
# Overall amount changed to 3080, install amount not changed,
# only percent changed.
self.assertEqual(self.so_service.amount_total, 3080.0)
self.so_service.invoice_plan_ids._compute_amount()
self.assertEqual(first_install.amount, 280.0)
Expand Down
56 changes: 18 additions & 38 deletions sale_invoice_plan/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,13 @@
<field name="model">sale.invoice.plan</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="no_edit" invisible="1" />
<field name="no_edit" column_invisible="1" />
<field name="analytic_account_id" />
<field
name="installment"
attrs="{'readonly': [('no_edit', '=', True)]}"
/>
<field
name="plan_date"
attrs="{'readonly': [('no_edit', '=', True)]}"
/>
<field
name="invoice_type"
attrs="{'readonly': [('no_edit', '=', True)]}"
/>
<field
name="percent"
optional="show"
attrs="{'readonly': [('no_edit', '=', True)]}"
/>
<field
name="amount"
optional="show"
attrs="{'readonly': [('no_edit', '=', True)]}"
/>
<field name="installment" readonly="no_edit" />
<field name="plan_date" readonly="no_edit" />
<field name="invoice_type" readonly="no_edit" />
<field name="percent" optional="show" readonly="no_edit" />
<field name="amount" optional="show" readonly="no_edit" />
<field name="amount_invoiced" optional="hide" sum="Amount" />
<field name="to_invoice" />
<field name="invoiced" />
Expand All @@ -37,7 +20,7 @@
optional="hide"
widget="many2many_tags"
/>
<field name="last" invisible="1" />
<field name="last" column_invisible="1" />
</tree>
</field>
</record>
Expand All @@ -62,7 +45,7 @@
</group>
<separator
string="Related Invoices"
attrs="{'invisible': [('invoice_move_ids', '=', [])]}"
invisible="invoice_move_ids == []"
/>
<field name="invoice_move_ids" widget="many2many_tags" />
</form>
Expand All @@ -74,7 +57,7 @@
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr='/form/sheet/notebook' position="before">
<div attrs="{'readonly': [('invoice_count', '>', 0)]}">
<div readonly="invoice_count > 0">
<field name="use_invoice_plan" />
<label for="use_invoice_plan" />
</div>
Expand All @@ -86,49 +69,46 @@
string="Create Invoice by Plan"
type="action"
class="btn-primary"
attrs="{'invisible': [('invoice_plan_process', '=', False)]}"
invisible="not invoice_plan_process"
/>
</xpath>
<xpath
expr="//button[@name='%(sale.action_view_sale_advance_payment_inv)d'][1]"
position="attributes"
>
<attribute
name="attrs"
>{'invisible': ['|', ('invoice_plan_process', '=', True), ('invoice_status', '!=', 'to invoice')]}</attribute>
name="invisible"
>invoice_plan_process or invoice_status != 'to invoice'</attribute>
</xpath>
<xpath
expr="//button[@name='%(sale.action_view_sale_advance_payment_inv)d'][2]"
position="attributes"
>
<attribute
name="attrs"
>{'invisible': ['|', ('invoice_plan_process', '=', True), '|', ('invoice_status', '!=', 'no'), ('state', '!=', 'sale')]}</attribute>
name="invisible"
>invoice_plan_process or invoice_status != 'no' or state != 'sale'</attribute>
</xpath>
<xpath expr="/form/sheet/notebook/page" position="after">
<page
string="Invoice Plan"
attrs="{'invisible': [('use_invoice_plan', '=', False)]}"
>
<page string="Invoice Plan" invisible="not use_invoice_plan">
<button
name="%(action_sale_create_invoice_plan)d"
string="⇒ Create Invoice Plan"
type="action"
class="oe_link"
attrs="{'invisible': ['|', ('invoice_plan_ids', '!=', []), ('invoice_count', '>', 0)]}"
invisible="invoice_plan_ids or invoice_count > 0"
/>
<button
name="remove_invoice_plan"
string="⇒ Remove Invoice Plan"
type="object"
class="oe_link"
attrs="{'invisible': ['|', ('invoice_plan_ids', '=', []), ('invoice_count', '>', 0)]}"
invisible="not invoice_plan_ids or invoice_count > 0"
confirm="Are you sure to remove this invoice plan?"
/>
<field
name="invoice_plan_ids"
context="{'tree_view_ref': 'sale_invoice_plan.view_sale_invoice_plan_tree'}"
attrs="{'invisible': [('invoice_plan_ids', '=', [])]}"
invisible="not invoice_plan_ids"
/>
<group class="oe_subtotal_footer oe_right">
<field name="invoice_plan_total_percent" />
Expand Down
2 changes: 1 addition & 1 deletion sale_invoice_plan/wizard/sale_make_planned_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_invoices_by_plan(self):
MakeInvoice = self.env["sale.advance.payment.inv"]
invoice_plans = (
self._context.get("all_remain_invoices")
and sale.invoice_plan_ids.filtered(lambda l: not l.invoiced)
and sale.invoice_plan_ids.filtered(lambda line: not line.invoiced)
or sale.invoice_plan_ids.filtered("to_invoice")
)
for plan in invoice_plans.sorted("installment"):
Expand Down

0 comments on commit a0827ba

Please sign in to comment.