Skip to content

Commit

Permalink
[IMP] sale_invoice_plan: usability - filter to invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeddies authored and dreispt committed Dec 20, 2023
1 parent 8899940 commit 5f76267
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
47 changes: 46 additions & 1 deletion sale_invoice_plan/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,59 @@ class SaleOrder(models.Model):
compute="_compute_invoice_plan_total",
string="Total Amount",
)
next_installment_date = fields.Date(
compute="_compute_next_installment_date",
store=True,
)
invoiced_installment_amount = fields.Monetary(
compute="_compute_invoiced_installment_amount",
store=True,
)
pending_installment_amount = fields.Monetary(
compute="_compute_pending_installment_amount",
store=True,
)

@api.depends("invoice_plan_ids.plan_date")
def _compute_next_installment_date(self):
for rec in self:
plans_to_invoice = rec.invoice_plan_ids.filtered(lambda x: x.to_invoice)
if plans_to_invoice:
rec.next_installment_date = plans_to_invoice[0].plan_date
else:
rec.next_installment_date = False

@api.depends("invoice_plan_ids")
@api.depends("invoice_plan_ids.amount_invoiced")
def _compute_invoiced_installment_amount(self):
for rec in self:
invoiced_plans = rec.invoice_plan_ids.filtered(lambda x: x.invoiced)
if invoiced_plans:
rec.invoiced_installment_amount = invoiced_plans[-1].amount_invoiced
else:
rec.invoiced_installment_amount = 0

@api.depends("invoice_plan_ids.amount")
def _compute_pending_installment_amount(self):
for rec in self:
plans_to_invoice = rec.invoice_plan_ids.filtered(lambda x: x.to_invoice)
if plans_to_invoice:
rec.pending_installment_amount = plans_to_invoice[0].amount
else:
rec.pending_installment_amount = 0

@api.depends("invoice_plan_ids.percent", "invoice_plan_ids.amount")
def _compute_invoice_plan_total(self):
for rec in self:
installments = rec.invoice_plan_ids.filtered("installment")
rec.invoice_plan_total_percent = sum(installments.mapped("percent"))
rec.invoice_plan_total_amount = sum(installments.mapped("amount"))

@api.depends(
"use_invoice_plan",
"state",
"invoice_status",
"invoice_plan_ids.invoiced",
)
def _compute_invoice_plan_process(self):
for rec in self:
has_invoice_plan = rec.use_invoice_plan and rec.invoice_plan_ids
Expand Down
51 changes: 51 additions & 0 deletions sale_invoice_plan/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,57 @@
</xpath>
</field>
</record>
<record id="view_order_tree_invoice_plan" model="ir.ui.view">
<field name="name">view.order.tree.invoice.plan</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='state']" position="after">
<field name="next_installment_date" optional="hide" />
<field name="invoiced_installment_amount" optional="hide" />
<field name="pending_installment_amount" optional="hide" />
</xpath>
</field>
</record>
<record id="view_order_search_invoice_plan" model="ir.ui.view">
<field name="name">view.order.search.invoice.plan</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.sale_order_view_search_inherit_sale" />
<field name="arch" type="xml">
<xpath expr="//filter[@name='my_sale_orders_filter']" position="inside">
<filter
string="Has Invoice Plan"
name="has_invoice_plan"
domain="[('invoice_plan_ids','!=', False)]"
/>
<filter
string="Has Pending Installment Amount"
name="has_pending_installment_amount"
domain="[('pending_installment_amount','!=', 0)]"
/>
<filter
string="This Months Installments"
name="this_months_installments"
domain="[
('next_installment_date', '>=', (context_today() - relativedelta(day=1)).strftime('%Y-%m-%d')),
('next_installment_date', '&lt;=', (context_today() + relativedelta(months=1, day=1, days=-1)).strftime('%Y-%m-%d'))]"
/>
<filter
string="Previous Month Installments"
name="last_months_installments"
domain="[
('next_installment_date', '>=', (context_today() - relativedelta(months=1, day=1)).strftime('%Y-%m-%d')),
('next_installment_date', '&lt;=', (context_today() - relativedelta(day=1, days=1)).strftime('%Y-%m-%d'))]"
/>
<filter
string="Next Installment Date"
name="groupby_next_installment_date"
domain="[]"
context="{'group_by': 'next_installment_date'}"
/>
</xpath>
</field>
</record>
<!-- Invoice Plan Lines -->
<record id="view_sale_invoice_plan_filter" model="ir.ui.view">
<field name="name">view.sale.invoice.plan.filter</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</field>
</record>
<record id="action_view_sale_make_planned_invoice" model="ir.actions.act_window">
<field name="name">Invoice Order</field>
<field name="name">Invoice Installments</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.make.planned.invoice</field>
<field name="binding_view_types">form</field>
Expand Down

0 comments on commit 5f76267

Please sign in to comment.