Browse Source

Dec 21: [FIX] Bug Fixed 'pos_traceability_validation'

pull/309/head
Cybrosys Technologies 4 months ago
parent
commit
c398899e15
  1. 16
      pos_traceability_validation/models/stock_lot.py
  2. 39
      pos_traceability_validation/static/src/js/pos_orderline.js
  3. 14
      pos_traceability_validation/static/src/js/pos_traceability_validation.js

16
pos_traceability_validation/models/stock_lot.py

@ -27,9 +27,11 @@ class StockLot(models.Model):
_inherit = 'stock.lot' _inherit = 'stock.lot'
@api.model @api.model
def validate_lots(self, lots): def validate_lots(self, lots, pos_config_id):
""" This method validates a list of lots.""" """ This method validates a list of lots."""
processed = [] 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'] LotObj = self.env['stock.lot']
for lot in lots: for lot in lots:
lot_id = LotObj.search([('name', '=', lot)], limit=1) lot_id = LotObj.search([('name', '=', lot)], limit=1)
@ -38,16 +40,16 @@ class StockLot(models.Model):
if lot_id.product_qty <= 0: if lot_id.product_qty <= 0:
return ['no_stock', lot] return ['no_stock', lot]
processed.append(lot) processed.append(lot)
if lot_id.location_id and lot_id.location_id.id != location_id:
return ['no_stock', lot]
return True return True
@api.model @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.""" """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([ stock_quant = self.env['stock.lot'].search([
('product_id', '=', product_id), ('product_id', '=', product_id),
('name', '=', lot_names), ('name', 'in', lot_names)
('location_id', '=', location_id)
]) ])
return stock_quant.product_qty total_quantity = sum(stock_quant.mapped('product_qty'))
return total_quantity

39
pos_traceability_validation/static/src/js/pos_orderline.js

@ -14,43 +14,20 @@ patch(Orderline.prototype, {
// Checking the orderline quantity and onhand lot quantity // Checking the orderline quantity and onhand lot quantity
super.set_quantity(quantity, keep_price); super.set_quantity(quantity, keep_price);
var lines = await this.get_lot_lines() var lines = await this.get_lot_lines()
var pos_config_id = this.pos.config.id
if(lines.length){ if(lines.length){
var product_id = this.get_product().id 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( 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) { print('1111111111111', quantity, result)
if (quantity > result) { if (quantity > result) {
this.quantity = result; this.quantity = result
await this.env.services.popup.add(CustomButtonPopup, { await this.env.services.popup.add(CustomButtonPopup, {
title: _t("Exception"), 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."
),
});
} }
} }
} }
}); });

14
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**/ /**Checking the lot and serial and raising the error popup**/
if (this.props.title === 'Lot/Serial Number(s) Required'){ if (this.props.title === 'Lot/Serial Number(s) Required'){
var pos_config_id = this.pos.config.id 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_string = this.state.array
var lot_names = []; var lot_names = [];
for (var i = 0; i < lot_string.length; i++) { for (var i = 0; i < lot_string.length; i++) {
@ -28,9 +28,9 @@ patch(EditListPopup.prototype, {
lot_names.push(lot_string[i].text); lot_names.push(lot_string[i].text);
} }
} }
var pos_config_id = this.pos.config.id
const result = await this.orm.call( 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 const StockStatus = this.pos.get_order()?.get_selected_orderline()?.stock
if(result != true){ 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{ else{
this.props.resolve({ confirmed: true, payload: await this.getPayload() }); this.props.resolve({ confirmed: true, payload: await this.getPayload() });
this.pos.closeTempScreen(); this.pos.closeTempScreen();

Loading…
Cancel
Save