[IMP] sale, sale_stock: Raise better error message
Purpose ======= If a user try to create an invoice without any "invoiceable lines"; an error is raised. The error message does not explain what to do to fix the error. Specification ============= Explain in the error message what actions the user could do to fix the issue. Task 2159161
This commit is contained in:
committed by
Lucas Lefèvre
parent
4511098d19
commit
32b9c4a585
@@ -603,6 +603,15 @@ class SaleOrder(models.Model):
|
||||
def _get_invoice_grouping_keys(self):
|
||||
return ['company_id', 'partner_id', 'currency_id']
|
||||
|
||||
@api.model
|
||||
def _nothing_to_invoice_error(self):
|
||||
msg = _("""There is nothing to invoice!\n
|
||||
Reason(s) of this behavior could be:
|
||||
- You should deliver your products before invoicing them: Click on the "truck" icon (top-right of your screen) and follow instructions.
|
||||
- You should modify the invoicing policy of your product: Open the product, go to the "Sales tab" and modify invoicing policy from "delivered quantities" to "ordered quantities".
|
||||
""")
|
||||
return UserError(msg)
|
||||
|
||||
def _create_invoices(self, grouped=False, final=False, date=None):
|
||||
"""
|
||||
Create the invoice associated to the SO.
|
||||
@@ -642,13 +651,12 @@ class SaleOrder(models.Model):
|
||||
invoice_vals['invoice_line_ids'].append((0, 0, line._prepare_invoice_line()))
|
||||
|
||||
if not invoice_vals['invoice_line_ids']:
|
||||
raise UserError(_('There is no invoiceable line. If a product has a Delivered quantities invoicing policy, please make sure that a quantity has been delivered.'))
|
||||
raise self._nothing_to_invoice_error()
|
||||
|
||||
invoice_vals_list.append(invoice_vals)
|
||||
|
||||
if not invoice_vals_list:
|
||||
raise UserError(_(
|
||||
'There is no invoiceable line. If a product has a Delivered quantities invoicing policy, please make sure that a quantity has been delivered.'))
|
||||
raise self._nothing_to_invoice_error()
|
||||
|
||||
# 2) Manage 'grouped' parameter: group by (partner_id, currency_id).
|
||||
if not grouped:
|
||||
|
||||
Reference in New Issue
Block a user