From 7510dc477d093ccf164ba6ad821436c58ffeca0f Mon Sep 17 00:00:00 2001
From: jbw-odoo
Date: Mon, 16 Jan 2023 08:33:55 +0000
Subject: [PATCH] [IMP] sale: alert if draft inv on make invoice wizard
Show alert on make invoice wizard if any invoice is still in draft state as draft invoices (and downpayments) will be taken into account into the computing of the amount when creating a new invoice
Task: 2678531
Part-of: odoo/odoo#105177
---
addons/sale/wizard/sale_make_invoice_advance.py | 11 +++++++++++
.../sale/wizard/sale_make_invoice_advance_views.xml | 4 ++++
2 files changed, 15 insertions(+)
diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py
index 0656143df1e..7dc24060f5f 100644
--- a/addons/sale/wizard/sale_make_invoice_advance.py
+++ b/addons/sale/wizard/sale_make_invoice_advance.py
@@ -69,6 +69,9 @@ class SaleAdvancePaymentInv(models.TransientModel):
domain=[('type_tax_use', '=', 'sale')],
help="Taxes used for deposits")
+ # UI
+ display_draft_invoice_warning = fields.Boolean(compute="_compute_display_draft_invoice_warning")
+
#=== COMPUTE METHODS ===#
@api.depends('sale_order_ids')
@@ -106,6 +109,14 @@ class SaleAdvancePaymentInv(models.TransientModel):
if wizard.count == 1:
wizard.product_id = wizard.company_id.sale_down_payment_product_id
+ @api.depends('sale_order_ids', 'advance_payment_method', 'deduct_down_payments')
+ def _compute_display_draft_invoice_warning(self):
+ for wizard in self:
+ wizard.display_draft_invoice_warning = (
+ wizard.advance_payment_method == 'delivered' and
+ any(aml.parent_state == 'draft' for aml in wizard.sale_order_ids.order_line.invoice_lines)
+ )
+
#=== ONCHANGE METHODS ===#
@api.onchange('advance_payment_method')
diff --git a/addons/sale/wizard/sale_make_invoice_advance_views.xml b/addons/sale/wizard/sale_make_invoice_advance_views.xml
index 48a58c4742e..afaf09f4d51 100644
--- a/addons/sale/wizard/sale_make_invoice_advance_views.xml
+++ b/addons/sale/wizard/sale_make_invoice_advance_views.xml
@@ -10,6 +10,10 @@
Invoices will be created in draft so that you can review
them before validation.
+
+
+ The new invoice will deduct draft invoices linked to this sale order.
+