[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
This commit is contained in:
jbw-odoo
2023-02-14 13:13:47 +01:00
parent bae9382896
commit 7510dc477d
2 changed files with 15 additions and 0 deletions
@@ -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')
@@ -10,6 +10,10 @@
Invoices will be created in draft so that you can review
them before validation.
</p>
<field name="display_draft_invoice_warning" invisible="1"/>
<p class="alert alert-warning" role="alert" attrs="{'invisible': [('display_draft_invoice_warning', '=', False)]}">
The new invoice will deduct draft invoices linked to this sale order.
</p>
<group>
<field name="sale_order_ids" invisible="1"/>
<field name="has_down_payments" invisible="1"/>