[FIX] website_sale_aplicoop: Calculate UoM quantity step server-side for portal users
Portal users cannot read uom.uom model due to ACL restrictions (1,0,0,0 permissions). This caused products sold by weight (kg) to have incorrect quantity step (1 instead of 0.1). Solution: - Calculate quantity_step in Python controller using product.uom_id.sudo() - Check if UoM category contains 'weight' or 'kg' -> use step=0.1 - For other products, use default step=1 - Pass quantity_step to template via product_display_info dict - Update XML input attributes (value, min, step) to use dynamic quantity_step This maintains proper UX for bulk products while respecting security permissions.
This commit is contained in:
parent
ed8c6acd92
commit
f35bf0c5a1
2 changed files with 15 additions and 3 deletions
|
|
@ -416,14 +416,21 @@ 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
|
||||||
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
|
||||||
|
category_name_lower = uom_category_name.lower()
|
||||||
|
if "weight" in category_name_lower or "kg" in category_name_lower:
|
||||||
|
quantity_step = 0.1
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"display_price": price_safe,
|
"display_price": price_safe,
|
||||||
"safe_uom_category": uom_category_name,
|
"safe_uom_category": uom_category_name,
|
||||||
|
"quantity_step": quantity_step,
|
||||||
}
|
}
|
||||||
|
|
||||||
def _compute_price_info(self, products, pricelist):
|
def _compute_price_info(self, products, pricelist):
|
||||||
|
|
|
||||||
|
|
@ -1225,6 +1225,10 @@
|
||||||
t-set="safe_uom_category"
|
t-set="safe_uom_category"
|
||||||
t-value="product_display_info.get(product.id, {}).get('safe_uom_category', '')"
|
t-value="product_display_info.get(product.id, {}).get('safe_uom_category', '')"
|
||||||
/>
|
/>
|
||||||
|
<t
|
||||||
|
t-set="quantity_step"
|
||||||
|
t-value="product_display_info.get(product.id, {}).get('quantity_step', 1)"
|
||||||
|
/>
|
||||||
<t
|
<t
|
||||||
t-set="order_id_safe"
|
t-set="order_id_safe"
|
||||||
t-value="group_order.id if group_order else ''"
|
t-value="group_order.id if group_order else ''"
|
||||||
|
|
@ -1236,6 +1240,7 @@
|
||||||
t-attf-data-product-name="{{ product.name }}"
|
t-attf-data-product-name="{{ product.name }}"
|
||||||
t-attf-data-product-price="{{ display_price }}"
|
t-attf-data-product-price="{{ display_price }}"
|
||||||
t-attf-data-uom-category="{{ safe_uom_category }}"
|
t-attf-data-uom-category="{{ safe_uom_category }}"
|
||||||
|
t-attf-data-quantity-step="{{ quantity_step }}"
|
||||||
>
|
>
|
||||||
<div class="qty-control">
|
<div class="qty-control">
|
||||||
<label
|
<label
|
||||||
|
|
@ -1259,9 +1264,9 @@
|
||||||
t-attf-id="qty_{{ product.id }}"
|
t-attf-id="qty_{{ product.id }}"
|
||||||
class="product-qty"
|
class="product-qty"
|
||||||
name="quantity"
|
name="quantity"
|
||||||
value="1"
|
t-attf-value="1"
|
||||||
min="1"
|
t-attf-min="{{ quantity_step }}"
|
||||||
step="1"
|
t-attf-step="{{ quantity_step }}"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="qty-increase"
|
class="qty-increase"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue