[fix] Current stock qty calculation in case of different UOM

This commit is contained in:
Faris Ansari 2018-04-30 15:44:49 +05:30
parent 6bc500bffa
commit 30304e68ff

View File

@ -120,8 +120,13 @@ def validate_quantity(doc, args, ref, valid_items, already_returned_items):
for column in fields: for column in fields:
returned_qty = flt(already_returned_data.get(column, 0)) if len(already_returned_data) > 0 else 0 returned_qty = flt(already_returned_data.get(column, 0)) if len(already_returned_data) > 0 else 0
reference_qty = (ref.get(column) if column == 'stock_qty'
else ref.get(column) * ref.get("conversion_factor", 1.0)) if column == 'stock_qty':
reference_qty = ref.get(column)
current_stock_qty = args.get(column)
else:
reference_qty = ref.get(column) * ref.get("conversion_factor", 1.0)
current_stock_qty = args.get(column) * args.get("conversion_factor", 1.0)
max_returnable_qty = flt(reference_qty) - returned_qty max_returnable_qty = flt(reference_qty) - returned_qty
label = column.replace('_', ' ').title() label = column.replace('_', ' ').title()
@ -132,7 +137,7 @@ def validate_quantity(doc, args, ref, valid_items, already_returned_items):
elif returned_qty >= reference_qty and args.get(column): elif returned_qty >= reference_qty and args.get(column):
frappe.throw(_("Item {0} has already been returned") frappe.throw(_("Item {0} has already been returned")
.format(args.item_code), StockOverReturnError) .format(args.item_code), StockOverReturnError)
elif (abs(args.get(column)) * args.get("conversion_factor", 1.0)) > max_returnable_qty: elif abs(current_stock_qty) > max_returnable_qty:
frappe.throw(_("Row # {0}: Cannot return more than {1} for Item {2}") frappe.throw(_("Row # {0}: Cannot return more than {1} for Item {2}")
.format(args.idx, reference_qty, args.item_code), StockOverReturnError) .format(args.idx, reference_qty, args.item_code), StockOverReturnError)