[IMP] website_sale_aplicoop: quantity_step multilingüe usando XML IDs de UoM. Detecta peso, volumen, longitud, superficie independiente del idioma.
This commit is contained in:
parent
92b35ccd6d
commit
464ca48127
1 changed files with 34 additions and 6 deletions
|
|
@ -416,16 +416,44 @@ class AplicoopWebsiteSale(WebsiteSale):
|
||||||
|
|
||||||
# Safety: Get UoM category name (use sudo for read-only display to avoid ACL issues)
|
# Safety: Get UoM category name (use sudo for read-only display to avoid ACL issues)
|
||||||
uom_category_name = ""
|
uom_category_name = ""
|
||||||
quantity_step = 1 # Default step for integer quantities
|
quantity_step = 1 # Default step for integer quantities (Units)
|
||||||
|
|
||||||
if product.uom_id:
|
if product.uom_id:
|
||||||
uom = product.uom_id.sudo()
|
uom = product.uom_id.sudo()
|
||||||
if uom.category_id:
|
if uom.category_id:
|
||||||
uom_category_name = uom.category_id.sudo().name or ""
|
uom_category_name = uom.category_id.sudo().name or ""
|
||||||
# Use 0.1 step for weight-based products (kg, g, etc.)
|
|
||||||
# This allows fractional quantities for bulk products
|
# Use XML IDs to detect fractional UoM categories (multilingual robust)
|
||||||
category_name_lower = uom_category_name.lower()
|
# This works regardless of translation/language
|
||||||
if "weight" in category_name_lower or "kg" in category_name_lower:
|
try:
|
||||||
quantity_step = 0.1
|
# Get external ID for the UoM category
|
||||||
|
ir_model_data = request.env["ir.model.data"].sudo()
|
||||||
|
external_id = ir_model_data.search(
|
||||||
|
[
|
||||||
|
("model", "=", "uom.category"),
|
||||||
|
("res_id", "=", uom.category_id.id),
|
||||||
|
],
|
||||||
|
limit=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
if external_id:
|
||||||
|
# Standard Odoo UoM categories requiring fractional step
|
||||||
|
fractional_categories = [
|
||||||
|
"uom.product_uom_categ_kgm", # Weight (kg, g, ton, etc.)
|
||||||
|
"uom.product_uom_categ_vol", # Volume (L, m³, etc.)
|
||||||
|
"uom.uom_categ_length", # Length/Distance (m, km, etc.)
|
||||||
|
"uom.uom_categ_surface", # Surface (m², ha, etc.)
|
||||||
|
]
|
||||||
|
full_xmlid = f"{external_id.module}.{external_id.name}"
|
||||||
|
if full_xmlid in fractional_categories:
|
||||||
|
quantity_step = 0.1
|
||||||
|
except Exception as e:
|
||||||
|
# Fallback to integer step on error
|
||||||
|
_logger.warning(
|
||||||
|
"_prepare_product_display_info: Error detecting UoM category XML ID for product %s: %s",
|
||||||
|
product.id,
|
||||||
|
str(e),
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"display_price": price_safe,
|
"display_price": price_safe,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue