Changeset ed6ef1e in rattail


Ignore:
Timestamp:
03/02/19 18:09:40 (18 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
9df0f00
Parents:
0b88942
Message:

Make "auto receive all" logic smarter, to handle split cases

also fix a bug within receive_row() logic, for split case calculation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/purchase.py

    r0b88942 red6ef1e  
    14521452                # maybe account for split cases
    14531453                if child_row.units_ordered_pending < 0:
    1454                     split_cases = -child_row.units_ordered_pending // child_row.case_quantity + 1
     1454                    split_cases = -child_row.units_ordered_pending // child_row.case_quantity
     1455                    if -child_row.units_ordered_pending % child_row.case_quantity:
     1456                        split_cases += 1
    14551457                    if split_cases > child_row.cases_ordered_pending:
    14561458                        raise ValueError("too many cases have been split?")
     
    16871689        def receive(row, i):
    16881690
    1689             # auto-receive remaining cases
    1690             cases_ordered = row.cases_ordered or 0
     1691            # calculate remaining cases, units
    16911692            cases_confirmed = ((row.cases_received or 0)
    16921693                               + (row.cases_damaged or 0)
    16931694                               + (row.cases_expired or 0))
    1694             if cases_ordered > cases_confirmed:
    1695                 row.cases_received = (row.cases_received or 0) + (
    1696                     cases_ordered - cases_confirmed)
    1697 
    1698             # auto-receive remaining units
    1699             units_ordered = row.units_ordered or 0
     1695            cases_pending = (row.cases_ordered or 0) - cases_confirmed
    17001696            units_confirmed = ((row.units_received or 0)
    17011697                               + (row.units_damaged or 0)
    17021698                               + (row.units_expired or 0))
    1703             if units_ordered > units_confirmed:
    1704                 row.units_received = (row.units_received or 0) + (
    1705                     units_ordered - units_confirmed)
    1706 
    1707             # establish truck dump claims if applicable
    1708             if (batch.is_truck_dump_parent()
    1709                 and batch.truck_dump_children_first
    1710                 and row.product):
    1711                 self.make_truck_dump_claims_for_parent_row(row)
     1699            units_pending = (row.units_ordered or 0) - units_confirmed
     1700
     1701            # maybe account for split cases
     1702            if units_pending < 0:
     1703                split_cases = -units_pending // row.case_quantity
     1704                if -units_pending % row.case_quantity:
     1705                    split_cases += 1
     1706                if split_cases > cases_pending:
     1707                    raise ValueError("too many cases have been split?")
     1708                cases_pending -= split_cases
     1709                units_pending += split_cases * row.case_quantity
     1710
     1711            # auto-receive whatever is left
     1712            if cases_pending:
     1713                self.receive_row(row, mode='received', cases=cases_pending)
     1714            if units_pending:
     1715                self.receive_row(row, mode='received', units=units_pending)
    17121716
    17131717        self.progress_loop(receive, batch.active_rows(), progress,
Note: See TracChangeset for help on using the changeset viewer.