From 32b9c4a585ffd492c9eeb11c1ea226b72a968e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Thu, 12 Mar 2020 15:52:48 +0000 Subject: [PATCH] [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 --- addons/sale/models/sale.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 0440dfcaf51..65d5fda54c7 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -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: