Claim 'expired' credits when adding child invoice to truck dump parent
This commit is contained in:
parent
bc1a180639
commit
37b827f6e0
|
@ -311,8 +311,6 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
|
||||
else: # things are a bit trickier in this scenario
|
||||
|
||||
# TODO: should we ever use case quantity from truck dump instead?
|
||||
|
||||
if ordered and avail_received:
|
||||
cases, units = self.calc_best_fit(avail_received, case_quantity)
|
||||
total = self.get_units(cases, units, case_quantity)
|
||||
|
@ -344,13 +342,21 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
# TODO: need to add support for credits to this one
|
||||
if ordered and avail_expired:
|
||||
possible_credits = [credit for credit in truck_dump_row.credits
|
||||
if credit.credit_type == 'expired']
|
||||
possible_shorted = sum([self.get_units_shorted(credit)
|
||||
for credit in possible_credits])
|
||||
if possible_shorted != avail_expired:
|
||||
raise NotImplementedError("need logic to handle 'expired' credit quantity mismatch?")
|
||||
cases, units = self.calc_best_fit(avail_expired, case_quantity)
|
||||
total = self.get_units(cases, units, case_quantity)
|
||||
assert total == avail_expired, "total units doesn't match avail_expired for {}".format(truck_dump_row)
|
||||
if total != avail_expired:
|
||||
raise ValueError("total units doesn't match avail_expired for {}".format(truck_dump_row))
|
||||
child_row.cases_expired = claim.cases_expired = cases or None
|
||||
child_row.cases_expired = claim.units_expired = units or None
|
||||
child_row.units_expired = claim.units_expired = units or None
|
||||
for credit in possible_credits:
|
||||
self.clone_truck_dump_credit(credit, child_row)
|
||||
self.refresh_row(child_row)
|
||||
avail_expired -= total
|
||||
ordered -= total
|
||||
|
|
Loading…
Reference in a new issue