From c398899e150535d947f9363764ac9d5a8d467297 Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Sat, 21 Dec 2024 17:31:57 +0530 Subject: [PATCH] Dec 21: [FIX] Bug Fixed 'pos_traceability_validation' --- .../models/stock_lot.py | 16 ++++---- .../static/src/js/pos_orderline.js | 39 ++++--------------- .../src/js/pos_traceability_validation.js | 14 ++----- 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/pos_traceability_validation/models/stock_lot.py b/pos_traceability_validation/models/stock_lot.py index 839242b3f..ed05a153f 100644 --- a/pos_traceability_validation/models/stock_lot.py +++ b/pos_traceability_validation/models/stock_lot.py @@ -27,9 +27,11 @@ class StockLot(models.Model): _inherit = 'stock.lot' @api.model - def validate_lots(self, lots): + def validate_lots(self, lots, pos_config_id): """ This method validates a list of lots.""" processed = [] + pos_config = self.env['pos.config'].browse(pos_config_id) + location_id = pos_config.picking_type_id.default_location_src_id.id LotObj = self.env['stock.lot'] for lot in lots: lot_id = LotObj.search([('name', '=', lot)], limit=1) @@ -38,16 +40,16 @@ class StockLot(models.Model): if lot_id.product_qty <= 0: return ['no_stock', lot] processed.append(lot) + if lot_id.location_id and lot_id.location_id.id != location_id: + return ['no_stock', lot] return True @api.model - def get_available_lots_qty_pos(self, product_id, lot_names, pos_config_id): + def get_available_lots_qty_pos(self, product_id, lot_names): """Check the max lot quantity of corresponding product.""" - pos_config = self.env['pos.config'].browse(pos_config_id) - location_id = pos_config.picking_type_id.default_location_src_id.id stock_quant = self.env['stock.lot'].search([ ('product_id', '=', product_id), - ('name', '=', lot_names), - ('location_id', '=', location_id) + ('name', 'in', lot_names) ]) - return stock_quant.product_qty + total_quantity = sum(stock_quant.mapped('product_qty')) + return total_quantity diff --git a/pos_traceability_validation/static/src/js/pos_orderline.js b/pos_traceability_validation/static/src/js/pos_orderline.js index 6b27630ec..37a3c0245 100644 --- a/pos_traceability_validation/static/src/js/pos_orderline.js +++ b/pos_traceability_validation/static/src/js/pos_orderline.js @@ -14,43 +14,20 @@ patch(Orderline.prototype, { // Checking the orderline quantity and onhand lot quantity super.set_quantity(quantity, keep_price); var lines = await this.get_lot_lines() - var pos_config_id = this.pos.config.id if(lines.length){ var product_id = this.get_product().id - var lot_name = lines.map(line => line.lot_name).pop(); + var lot_names = lines.map(line => line.lot_name); const result = await this.pos.orm.call( - "stock.lot", "get_available_lots_qty_pos", [product_id, lot_name, pos_config_id], {} + "stock.lot", "get_available_lots_qty_pos", [product_id, lot_names], {} ) - if (result != 0 && lines.length == 1) { - if (quantity > result) { - this.quantity = result; - await this.env.services.popup.add(CustomButtonPopup, { - title: _t("Exception"), - body: _t("Product quantity Exceeding the allowed lot quantity") - }); - } - } else if (result == 0) { - const order = this.pos.get_order(); - const selectedLine = order.get_selected_orderline(); - selectedLine.stock = result; - if (quantity === 1 && lines.length >= 1) { - order._unlinkOrderline(selectedLine); - } - else if (quantity >=1) { - const Length = selectedLine.pack_lot_lines.length - const LastLine = selectedLine.pack_lot_lines[Length - 1] - selectedLine.pack_lot_lines.remove(LastLine) - selectedLine.set_quantity(quantity - 1, keep_price) - } - this.env.services.popup.add(ErrorPopup, { - title: _t("No Stock Available"), - body: _t( - "The requested lot:" + lot_name + "is currently out of stock." - ), - }); + print('1111111111111', quantity, result) + if (quantity > result) { + this.quantity = result + await this.env.services.popup.add(CustomButtonPopup, { + title: _t("Exception"), + }); } - } } }); diff --git a/pos_traceability_validation/static/src/js/pos_traceability_validation.js b/pos_traceability_validation/static/src/js/pos_traceability_validation.js index fec40b13d..0d8aa7c1d 100644 --- a/pos_traceability_validation/static/src/js/pos_traceability_validation.js +++ b/pos_traceability_validation/static/src/js/pos_traceability_validation.js @@ -20,7 +20,7 @@ patch(EditListPopup.prototype, { /**Checking the lot and serial and raising the error popup**/ if (this.props.title === 'Lot/Serial Number(s) Required'){ var pos_config_id = this.pos.config.id - let product_id = this.props.id + let product_id = this.props.product var lot_string = this.state.array var lot_names = []; for (var i = 0; i < lot_string.length; i++) { @@ -28,9 +28,9 @@ patch(EditListPopup.prototype, { lot_names.push(lot_string[i].text); } } - + var pos_config_id = this.pos.config.id const result = await this.orm.call( - "stock.lot", "validate_lots", [lot_names], {} + "stock.lot", "validate_lots", [lot_names, pos_config_id], {} ) const StockStatus = this.pos.get_order()?.get_selected_orderline()?.stock if(result != true){ @@ -60,14 +60,6 @@ patch(EditListPopup.prototype, { }); } } -// else if(StockStatus === 0){ -// this.env.services.popup.add(ErrorPopup, { -// title: _t("No Stock Available"), -// body: _t( -// "The requested lot: is currently out of stock." -// ), -// }); -// } else{ this.props.resolve({ confirmed: true, payload: await this.getPayload() }); this.pos.closeTempScreen();