From e1d026d2b870704d2edd1c82c8d908f3cbbbe4e7 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 2 Nov 2020 17:52:08 +0100 Subject: [PATCH] sale_confirm_warning: add sale_warn --- sale_confirm_wizard/__manifest__.py | 2 ++ sale_confirm_wizard/wizard/sale_confirm.py | 16 +++++++++++++++- sale_confirm_wizard/wizard/sale_confirm_view.xml | 9 ++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/sale_confirm_wizard/__manifest__.py b/sale_confirm_wizard/__manifest__.py index eeb563f..453e6f1 100644 --- a/sale_confirm_wizard/__manifest__.py +++ b/sale_confirm_wizard/__manifest__.py @@ -19,6 +19,8 @@ When you confirm a quotation, Odoo will open a small wizard where you will be ab * invoicing address, * payment terms. +It will also display the sale warning if the customer's company has one. And it is a blocker warning, the user won't be able to confirm the quotation. + This module has been developped because the experience has shown, when a sales assistant confirms a quotation in Odoo, it overlooks the important information written in the customer PO that may be different from the information of the quotation in Odoo, which causes many errors in delivery and invoicing. This module has been written by Alexis de Lattre from Akretion diff --git a/sale_confirm_wizard/wizard/sale_confirm.py b/sale_confirm_wizard/wizard/sale_confirm.py index e9d1c8e..0821700 100644 --- a/sale_confirm_wizard/wizard/sale_confirm.py +++ b/sale_confirm_wizard/wizard/sale_confirm.py @@ -2,7 +2,9 @@ # © 2017 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import models, fields, api, _ +from odoo.exceptions import UserError +from odoo.addons.base.res.res_partner import WARNING_MESSAGE class SaleConfirm(models.TransientModel): @@ -24,15 +26,21 @@ class SaleConfirm(models.TransientModel): show_partner_shipping_id = fields.Many2one( related='partner_shipping_id', readonly=True, string='Detailed Delivery Address') + sale_warn = fields.Selection( + WARNING_MESSAGE, 'Sale Warning Type', readonly=True) + sale_warn_msg = fields.Text(string='Sale Warning Message', readonly=True) @api.model def _prepare_default_get(self, order): + partner = order.partner_id.commercial_partner_id default = { 'sale_id': order.id, 'client_order_ref': order.client_order_ref, 'payment_term_id': order.payment_term_id.id or False, 'partner_invoice_id': order.partner_invoice_id.id, 'partner_shipping_id': order.partner_shipping_id.id, + 'sale_warn_msg': partner.sale_warn_msg, + 'sale_warn': partner.sale_warn, } return default @@ -59,6 +67,12 @@ class SaleConfirm(models.TransientModel): @api.multi def confirm(self): self.ensure_one() + partner = self.sale_id.partner_id.commercial_partner_id + if partner.sale_warn == 'block': + raise UserError(_( + "You cannot confirm this quotation because " + "customer '%s' has a blocker sale warning:\n\n%s") + % (partner.display_name, partner.sale_warn_msg)) vals = self._prepare_update_so() self.sale_id.write(vals) # confirm sale order diff --git a/sale_confirm_wizard/wizard/sale_confirm_view.xml b/sale_confirm_wizard/wizard/sale_confirm_view.xml index 97d02e9..24b3d15 100644 --- a/sale_confirm_wizard/wizard/sale_confirm_view.xml +++ b/sale_confirm_wizard/wizard/sale_confirm_view.xml @@ -12,8 +12,12 @@

At this stage, you have received the Purchase Order from the customer and you are about to convert the related quotation to an order.

+ + + + - + @@ -32,8 +36,7 @@