Browse Source

Jun 23: [FIX] Bug Fixed 'pos_restrict_product_stock'

17.0
Cybrosys Technologies 4 days ago
parent
commit
c24208ee70
  1. 2
      pos_restrict_product_stock/__manifest__.py
  2. 6
      pos_restrict_product_stock/doc/RELEASE_NOTES.md
  3. 2
      pos_restrict_product_stock/static/description/index.html
  4. 59
      pos_restrict_product_stock/static/src/js/OrderScreen.js
  5. 40
      pos_restrict_product_stock/static/src/js/ProductScreen.js
  6. 3
      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', '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', 'category': 'Point of Sale',
'summary': """Enhance your Point of Sale experience by preventing the 'summary': """Enhance your Point of Sale experience by preventing the
ordering of out-of-stock products during your session""", ordering of out-of-stock products during your session""",

6
pos_restrict_product_stock/doc/RELEASE_NOTES.md

@ -10,9 +10,3 @@
#### Update #### Update
- Added a new feature that restricts stock availability when clicking the payment button. - 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. 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

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);"> 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" <div class="d-flex mb-3"
style="font-size: 0.8rem; font-weight: 500;"><span>Version 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 class="px-2">|</span><span
style="color: #714B67;font-weight: 600;">Released on:28th November 2023</span> style="color: #714B67;font-weight: 600;">Released on:28th November 2023</span>
</div> </div>

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

40
pos_restrict_product_stock/static/src/js/ProductScreen.js

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

3
pos_restrict_product_stock/static/src/js/RestrictStockPopup.js

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

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

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

Loading…
Cancel
Save