From 64104efa278d2f8ec30e3c176cf8b3b8139d4a96 Mon Sep 17 00:00:00 2001 From: cbeddies Date: Wed, 13 Dec 2023 09:21:01 -0500 Subject: [PATCH] [IMP] sale_invoice_plan: usability - filter to invoice --- sale_invoice_plan/models/sale.py | 47 ++++++++++++++++- sale_invoice_plan/views/sale_view.xml | 51 +++++++++++++++++++ .../wizard/sale_make_planned_invoice_view.xml | 2 +- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/sale_invoice_plan/models/sale.py b/sale_invoice_plan/models/sale.py index 21e2aad54d96..384940958a58 100644 --- a/sale_invoice_plan/models/sale.py +++ b/sale_invoice_plan/models/sale.py @@ -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 diff --git a/sale_invoice_plan/views/sale_view.xml b/sale_invoice_plan/views/sale_view.xml index 869303e55244..e9d09eed0695 100644 --- a/sale_invoice_plan/views/sale_view.xml +++ b/sale_invoice_plan/views/sale_view.xml @@ -121,6 +121,57 @@ + + view.order.tree.invoice.plan + sale.order + + + + + + + + + + + view.order.search.invoice.plan + sale.order + + + + + + + + + + + view.sale.invoice.plan.filter diff --git a/sale_invoice_plan/wizard/sale_make_planned_invoice_view.xml b/sale_invoice_plan/wizard/sale_make_planned_invoice_view.xml index 652d5e084a2a..dde644c247f5 100644 --- a/sale_invoice_plan/wizard/sale_make_planned_invoice_view.xml +++ b/sale_invoice_plan/wizard/sale_make_planned_invoice_view.xml @@ -27,7 +27,7 @@ - Invoice Order + Invoice Installments ir.actions.act_window sale.make.planned.invoice form