Fix how some "receive row" logic worked, for aggregated product rows
also fix the batch invoice total aggregation, hopefully
This commit is contained in:
parent
7b4d418177
commit
1242a5e88d
|
@ -178,8 +178,10 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
# add 'invoice_total' quantities
|
||||
if child_row.invoice_total:
|
||||
parent_row.invoice_total = (parent_row.invoice_total or 0) + child_row.invoice_total
|
||||
parent_batch.invoice_total = (parent_batch.invoice_total or 0) + child_row.invoice_total
|
||||
if child_row.invoice_total_calculated:
|
||||
parent_row.invoice_total_calculated = (parent_row.invoice_total_calculated or 0) + child_row.invoice_total_calculated
|
||||
parent_batch.invoice_total_calculated = (parent_batch.invoice_total_calculated or 0) + child_row.invoice_total_calculated
|
||||
|
||||
else: # new product; simply add new row to parent
|
||||
parent_row = self.make_parent_row_from_child(child_row)
|
||||
|
@ -1068,6 +1070,7 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
|
||||
# update calculated invoice totals if normal received amounts
|
||||
if mode == 'received':
|
||||
# TODO: should round invoice amount to 2 places here?
|
||||
invoice_amount = 0
|
||||
if cases:
|
||||
invoice_amount += cases * row.case_quantity * row.invoice_unit_cost
|
||||
|
@ -1317,27 +1320,33 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
if positive:
|
||||
if cases and units and (child_row.cases_ordered_pending
|
||||
and child_row.units_ordered_pending):
|
||||
update(child_row.cases_ordered_pending, child_row.units_ordered_pending)
|
||||
return (cases - child_row.cases_ordered_pending,
|
||||
units - child_row.units_ordered_pending)
|
||||
pending = (child_row.cases_ordered_pending,
|
||||
child_row.units_ordered_pending)
|
||||
update(pending[0], pending[1])
|
||||
return cases - pending[0], units - pending[1]
|
||||
if cases and child_row.cases_ordered_pending:
|
||||
update(child_row.cases_ordered_pending, 0)
|
||||
return cases - child_row.cases_ordered_pending, 0
|
||||
pending = child_row.cases_ordered_pending
|
||||
update(pending, 0)
|
||||
return cases - pending, 0
|
||||
if units and child_row.units_ordered_pending:
|
||||
update(0, child_row.units_ordered_pending)
|
||||
return 0, units - child_row.units_ordered_pending
|
||||
pending = child_row.units_ordered_pending
|
||||
update(0, pending)
|
||||
return 0, units - pending
|
||||
else: # negative
|
||||
if cases and units and (child_row.cases_ordered_claimed
|
||||
and child_row.units_ordered_claimed):
|
||||
update(-child_row.cases_ordered_claimed, -child_row.units_ordered_claimed)
|
||||
return (cases + child_row.cases_ordered_claimed,
|
||||
units + child_row.units_ordered_claimed)
|
||||
claimed = (child_row.cases_ordered_claimed,
|
||||
child_row.units_ordered_claimed)
|
||||
update(-claimed[0], -claimed[1])
|
||||
return cases + claimed[0], units + claimed[1]
|
||||
if cases and child_row.cases_ordered_claimed:
|
||||
update(-child_row.cases_ordered_claimed, 0)
|
||||
return cases + child_row.cases_ordered_claimed, 0
|
||||
claimed = child_row.cases_ordered_claimed
|
||||
update(-claimed, 0)
|
||||
return cases + claimed, 0
|
||||
if units and child_row.units_ordered_claimed:
|
||||
update(0, -child_row.units_ordered_claimed)
|
||||
return 0, units + child_row.units_ordered_claimed
|
||||
claimed = child_row.units_ordered_claimed
|
||||
update(0, -claimed)
|
||||
return 0, units + claimed
|
||||
|
||||
# looks like we're gonna have to split some cases, one way or another
|
||||
if parent_row.case_quantity != child_row.case_quantity:
|
||||
|
@ -1353,9 +1362,10 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
update(0, unit_cases * parent_row.case_quantity)
|
||||
return cases - unit_cases, units
|
||||
else: # units_pending < case_size
|
||||
update(0, child_row.units_ordered_pending)
|
||||
pending = child_row.units_ordered_pending
|
||||
update(0, pending)
|
||||
return (cases - 1,
|
||||
(units or 0) + parent_row.case_quantity - child_row.units_ordered_pending)
|
||||
(units or 0) + parent_row.case_quantity - pending)
|
||||
if units and child_row.cases_ordered_pending:
|
||||
if units >= parent_row.case_quantity:
|
||||
unit_cases = units // parent_row.case_quantity
|
||||
|
@ -1363,8 +1373,9 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
update(unit_cases, 0)
|
||||
return 0, units - (unit_cases * parent_row.case_quantity)
|
||||
else: # unit_cases > cases_pending
|
||||
update(child_row.cases_ordered_pending, 0)
|
||||
return 0, units - (child_row.cases_ordered_pending * parent_row.case_quantity)
|
||||
pending = child_row.cases_ordered_pending
|
||||
update(pending, 0)
|
||||
return 0, units - (pending * parent_row.case_quantity)
|
||||
else: # units < case_size
|
||||
update(0, units)
|
||||
return 0, 0
|
||||
|
@ -1379,9 +1390,10 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
update(0, -unit_cases * parent_row.case_quantity)
|
||||
return cases + unit_cases, units
|
||||
else: # units_claimed < case_size
|
||||
update(0, -child_row.units_ordered_claimed)
|
||||
claimed = child_row.units_ordered_claimed
|
||||
update(0, -claimed)
|
||||
return (cases + 1,
|
||||
(units or 0) - parent_row.case_quantity + child_row.units_ordered_claimed)
|
||||
(units or 0) - parent_row.case_quantity + claimed)
|
||||
if units and child_row.cases_ordered_claimed:
|
||||
if -units >= parent_row.case_quantity:
|
||||
unit_cases = -units // parent_row.case_quantity
|
||||
|
@ -1389,8 +1401,9 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
update(-unit_cases, 0)
|
||||
return 0, units + (unit_cases * parent_row.case_quantity)
|
||||
else: # unit_cases > cases_claimed
|
||||
update(-child_row.cases_ordered_claimed, 0)
|
||||
return 0, units + (child_row.cases_ordered_claimed * parent_row.case_quantity)
|
||||
claimed = child_row.cases_ordered_claimed
|
||||
update(-claimed, 0)
|
||||
return 0, units + (claimed * parent_row.case_quantity)
|
||||
else: # -units < case_size
|
||||
update(0, units)
|
||||
return 0, 0
|
||||
|
|
Loading…
Reference in a new issue