From 079cc8b10a044b79af5ee6f14018c6b9aa9290bd Mon Sep 17 00:00:00 2001 From: "Bastien (bvdn)" Date: Thu, 28 Mar 2024 10:21:24 +0100 Subject: [PATCH] [FIX] product,purchase,sale_* : add product type to catalog product props The sale_stock module patches the ProductCatalogKanbanRecord updateQuantity method to prevent the quantity to go under the delivered quantity of the product The issue is that we are also using the ProductCatalogKanbanRecord in the industry_fsm_stock module in which the services product added to the sale order are considered by default but we would like to be able to dimish their quantity in the catalog (in case of a missclick for exemple) Since the service product can't be considered delivered in sale modules, the condition in updateQuantity shouldn't change anything Task-3689939 closes odoo/odoo#155157 Related: odoo/enterprise#55455 Signed-off-by: Xavier Bol (xbo) --- addons/product/models/product_catalog_mixin.py | 12 ++++++++++-- .../src/product_catalog/order_line/order_line.js | 1 + addons/purchase/models/purchase_order.py | 5 ++++- addons/sale/models/sale_order.py | 2 +- .../static/src/product_catalog/kanban_record.js | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/addons/product/models/product_catalog_mixin.py b/addons/product/models/product_catalog_mixin.py index 95a372364d7..f8bc7b97d8f 100644 --- a/addons/product/models/product_catalog_mixin.py +++ b/addons/product/models/product_catalog_mixin.py @@ -66,11 +66,15 @@ class ProductCatalogMixin(models.AbstractModel): { 'productId': int 'quantity': float (optional) + 'productType': string 'price': float 'readOnly': bool (optional) } """ - return {} + res = {} + for product in products: + res[product.id] = {'productType': product.type} + return res def _get_product_catalog_order_line_info(self, product_ids, **kwargs): """ Returns products information to be shown in the catalog. @@ -82,6 +86,7 @@ class ProductCatalogMixin(models.AbstractModel): { 'productId': int 'quantity': float (optional) + 'productType': string 'price': float 'readOnly': bool (optional) } @@ -90,7 +95,10 @@ class ProductCatalogMixin(models.AbstractModel): default_data = self._default_order_line_values() for product, record_lines in self._get_product_catalog_record_lines(product_ids).items(): - order_line_info[product.id] = record_lines._get_product_catalog_lines_data(**kwargs) + order_line_info[product.id] = { + **record_lines._get_product_catalog_lines_data(parent_record=self, **kwargs), + 'productType': product.type, + } product_ids.remove(product.id) products = self.env['product.product'].browse(product_ids) 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 78a7de40de8..bfc654d9e9f 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 @@ -8,6 +8,7 @@ export class ProductCatalogOrderLine extends Component { productId: Number, quantity: Number, price: Number, + productType: String, readOnly: { type: Boolean, optional: true }, warning: { type: String, optional: true}, }; diff --git a/addons/purchase/models/purchase_order.py b/addons/purchase/models/purchase_order.py index b2575eb2888..585fe772d41 100644 --- a/addons/purchase/models/purchase_order.py +++ b/addons/purchase/models/purchase_order.py @@ -844,7 +844,10 @@ class PurchaseOrder(models.Model): return expression.AND([super()._get_product_catalog_domain(), [('purchase_ok', '=', True)]]) def _get_product_catalog_order_data(self, products, **kwargs): - return {product.id: self._get_product_price_and_data(product) for product in products} + res = super()._get_product_catalog_order_data(products, **kwargs) + for product in products: + res[product.id] += self._get_product_price_and_data(product) + return res def _get_product_catalog_record_lines(self, product_ids): grouped_lines = defaultdict(lambda: self.env['purchase.order.line']) diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 984a5d564f1..9401f5e91f3 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -1822,7 +1822,7 @@ class SaleOrder(models.Model): date=self.date_order, **kwargs, ) - res = {} + res = super()._get_product_catalog_order_data(products, **kwargs) for product in products: res[product.id] = {'price': pricelist.get(product.id)} if product.sale_line_warn != 'no-message' and product.sale_line_warn_msg: diff --git a/addons/sale_stock/static/src/product_catalog/kanban_record.js b/addons/sale_stock/static/src/product_catalog/kanban_record.js index d26957b01c7..d750f393c9a 100644 --- a/addons/sale_stock/static/src/product_catalog/kanban_record.js +++ b/addons/sale_stock/static/src/product_catalog/kanban_record.js @@ -5,7 +5,7 @@ import { patch } from "@web/core/utils/patch"; patch(ProductCatalogKanbanRecord.prototype, { updateQuantity(quantity) { - if (this.env.orderResModel !== "sale.order") { + if (this.env.orderResModel !== "sale.order" || this.productCatalogData.productType == "service") { super.updateQuantity(...arguments); } else if ( this.productCatalogData.quantity === this.productCatalogData.deliveredQty &&