From a60cced44810d708beaf8ea5a166aa554a7c852b Mon Sep 17 00:00:00 2001 From: sbel-odoo Date: Tue, 30 Jan 2024 13:21:00 +0100 Subject: [PATCH] [FIX] sale, purchase, product: show sale warning in catalog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, when adding a product to a quotation with the catalog, no warning message will appear when adding a poduct that has a warning or blocking message. Steps to reproduce: ------------------- * Go to **Sales** app -> Configuration -> Settings * Enable **Sale Warnings** * Go to **Products** -> Products * Create a new product * Under **Sales** tab: * For warning, select either warning or blocking message * Write a message * Go to **Orders** -> Quotations * Create a new quotation * Select the **Catalog** to add products * Add the newly created product Why the fix: ------------ The first version of this fix was a python exclusive change. It was a bit hacky; it was raising an error when the product had a blocking warning and sending a message on the bus when the product had a non-blocking warning. The second version was changing the return value of `_update_order_line_info` to return the price and the warning if any. The warning was shown inside JS with `_updateQuantity`. This change was not good for a stable verion as it was changing the signature of a public method. This fix automatically changes the data that is loaded to the catalog. It adds the warning message if any and changes the `readOnly` field accordingly. Warning/blocking messages will be automatically displayed in the catalog, on the product informations. Products with blocking messages will me marked as readonly to avoid being able to add the product to the sale order (this is the original behavior for blocking messages). Regarding the field `readOnly` and ẁarning`: * We can't write `res[product.id]['readOnly'] = product.sale_line_warn == "block"' because readOnly is set to True by default if the sale order is cancelled and doing this would overide that value later. See: https://github.com/odoo/odoo/blob/21c25a7ccd0ba2d6574ddbcfbcf50dbbc03a1e6c/addons/product/models/product_catalog_mixin.py#L97-L99 * We're also sending the warning only if there is one because of this: ```python You can't edit this product in the catalog. ``` Because in the case where readOnly is True for another reason than the product having a blocking warning, the initial message will be displyed. Since the module purchase also uses the warning on products, this fix is extended to include it. opw-3631511 closes odoo/odoo#149155 Signed-off-by: Valentin Chevalier Co-authored-by: Valentin Chevalier --- .../src/product_catalog/kanban_record.xml | 2 +- .../product_catalog/order_line/order_line.js | 3 ++- .../product_catalog/order_line/order_line.xml | 24 ++++++++++++++++--- addons/purchase/models/purchase_order.py | 4 ++++ addons/purchase/models/purchase_order_line.py | 4 +++- addons/sale/models/sale_order.py | 9 ++++++- addons/sale/models/sale_order_line.py | 19 +++++++++++---- 7 files changed, 53 insertions(+), 12 deletions(-) diff --git a/addons/product/static/src/product_catalog/kanban_record.xml b/addons/product/static/src/product_catalog/kanban_record.xml index 83e43d941b0..219ae519618 100644 --- a/addons/product/static/src/product_catalog/kanban_record.xml +++ b/addons/product/static/src/product_catalog/kanban_record.xml @@ -8,7 +8,7 @@ t-on-click="onGlobalClick" t-ref="root">
+ t-att-class="{'o_product_added': productCatalogData.quantity}"> diff --git a/addons/product/static/src/product_catalog/order_line/order_line.js b/addons/product/static/src/product_catalog/order_line/order_line.js index d1363221a0d..78a7de40de8 100644 --- a/addons/product/static/src/product_catalog/order_line/order_line.js +++ b/addons/product/static/src/product_catalog/order_line/order_line.js @@ -9,7 +9,8 @@ export class ProductCatalogOrderLine extends Component { quantity: Number, price: Number, readOnly: { type: Boolean, optional: true }, - } + warning: { type: String, optional: true}, + }; //-------------------------------------------------------------------------- // Private diff --git a/addons/product/static/src/product_catalog/order_line/order_line.xml b/addons/product/static/src/product_catalog/order_line/order_line.xml index ead4e0ebc8c..9571e50b90b 100644 --- a/addons/product/static/src/product_catalog/order_line/order_line.xml +++ b/addons/product/static/src/product_catalog/order_line/order_line.xml @@ -6,10 +6,19 @@ Unit price: - +
+ + +
+ You can't edit this product in the catalog. -
+
-
+ + + + +