Browse Source

Jun 23: [FIX] Bug Fixed 'pos_restrict_product_stock'

17.0
Cybrosys Technologies 2 days ago
parent
commit
c24208ee70
  1. 2
      pos_restrict_product_stock/__manifest__.py
  2. 8
      pos_restrict_product_stock/doc/RELEASE_NOTES.md
  3. 2
      pos_restrict_product_stock/static/description/index.html
  4. 75
      pos_restrict_product_stock/static/src/js/OrderScreen.js
  5. 42
      pos_restrict_product_stock/static/src/js/ProductScreen.js
  6. 17
      pos_restrict_product_stock/static/src/js/RestrictStockPopup.js
  7. 2
      pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml

2
pos_restrict_product_stock/__manifest__.py

@ -20,7 +20,7 @@
#############################################################################
{
'name': 'Display Stock in POS | Restrict Out-of-Stock Products in POS',
'version': '17.0.2.1.2',
'version': '17.0.2.1.1',
'category': 'Point of Sale',
'summary': """Enhance your Point of Sale experience by preventing the
ordering of out-of-stock products during your session""",

8
pos_restrict_product_stock/doc/RELEASE_NOTES.md

@ -9,10 +9,4 @@
#### Version 17.0.2.1.1
#### Update
- Added a new feature that restricts stock availability when clicking the payment button.
This will help prevent the ordering of out-of-stock products, whether entered via barcode or through any other method.
#### 12.06.2025
#### Version 17.0.2.1.2
#### Update
- Fixed the issue occurring while ordering out-of-stock products
This will help prevent the ordering of out-of-stock products, whether entered via barcode or through any other method.

2
pos_restrict_product_stock/static/description/index.html

@ -358,7 +358,7 @@
style="font-weight: 500;background-color: #fff; border-radius: 4px; padding: 1rem; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);">
<div class="d-flex mb-3"
style="font-size: 0.8rem; font-weight: 500;"><span>Version
17.0.2.1.2</span><span
17.0.1.0.0</span><span
class="px-2">|</span><span
style="color: #714B67;font-weight: 600;">Released on:28th November 2023</span>
</div>

75
pos_restrict_product_stock/static/src/js/OrderScreen.js

@ -1,4 +1,4 @@
/** @odoo-module */
/** @odoo-module */
import { Order } from "@point_of_sale/app/store/models";
import { patch } from "@web/core/utils/patch";
@ -6,30 +6,51 @@ import RestrictStockPopup from "@pos_restrict_product_stock/js/RestrictStockPopu
patch(Order.prototype, {
async pay() {
var type = this.pos.config.stock_type
const pay = true
const body = []
const pro_id = false
for (const line of this.orderlines) {
if (line.pos.config.is_restrict_product && ((type == 'qty_on_hand') && (line.product.qty_available <= 0)) | ((type == 'virtual_qty') && (line.product.virtual_available <= 0)) |
((line.product.qty_available <= 0) && (line.product.virtual_available <= 0))) {
// If the product restriction is activated in the settings and quantity is out stock, it show the restrict popup.
body.push(line.product.display_name)
}
}
if (body.length > 0) { // Check if body has items
const confirmed = await this.pos.popup.add(RestrictStockPopup, {
body: body,
pro_id: pro_id
});
if (confirmed == true) {
return super.pay(); // Proceed with payment
} else {
return ;
}
} else {
return super.pay(); // No restrictions, proceed with payment
}
}
const type = this.pos.config.stock_type;
const is_restrict = this.pos.config.is_restrict_product;
const body = [];
const productQuantities = {};
})
for (const line of this.orderlines) {
const productId = line.product.id;
if (!productQuantities[productId]) {
productQuantities[productId] = {
name: line.product.display_name,
product: line.product,
total_qty: 0,
};
}
productQuantities[productId].total_qty += line.quantity;
}
for (const { product, total_qty, name } of Object.values(productQuantities)) {
if (is_restrict) {
const qty_available = product.qty_available;
const virtual_qty = product.virtual_available;
const should_restrict = (
(type === 'qty_on_hand' && total_qty > qty_available) ||
(type === 'virtual_qty' && total_qty > virtual_qty) ||
(total_qty > qty_available && total_qty > virtual_qty)
);
if (should_restrict) {
body.push(name);
}
}
}
if (body.length > 0) {
const confirmed = await this.pos.popup.add(RestrictStockPopup, {
body: body.join(', '),
pro_id: false
});
if (confirmed === true) {
return super.pay();
} else {
return;
}
}
return super.pay();
}
})

42
pos_restrict_product_stock/static/src/js/ProductScreen.js

@ -2,20 +2,40 @@
import { patch } from "@web/core/utils/patch";
import RestrictStockPopup from "@pos_restrict_product_stock/js/RestrictStockPopup"
import { PosStore } from "@point_of_sale/app/store/pos_store";
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";
import { _t } from "@web/core/l10n/translation";
patch(PosStore.prototype, {
async addProductToCurrentOrder(...args) {
var type = this.config.stock_type
if (this.config.is_restrict_product && ((type == 'qty_on_hand') && (args['0'].qty_available <= 0)) | ((type == 'virtual_qty') && (args['0'].virtual_available <= 0)) |
((args['0'].qty_available <= 0) && (args['0'].virtual_available <= 0))) {
// If the product restriction is activated in the settings and quantity is out stock, it show the restrict popup.
this.popup.add(RestrictStockPopup, {
body: args['0'].display_name,
pro_id: args['0'].id
});
const product = args[0];
const type = this.config.stock_type;
const order = this.get_order();
const selected_orderline = order.get_selected_orderline();
let order_quantity = 1;
if (selected_orderline && selected_orderline.product.id === product.id) {
order_quantity = selected_orderline.quantity + 1;
}
else{
await super.addProductToCurrentOrder(...args)
const qty_available = product.qty_available;
const virtual_qty = product.virtual_available;
const should_restrict =
this.config.is_restrict_product &&
(
(type === 'qty_on_hand' && order_quantity > qty_available) ||
(type === 'virtual_qty' && order_quantity > virtual_qty) ||
(order_quantity > qty_available && order_quantity > virtual_qty)
);
if (should_restrict) {
const confirmed = this.popup.add(RestrictStockPopup, {
body: product.display_name,
pro_id: product.id,
});
} else {
await super.addProductToCurrentOrder(...args);
}
},
});
});

17
pos_restrict_product_stock/static/src/js/RestrictStockPopup.js

@ -5,16 +5,17 @@
import { AbstractAwaitablePopup } from "@point_of_sale/app/popup/abstract_awaitable_popup";
class RestrictStockPopup extends AbstractAwaitablePopup {
_OrderProduct() {
// On clicking order product button on popup, it will add product to orderline
if(this.props.pro_id){
var product = this.env.services.pos.db.get_product_by_id(this.props.pro_id)
product.order_status = true
this.env.services.pos.selectedOrder.add_product(product);
}
this.props.resolve(true);
this.cancel();
}
if(this.props.pro_id){
var product = this.env.services.pos.db.get_product_by_id(this.props.pro_id)
product.order_status = true
this.env.services.pos.selectedOrder.add_product(product);
}
this.props.resolve(true);
this.props.close();
}
}
RestrictStockPopup.template = 'RestrictStockPopup';
export default RestrictStockPopup;

2
pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml

@ -23,4 +23,4 @@
</div>
</div>
</t>
</template>
</template>

Loading…
Cancel
Save