Browse Source

Oct 06: [FIX] Bug fixed 'pos_restrict_product_stock'

pull/309/merge
Risvana Cybro 1 week ago
parent
commit
ddd15735fa
  1. 16
      pos_restrict_product_stock/models/pos_session.py
  2. 2
      pos_restrict_product_stock/static/src/js/OrderScreen.js
  3. 2
      pos_restrict_product_stock/static/src/js/ProductScreen.js
  4. 4
      pos_restrict_product_stock/static/src/xml/ProductItem.xml

16
pos_restrict_product_stock/models/pos_session.py

@ -33,4 +33,20 @@ class PosSession(models.Model):
result = super()._loader_params_product_product()
result['search_params']['fields'].append('qty_available')
result['search_params']['fields'].append('virtual_available')
# ❌ DO NOT add pos_stock_qty here (not a real field)
return result
def _get_pos_ui_product_product(self, params):
"""Inject warehouse-specific stock"""
products = super()._get_pos_ui_product_product(params)
pos_location = self.config_id.picking_type_id.default_location_src_id or \
self.config_id.picking_type_id.warehouse_id.lot_stock_id
for product in products:
product_id = product['id']
product_record = self.env['product.product'].browse(product_id)
product['pos_stock_qty'] = product_record.with_context(
location=pos_location.id,
compute_child=True
).qty_available
return products

2
pos_restrict_product_stock/static/src/js/OrderScreen.js

@ -25,7 +25,7 @@ patch(Order.prototype, {
for (const { product, total_qty, name } of Object.values(productQuantities)) {
if (is_restrict) {
const qty_available = product.qty_available;
const qty_available = product.pos_stock_qty ?? product.qty_available;
const virtual_qty = product.virtual_available;
const should_restrict = (

2
pos_restrict_product_stock/static/src/js/ProductScreen.js

@ -17,7 +17,7 @@ patch(PosStore.prototype, {
order_quantity = selected_orderline.quantity + 1;
}
const qty_available = product.qty_available;
const qty_available = product.pos_stock_qty ?? product.qty_available;
const virtual_qty = product.virtual_available;
const should_restrict =

4
pos_restrict_product_stock/static/src/xml/ProductItem.xml

@ -9,7 +9,7 @@
<t t-if="this.env.services.pos.config.is_display_stock">
<t t-if="this.env.services.pos.config.stock_type == 'qty_on_hand'">
<div id="qty_display" t-attf-class="display_qty #{this.env.services.pos.db.product_by_id[props.productId].qty_available lte 0 ? 'not-available' : ''}">
<t t-esc="this.env.services.pos.db.product_by_id[props.productId].qty_available"/>
<t t-esc="this.env.services.pos.db.product_by_id[props.productId].pos_stock_qty"/>
</div>
</t>
@ -20,7 +20,7 @@
</t>
<t t-if="this.env.services.pos.config.stock_type == 'both'">
<div id="qty_display" t-attf-class="display_qty #{this.env.services.pos.db.product_by_id[props.productId].qty_available lte 0 ? 'not-available' : ''}">
<t t-esc="this.env.services.pos.db.product_by_id[props.productId].qty_available"/>
<t t-esc="this.env.services.pos.db.product_by_id[props.productId].pos_stock_qty"/>
</div>
<div t-attf-class="display_virtual #{this.env.services.pos.db.product_by_id[props.productId].virtual_available 0 ? 'not-available':''}">
<t t-esc="this.env.services.pos.db.product_by_id[props.productId].virtual_available"/>

Loading…
Cancel
Save