[IMP] point_of_sale: handle products tracked as lots
The POS support for tracked products implemented at
8f39c652c6 was mainly meant for products
tracked with serial numbers. In theory it would also work for lots as
long as the lots were only sold in integer quantities. One could specify
the same lot multiple times.
For products tracked in non-integer quantities this wouldn't work
however. This commit makes the POS handle lots more like the stock
module. When a product tracked in lots is bought in the POS you can only
specify one lot number. If a product is sold from multiple lots then
multiple order lines have to be specified.
Fixes #15325
This commit is contained in:
committed by
Josse Colpaert
parent
76852a2fad
commit
025d9432a1
@@ -654,7 +654,8 @@ class PosOrder(models.Model):
|
||||
stock_production_lot = StockProductionLot.search([('name', '=', lot_name), ('product_id', '=', pack_operation.product_id.id)])
|
||||
if stock_production_lot:
|
||||
if stock_production_lot.product_id.tracking == 'lot':
|
||||
qty = pack_lot_names.count(lot_name)
|
||||
# if a lot nr is set through the frontend it will refer to the full quantity
|
||||
qty = pack_operation.product_qty
|
||||
else:
|
||||
qty = 1.0
|
||||
qty_done += qty
|
||||
|
||||
@@ -1282,16 +1282,28 @@ exports.Orderline = Backbone.Model.extend({
|
||||
}
|
||||
},
|
||||
|
||||
get_required_number_of_lots: function(){
|
||||
var lots_required = 1;
|
||||
|
||||
if (this.product.tracking == 'serial') {
|
||||
lots_required = this.quantity;
|
||||
}
|
||||
|
||||
return lots_required;
|
||||
},
|
||||
|
||||
compute_lot_lines: function(){
|
||||
var pack_lot_lines = this.pack_lot_lines;
|
||||
var lines = pack_lot_lines.length;
|
||||
if(this.quantity > lines){
|
||||
for(var i=0; i<this.quantity - lines; i++){
|
||||
var lots_required = this.get_required_number_of_lots();
|
||||
|
||||
if(lots_required > lines){
|
||||
for(var i=0; i<lots_required - lines; i++){
|
||||
pack_lot_lines.add(new exports.Packlotline({}, {'order_line': this}));
|
||||
}
|
||||
}
|
||||
if(this.quantity < lines){
|
||||
var to_remove = lines - this.quantity;
|
||||
if(lots_required < lines){
|
||||
var to_remove = lines - lots_required;
|
||||
var lot_lines = pack_lot_lines.sortBy('lot_name').slice(0, to_remove);
|
||||
pack_lot_lines.remove(lot_lines);
|
||||
}
|
||||
@@ -1303,7 +1315,7 @@ exports.Orderline = Backbone.Model.extend({
|
||||
return true;
|
||||
}
|
||||
var valid_product_lot = this.pack_lot_lines.get_valid_lots();
|
||||
return this.quantity === valid_product_lot.length;
|
||||
return this.get_required_number_of_lots() === valid_product_lot.length;
|
||||
},
|
||||
|
||||
// return the unit of measure of the product
|
||||
@@ -1344,6 +1356,8 @@ exports.Orderline = Backbone.Model.extend({
|
||||
return false;
|
||||
}else if(this.price !== orderline.price){
|
||||
return false;
|
||||
}else if(this.product.tracking == 'lot') {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
@@ -1665,8 +1679,10 @@ var PacklotlineCollection = Backbone.Collection.extend({
|
||||
},
|
||||
|
||||
set_quantity_by_lot: function() {
|
||||
var valid_lots = this.get_valid_lots();
|
||||
this.order_line.set_quantity(valid_lots.length);
|
||||
if (this.order_line.product.tracking == 'serial') {
|
||||
var valid_lots = this.get_valid_lots();
|
||||
this.order_line.set_quantity(valid_lots.length);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2135,7 +2151,8 @@ exports.Order = Backbone.Model.extend({
|
||||
this.pos.gui.show_popup('packlotline', {
|
||||
'title': _t('Lot/Serial Number(s) Required'),
|
||||
'pack_lot_lines': pack_lot_lines,
|
||||
'order': this
|
||||
'order_line': order_line,
|
||||
'order': this,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -223,11 +223,12 @@ var PackLotLinePopupWidget = PopupWidget.extend({
|
||||
pack_lot_lines.remove_empty_model();
|
||||
pack_lot_lines.set_quantity_by_lot();
|
||||
this.options.order.save_to_db();
|
||||
this.options.order_line.trigger('change', this.options.order_line);
|
||||
this.gui.close_popup();
|
||||
},
|
||||
|
||||
add_lot: function(ev) {
|
||||
if (ev.keyCode === $.ui.keyCode.ENTER){
|
||||
if (ev.keyCode === $.ui.keyCode.ENTER && this.options.order_line.product.tracking == 'serial'){
|
||||
var pack_lot_lines = this.options.pack_lot_lines,
|
||||
$input = $(ev.target),
|
||||
cid = $input.attr('cid'),
|
||||
|
||||
Reference in New Issue
Block a user