[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) <xbo@odoo.com>
This commit is contained in:
Bastien (bvdn)
2024-04-10 08:17:47 +00:00
parent b4d70e34f2
commit 079cc8b10a
5 changed files with 17 additions and 5 deletions
+10 -2
View File
@@ -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)
@@ -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},
};
+4 -1
View File
@@ -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'])
+1 -1
View File
@@ -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:
@@ -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 &&