Changeset 1d05f73 in rattail


Ignore:
Timestamp:
04/01/19 13:18:40 (6 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
aa74623
Parents:
850c197
Message:

Use "shipped" instead of "ordered" for truck dump child row "claims"

i.e. if 1 CS is received, that should count against the *shipped* quantity and
not the "ordered" quantity. if shipped is not explicitly stated on the
invoice, its value should be copied from the ordered quantity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/purchase.py

    r850c197 r1d05f73  
    362362            # vs. "pending" product quantities
    363363
    364             # cases_ordered
    365             cases_ordered = child_row.cases_ordered or 0
    366             cases_ordered_claimed = sum([(claim.cases_received or 0)
     364            # cases_shipped
     365            cases_shipped = child_row.cases_shipped or 0
     366            cases_shipped_claimed = sum([(claim.cases_received or 0)
    367367                                         + (claim.cases_damaged or 0)
    368368                                         + (claim.cases_expired or 0)
    369369                                         for claim in child_row.truck_dump_claims])
    370             cases_ordered_pending = cases_ordered - cases_ordered_claimed
    371 
    372             # units_ordered
    373             units_ordered = child_row.units_ordered or 0
    374             units_ordered_claimed = sum([(claim.units_received or 0)
     370            cases_shipped_pending = cases_shipped - cases_shipped_claimed
     371
     372            # units_shipped
     373            units_shipped = child_row.units_shipped or 0
     374            units_shipped_claimed = sum([(claim.units_received or 0)
    375375                                         + (claim.units_damaged or 0)
    376376                                         + (claim.units_expired or 0)
    377377                                         for claim in child_row.truck_dump_claims])
    378             units_ordered_pending = units_ordered - units_ordered_claimed
     378            units_shipped_pending = units_shipped - units_shipped_claimed
    379379
    380380            # skip this child row if everything in it is accounted for
    381             if not (cases_ordered_pending or units_ordered_pending):
     381            if not (cases_shipped_pending or units_shipped_pending):
    382382                continue
    383383
     
    389389
    390390            # make case claims
    391             if cases_ordered_pending and cases_received_pending:
     391            if cases_shipped_pending and cases_received_pending:
    392392                claim = claim or make_claim(child_row)
    393                 if cases_received_pending >= cases_ordered_pending:
    394                     claim.cases_received = (claim.cases_received or 0) + cases_ordered_pending
    395                     child_row.cases_received = (child_row.cases_received or 0) + cases_ordered_pending
    396                     cases_received_pending -= cases_ordered_pending
    397                     cases_ordered_pending = 0
    398                 else: # ordered > received
     393                if cases_received_pending >= cases_shipped_pending:
     394                    claim.cases_received = (claim.cases_received or 0) + cases_shipped_pending
     395                    child_row.cases_received = (child_row.cases_received or 0) + cases_shipped_pending
     396                    cases_received_pending -= cases_shipped_pending
     397                    cases_shipped_pending = 0
     398                else: # shipped > received
    399399                    claim.cases_received = (claim.cases_received or 0) + cases_received_pending
    400400                    child_row.cases_received = (child_row.cases_received or 0) + cases_received_pending
    401                     cases_ordered_pending -= cases_received_pending
     401                    cases_shipped_pending -= cases_received_pending
    402402                    cases_received_pending = 0
    403403                self.refresh_row(child_row)
    404             if cases_ordered_pending and cases_damaged_pending:
     404            if cases_shipped_pending and cases_damaged_pending:
    405405                claim = claim or make_claim(child_row)
    406                 if cases_damaged_pending >= cases_ordered_pending:
    407                     claim.cases_damaged = (claim.cases_damaged or 0) + cases_ordered_pending
    408                     child_row.cases_damaged = (child_row.cases_damaged or 0) + cases_ordered_pending
    409                     cases_damaged_pending -= cases_ordered_pending
    410                     cases_ordered_pending = 0
    411                 else: # ordered > damaged
     406                if cases_damaged_pending >= cases_shipped_pending:
     407                    claim.cases_damaged = (claim.cases_damaged or 0) + cases_shipped_pending
     408                    child_row.cases_damaged = (child_row.cases_damaged or 0) + cases_shipped_pending
     409                    cases_damaged_pending -= cases_shipped_pending
     410                    cases_shipped_pending = 0
     411                else: # shipped > damaged
    412412                    claim.cases_damaged = (claim.cases_damaged or 0) + cases_damaged_pending
    413413                    child_row.cases_damaged = (child_row.cases_damaged or 0) + cases_damaged_pending
    414                     cases_ordered_pending -= cases_damaged_pending
     414                    cases_shipped_pending -= cases_damaged_pending
    415415                    cases_damaged_pending = 0
    416416                self.refresh_row(child_row)
    417             if cases_ordered_pending and cases_expired_pending:
     417            if cases_shipped_pending and cases_expired_pending:
    418418                claim = claim or make_claim(child_row)
    419                 if cases_expired_pending >= cases_ordered_pending:
    420                     claim.cases_expired = (claim.cases_expired or 0) + cases_ordered_pending
    421                     child_row.cases_expired = (child_row.cases_expired or 0) + cases_ordered_pending
    422                     cases_expired_pending -= cases_ordered_pending
    423                     cases_ordered_pending = 0
    424                 else: # ordered > expired
     419                if cases_expired_pending >= cases_shipped_pending:
     420                    claim.cases_expired = (claim.cases_expired or 0) + cases_shipped_pending
     421                    child_row.cases_expired = (child_row.cases_expired or 0) + cases_shipped_pending
     422                    cases_expired_pending -= cases_shipped_pending
     423                    cases_shipped_pending = 0
     424                else: # shipped > expired
    425425                    claim.cases_expired = (claim.cases_expired or 0) + cases_expired_pending
    426426                    child_row.cases_expired = (child_row.cases_expired or 0) + cases_expired_pending
    427                     cases_ordered_pending -= cases_expired_pending
     427                    cases_shipped_pending -= cases_expired_pending
    428428                    cases_expired_pending = 0
    429429                self.refresh_row(child_row)
    430430
    431431            # make unit claims
    432             if units_ordered_pending and units_received_pending:
     432            if units_shipped_pending and units_received_pending:
    433433                claim = claim or make_claim(child_row)
    434                 if units_received_pending >= units_ordered_pending:
    435                     claim.units_received = (claim.units_received or 0) + units_ordered_pending
    436                     child_row.units_received = (child_row.units_received or 0) + units_ordered_pending
    437                     units_received_pending -= units_ordered_pending
    438                     units_ordered_pending = 0
    439                 else: # ordered > received
     434                if units_received_pending >= units_shipped_pending:
     435                    claim.units_received = (claim.units_received or 0) + units_shipped_pending
     436                    child_row.units_received = (child_row.units_received or 0) + units_shipped_pending
     437                    units_received_pending -= units_shipped_pending
     438                    units_shipped_pending = 0
     439                else: # shipped > received
    440440                    claim.units_received = (claim.units_received or 0) + units_received_pending
    441441                    child_row.units_received = (child_row.units_received or 0) + units_received_pending
    442                     units_ordered_pending -= units_received_pending
     442                    units_shipped_pending -= units_received_pending
    443443                    units_received_pending = 0
    444444                self.refresh_row(child_row)
    445             if units_ordered_pending and units_damaged_pending:
     445            if units_shipped_pending and units_damaged_pending:
    446446                claim = claim or make_claim(child_row)
    447                 if units_damaged_pending >= units_ordered_pending:
    448                     claim.units_damaged = (claim.units_damaged or 0) + units_ordered_pending
    449                     child_row.units_damaged = (child_row.units_damaged or 0) + units_ordered_pending
    450                     units_damaged_pending -= units_ordered_pending
    451                     units_ordered_pending = 0
    452                 else: # ordered > damaged
     447                if units_damaged_pending >= units_shipped_pending:
     448                    claim.units_damaged = (claim.units_damaged or 0) + units_shipped_pending
     449                    child_row.units_damaged = (child_row.units_damaged or 0) + units_shipped_pending
     450                    units_damaged_pending -= units_shipped_pending
     451                    units_shipped_pending = 0
     452                else: # shipped > damaged
    453453                    claim.units_damaged = (claim.units_damaged or 0) + units_damaged_pending
    454454                    child_row.units_damaged = (child_row.units_damaged or 0) + units_damaged_pending
    455                     units_ordered_pending -= units_damaged_pending
     455                    units_shipped_pending -= units_damaged_pending
    456456                    units_damaged_pending = 0
    457457                self.refresh_row(child_row)
    458             if units_ordered_pending and units_expired_pending:
     458            if units_shipped_pending and units_expired_pending:
    459459                claim = claim or make_claim(child_row)
    460                 if units_expired_pending >= units_ordered_pending:
    461                     claim.units_expired = (claim.units_expired or 0) + units_ordered_pending
    462                     child_row.units_expired = (child_row.units_expired or 0) + units_ordered_pending
    463                     units_expired_pending -= units_ordered_pending
    464                     units_ordered_pending = 0
    465                 else: # ordered > expired
     460                if units_expired_pending >= units_shipped_pending:
     461                    claim.units_expired = (claim.units_expired or 0) + units_shipped_pending
     462                    child_row.units_expired = (child_row.units_expired or 0) + units_shipped_pending
     463                    units_expired_pending -= units_shipped_pending
     464                    units_shipped_pending = 0
     465                else: # shipped > expired
    466466                    claim.units_expired = (claim.units_expired or 0) + units_expired_pending
    467467                    child_row.units_expired = (child_row.units_expired or 0) + units_expired_pending
    468                     units_ordered_pending -= units_expired_pending
     468                    units_shipped_pending -= units_expired_pending
    469469                    units_expired_pending = 0
    470470                self.refresh_row(child_row)
     
    474474            # we assume the child row has correct case quantity even if parent
    475475            # row has a different one.
    476             if cases_ordered_pending and units_received_pending:
     476            if cases_shipped_pending and units_received_pending:
    477477                received = units_received_pending // case_quantity
    478478                if received:
    479479                    claim = claim or make_claim(child_row)
    480                     if received >= cases_ordered_pending:
    481                         claim.cases_received = (claim.cases_received or 0) + cases_ordered_pending
    482                         child_row.cases_received = (child_row.units_received or 0) + cases_ordered_pending
    483                         units_received_pending -= (cases_ordered_pending * case_quantity)
    484                         cases_ordered_pending = 0
    485                     else: # ordered > received
     480                    if received >= cases_shipped_pending:
     481                        claim.cases_received = (claim.cases_received or 0) + cases_shipped_pending
     482                        child_row.cases_received = (child_row.units_received or 0) + cases_shipped_pending
     483                        units_received_pending -= (cases_shipped_pending * case_quantity)
     484                        cases_shipped_pending = 0
     485                    else: # shipped > received
    486486                        claim.cases_received = (claim.cases_received or 0) + received
    487487                        child_row.cases_received = (child_row.units_received or 0) + received
    488                         cases_ordered_pending -= received
     488                        cases_shipped_pending -= received
    489489                        units_received_pending -= (received * case_quantity)
    490490                    self.refresh_row(child_row)
    491             if cases_ordered_pending and units_damaged_pending:
     491            if cases_shipped_pending and units_damaged_pending:
    492492                damaged = units_damaged_pending // case_quantity
    493493                if damaged:
    494494                    claim = claim or make_claim(child_row)
    495                     if damaged >= cases_ordered_pending:
    496                         claim.cases_damaged = (claim.cases_damaged or 0) + cases_ordered_pending
    497                         child_row.cases_damaged = (child_row.units_damaged or 0) + cases_ordered_pending
    498                         units_damaged_pending -= (cases_ordered_pending * case_quantity)
    499                         cases_ordered_pending = 0
    500                     else: # ordered > damaged
     495                    if damaged >= cases_shipped_pending:
     496                        claim.cases_damaged = (claim.cases_damaged or 0) + cases_shipped_pending
     497                        child_row.cases_damaged = (child_row.units_damaged or 0) + cases_shipped_pending
     498                        units_damaged_pending -= (cases_shipped_pending * case_quantity)
     499                        cases_shipped_pending = 0
     500                    else: # shipped > damaged
    501501                        claim.cases_damaged = (claim.cases_damaged or 0) + damaged
    502502                        child_row.cases_damaged = (child_row.units_damaged or 0) + damaged
    503                         cases_ordered_pending -= damaged
     503                        cases_shipped_pending -= damaged
    504504                        units_damaged_pending -= (damaged * case_quantity)
    505505                    self.refresh_row(child_row)
    506             if cases_ordered_pending and units_expired_pending:
     506            if cases_shipped_pending and units_expired_pending:
    507507                expired = units_expired_pending // case_quantity
    508508                if expired:
    509509                    claim = claim or make_claim(child_row)
    510                     if expired >= cases_ordered_pending:
    511                         claim.cases_expired = (claim.cases_expired or 0) + cases_ordered_pending
    512                         child_row.cases_expired = (child_row.units_expired or 0) + cases_ordered_pending
    513                         units_expired_pending -= (cases_ordered_pending * case_quantity)
    514                         cases_ordered_pending = 0
    515                     else: # ordered > expired
     510                    if expired >= cases_shipped_pending:
     511                        claim.cases_expired = (claim.cases_expired or 0) + cases_shipped_pending
     512                        child_row.cases_expired = (child_row.units_expired or 0) + cases_shipped_pending
     513                        units_expired_pending -= (cases_shipped_pending * case_quantity)
     514                        cases_shipped_pending = 0
     515                    else: # shipped > expired
    516516                        claim.cases_expired = (claim.cases_expired or 0) + expired
    517517                        child_row.cases_expired = (child_row.units_expired or 0) + expired
    518                         cases_ordered_pending -= expired
     518                        cases_shipped_pending -= expired
    519519                        units_expired_pending -= (expired * case_quantity)
    520520                    self.refresh_row(child_row)
     
    525525            # (otherwise who knows what could go wrong.)
    526526            if case_quantity == truck_dump_row.case_quantity:
    527                 if units_ordered_pending and cases_received_pending:
     527                if units_shipped_pending and cases_received_pending:
    528528                    received = cases_received_pending * case_quantity
    529529                    claim = claim or make_claim(child_row)
    530                     if received >= units_ordered_pending:
    531                         claim.units_received = (claim.units_received or 0) + units_ordered_pending
    532                         child_row.units_received = (child_row.units_received or 0) + units_ordered_pending
    533                         leftover = received % units_ordered_pending
     530                    if received >= units_shipped_pending:
     531                        claim.units_received = (claim.units_received or 0) + units_shipped_pending
     532                        child_row.units_received = (child_row.units_received or 0) + units_shipped_pending
     533                        leftover = received % units_shipped_pending
    534534                        if leftover == 0:
    535                             cases_received_pending -= (received // units_ordered_pending)
     535                            cases_received_pending -= (received // units_shipped_pending)
    536536                        else:
    537                             cases_received_pending -= (received // units_ordered_pending) - 1
     537                            cases_received_pending -= (received // units_shipped_pending) - 1
    538538                            units_received_pending += leftover
    539                         units_ordered_pending = 0
    540                     else: # ordered > received
     539                        units_shipped_pending = 0
     540                    else: # shipped > received
    541541                        claim.units_received = (claim.units_received or 0) + received
    542542                        child_row.units_received = (child_row.units_received or 0) + received
    543                         units_ordered_pending -= received
     543                        units_shipped_pending -= received
    544544                        cases_received_pending = 0
    545545                    self.refresh_row(child_row)
    546                 if units_ordered_pending and cases_damaged_pending:
     546                if units_shipped_pending and cases_damaged_pending:
    547547                    damaged = cases_damaged_pending * case_quantity
    548548                    claim = claim or make_claim(child_row)
    549                     if damaged >= units_ordered_pending:
    550                         claim.units_damaged = (claim.units_damaged or 0) + units_ordered_pending
    551                         child_row.units_damaged = (child_row.units_damaged or 0) + units_ordered_pending
    552                         leftover = damaged % units_ordered_pending
     549                    if damaged >= units_shipped_pending:
     550                        claim.units_damaged = (claim.units_damaged or 0) + units_shipped_pending
     551                        child_row.units_damaged = (child_row.units_damaged or 0) + units_shipped_pending
     552                        leftover = damaged % units_shipped_pending
    553553                        if leftover == 0:
    554                             cases_damaged_pending -= (damaged // units_ordered_pending)
     554                            cases_damaged_pending -= (damaged // units_shipped_pending)
    555555                        else:
    556                             cases_damaged_pending -= (damaged // units_ordered_pending) - 1
     556                            cases_damaged_pending -= (damaged // units_shipped_pending) - 1
    557557                            units_damaged_pending += leftover
    558                         units_ordered_pending = 0
    559                     else: # ordered > damaged
     558                        units_shipped_pending = 0
     559                    else: # shipped > damaged
    560560                        claim.units_damaged = (claim.units_damaged or 0) + damaged
    561561                        child_row.units_damaged = (child_row.units_damaged or 0) + damaged
    562                         units_ordered_pending -= damaged
     562                        units_shipped_pending -= damaged
    563563                        cases_damaged_pending = 0
    564564                    self.refresh_row(child_row)
    565                 if units_ordered_pending and cases_expired_pending:
     565                if units_shipped_pending and cases_expired_pending:
    566566                    expired = cases_expired_pending * case_quantity
    567567                    claim = claim or make_claim(child_row)
    568                     if expired >= units_ordered_pending:
    569                         claim.units_expired = (claim.units_expired or 0) + units_ordered_pending
    570                         child_row.units_expired = (child_row.units_expired or 0) + units_ordered_pending
    571                         leftover = expired % units_ordered_pending
     568                    if expired >= units_shipped_pending:
     569                        claim.units_expired = (claim.units_expired or 0) + units_shipped_pending
     570                        child_row.units_expired = (child_row.units_expired or 0) + units_shipped_pending
     571                        leftover = expired % units_shipped_pending
    572572                        if leftover == 0:
    573                             cases_expired_pending -= (expired // units_ordered_pending)
     573                            cases_expired_pending -= (expired // units_shipped_pending)
    574574                        else:
    575                             cases_expired_pending -= (expired // units_ordered_pending) - 1
     575                            cases_expired_pending -= (expired // units_shipped_pending) - 1
    576576                            units_expired_pending += leftover
    577                         units_ordered_pending = 0
    578                     else: # ordered > expired
     577                        units_shipped_pending = 0
     578                    else: # shipped > expired
    579579                        claim.units_expired = (claim.units_expired or 0) + expired
    580580                        child_row.units_expired = (child_row.units_expired or 0) + expired
    581                         units_ordered_pending -= expired
     581                        units_shipped_pending -= expired
    582582                        cases_expired_pending = 0
    583583                    self.refresh_row(child_row)
     
    13931393            self.receiving_update_row_attrs(child_row, mode, cases, units)
    13941394            if cases:
    1395                 child_row.cases_ordered_claimed += cases
    1396                 child_row.cases_ordered_pending -= cases
     1395                child_row.cases_shipped_claimed += cases
     1396                child_row.cases_shipped_pending -= cases
    13971397            if units:
    1398                 child_row.units_ordered_claimed += units
    1399                 child_row.units_ordered_pending -= units
     1398                child_row.units_shipped_claimed += units
     1399                child_row.units_shipped_pending -= units
    14001400
    14011401            # update child credit, if applicable
     
    14191419        if positive:
    14201420            if cases and units:
    1421                 if child_row.cases_ordered_pending >= cases and child_row.units_ordered_pending >= units:
     1421                if child_row.cases_shipped_pending >= cases and child_row.units_shipped_pending >= units:
    14221422                    update(cases, units)
    14231423                    return 0, 0
    14241424            elif cases:
    1425                 if child_row.cases_ordered_pending >= cases:
     1425                if child_row.cases_shipped_pending >= cases:
    14261426                    update(cases, 0)
    14271427                    return 0, 0
    14281428            else: # units
    1429                 if child_row.units_ordered_pending >= units:
     1429                if child_row.units_shipped_pending >= units:
    14301430                    update(0, units)
    14311431                    return 0, 0
    14321432        else: # negative
    14331433            if cases and units:
    1434                 if child_row.cases_ordered_claimed >= -cases and child_row.units_ordered_claimed >= -units:
     1434                if child_row.cases_shipped_claimed >= -cases and child_row.units_shipped_claimed >= -units:
    14351435                    update(cases, units)
    14361436                    return 0, 0
    14371437            elif cases:
    1438                 if child_row.cases_ordered_claimed >= -cases:
     1438                if child_row.cases_shipped_claimed >= -cases:
    14391439                    update(cases, 0)
    14401440                    return 0, 0
    14411441            else: # units
    1442                 if child_row.units_ordered_claimed >= -units:
     1442                if child_row.units_shipped_claimed >= -units:
    14431443                    update(0, units)
    14441444                    return 0, 0
     
    14481448        if cases and units:
    14491449            if positive:
    1450                 if child_row.cases_ordered_pending >= cases:
     1450                if child_row.cases_shipped_pending >= cases:
    14511451                    update(cases, 0)
    14521452                    return 0, units
    1453                 if child_row.units_ordered_pending >= units:
     1453                if child_row.units_shipped_pending >= units:
    14541454                    update(0, units)
    14551455                    return cases, 0
    14561456            else: # negative
    1457                 if child_row.cases_ordered_claimed >= -cases:
     1457                if child_row.cases_shipped_claimed >= -cases:
    14581458                    update(cases, 0)
    14591459                    return 0, units
    1460                 if child_row.units_ordered_claimed >= -units:
     1460                if child_row.units_shipped_claimed >= -units:
    14611461                    update(0, units)
    14621462                    return cases, 0
     
    14641464        # okay then, try to (simply) use up any "child" quantities
    14651465        if positive:
    1466             if cases and units and (child_row.cases_ordered_pending
    1467                                     and child_row.units_ordered_pending):
    1468                 pending = (child_row.cases_ordered_pending,
    1469                            child_row.units_ordered_pending)
     1466            if cases and units and (child_row.cases_shipped_pending
     1467                                    and child_row.units_shipped_pending):
     1468                pending = (child_row.cases_shipped_pending,
     1469                           child_row.units_shipped_pending)
    14701470                update(pending[0], pending[1])
    14711471                return cases - pending[0], units - pending[1]
    1472             if cases and child_row.cases_ordered_pending:
    1473                 pending = child_row.cases_ordered_pending
     1472            if cases and child_row.cases_shipped_pending:
     1473                pending = child_row.cases_shipped_pending
    14741474                update(pending, 0)
    14751475                return cases - pending, 0
    1476             if units and child_row.units_ordered_pending:
    1477                 pending = child_row.units_ordered_pending
     1476            if units and child_row.units_shipped_pending:
     1477                pending = child_row.units_shipped_pending
    14781478                update(0, pending)
    14791479                return 0, units - pending
    14801480        else: # negative
    1481             if cases and units and (child_row.cases_ordered_claimed
    1482                                     and child_row.units_ordered_claimed):
    1483                 claimed = (child_row.cases_ordered_claimed,
    1484                            child_row.units_ordered_claimed)
     1481            if cases and units and (child_row.cases_shipped_claimed
     1482                                    and child_row.units_shipped_claimed):
     1483                claimed = (child_row.cases_shipped_claimed,
     1484                           child_row.units_shipped_claimed)
    14851485                update(-claimed[0], -claimed[1])
    14861486                return cases + claimed[0], units + claimed[1]
    1487             if cases and child_row.cases_ordered_claimed:
    1488                 claimed = child_row.cases_ordered_claimed
     1487            if cases and child_row.cases_shipped_claimed:
     1488                claimed = child_row.cases_shipped_claimed
    14891489                update(-claimed, 0)
    14901490                return cases + claimed, 0
    1491             if units and child_row.units_ordered_claimed:
    1492                 claimed = child_row.units_ordered_claimed
     1491            if units and child_row.units_shipped_claimed:
     1492                claimed = child_row.units_shipped_claimed
    14931493                update(0, -claimed)
    14941494                return 0, units + claimed
     
    14981498            raise NotImplementedError("cannot split case when parent/child disagree about size")
    14991499        if positive:
    1500             if cases and child_row.units_ordered_pending:
    1501                 if child_row.units_ordered_pending >= parent_row.case_quantity:
    1502                     unit_cases = child_row.units_ordered_pending // parent_row.case_quantity
     1500            if cases and child_row.units_shipped_pending:
     1501                if child_row.units_shipped_pending >= parent_row.case_quantity:
     1502                    unit_cases = child_row.units_shipped_pending // parent_row.case_quantity
    15031503                    if unit_cases >= cases:
    15041504                        update(0, cases * parent_row.case_quantity)
     
    15081508                        return cases - unit_cases, units
    15091509                else: # units_pending < case_size
    1510                     pending = child_row.units_ordered_pending
     1510                    pending = child_row.units_shipped_pending
    15111511                    update(0, pending)
    15121512                    return (cases - 1,
    15131513                            (units or 0) + parent_row.case_quantity - pending)
    1514             if units and child_row.cases_ordered_pending:
     1514            if units and child_row.cases_shipped_pending:
    15151515                if units >= parent_row.case_quantity:
    15161516                    unit_cases = units // parent_row.case_quantity
    1517                     if unit_cases <= child_row.cases_ordered_pending:
     1517                    if unit_cases <= child_row.cases_shipped_pending:
    15181518                        update(unit_cases, 0)
    15191519                        return 0, units - (unit_cases * parent_row.case_quantity)
    15201520                    else: # unit_cases > cases_pending
    1521                         pending = child_row.cases_ordered_pending
     1521                        pending = child_row.cases_shipped_pending
    15221522                        update(pending, 0)
    15231523                        return 0, units - (pending * parent_row.case_quantity)
     
    15261526                    return 0, 0
    15271527        else: # negative
    1528             if cases and child_row.units_ordered_claimed:
    1529                 if child_row.units_ordered_claimed >= parent_row.case_quantity:
    1530                     unit_cases = child_row.units_ordered_claimed // parent_row.case_quantity
     1528            if cases and child_row.units_shipped_claimed:
     1529                if child_row.units_shipped_claimed >= parent_row.case_quantity:
     1530                    unit_cases = child_row.units_shipped_claimed // parent_row.case_quantity
    15311531                    if unit_cases >= -cases:
    15321532                        update(0, cases * parent_row.case_quantity)
     
    15361536                        return cases + unit_cases, units
    15371537                else: # units_claimed < case_size
    1538                     claimed = child_row.units_ordered_claimed
     1538                    claimed = child_row.units_shipped_claimed
    15391539                    update(0, -claimed)
    15401540                    return (cases + 1,
    15411541                            (units or 0) - parent_row.case_quantity + claimed)
    1542             if units and child_row.cases_ordered_claimed:
     1542            if units and child_row.cases_shipped_claimed:
    15431543                if -units >= parent_row.case_quantity:
    15441544                    unit_cases = -units // parent_row.case_quantity
    1545                     if unit_cases <= child_row.cases_ordered_claimed:
     1545                    if unit_cases <= child_row.cases_shipped_claimed:
    15461546                        update(-unit_cases, 0)
    15471547                        return 0, units + (unit_cases * parent_row.case_quantity)
    15481548                    else: # unit_cases > cases_claimed
    1549                         claimed = child_row.cases_ordered_claimed
     1549                        claimed = child_row.cases_shipped_claimed
    15501550                        update(-claimed, 0)
    15511551                        return 0, units + (claimed * parent_row.case_quantity)
     
    16051605
    16061606                # cases_ordered
    1607                 child_row.cases_ordered_claimed = sum([(claim.cases_received or 0)
     1607                child_row.cases_shipped_claimed = sum([(claim.cases_received or 0)
    16081608                                                       + (claim.cases_damaged or 0)
    16091609                                                       + (claim.cases_expired or 0)
    16101610                                                       for claim in child_row.truck_dump_claims])
    1611                 child_row.cases_ordered_pending = (child_row.cases_ordered or 0) - child_row.cases_ordered_claimed
     1611                child_row.cases_shipped_pending = (child_row.cases_ordered or 0) - child_row.cases_shipped_claimed
    16121612
    16131613                # units_ordered
    1614                 child_row.units_ordered_claimed = sum([(claim.units_received or 0)
     1614                child_row.units_shipped_claimed = sum([(claim.units_received or 0)
    16151615                                                       + (claim.units_damaged or 0)
    16161616                                                       + (claim.units_expired or 0)
    16171617                                                       for claim in child_row.truck_dump_claims])
    1618                 child_row.units_ordered_pending = (child_row.units_ordered or 0) - child_row.units_ordered_claimed
     1618                child_row.units_shipped_pending = (child_row.units_ordered or 0) - child_row.units_shipped_claimed
    16191619
    16201620                # maybe account for split cases
    1621                 if child_row.units_ordered_pending < 0:
    1622                     split_cases = -child_row.units_ordered_pending // child_row.case_quantity
    1623                     if -child_row.units_ordered_pending % child_row.case_quantity:
     1621                if child_row.units_shipped_pending < 0:
     1622                    split_cases = -child_row.units_shipped_pending // child_row.case_quantity
     1623                    if -child_row.units_shipped_pending % child_row.case_quantity:
    16241624                        split_cases += 1
    1625                     if split_cases > child_row.cases_ordered_pending:
     1625                    if split_cases > child_row.cases_shipped_pending:
    16261626                        raise ValueError("too many cases have been split?")
    1627                     child_row.cases_ordered_pending -= split_cases
    1628                     child_row.units_ordered_pending += split_cases * child_row.case_quantity
     1627                    child_row.cases_shipped_pending -= split_cases
     1628                    child_row.units_shipped_pending += split_cases * child_row.case_quantity
    16291629
    16301630                all_child_rows.append(child_row)
     
    16321632        def sortkey(row):
    16331633            if positive:
    1634                 return self.get_units(row.cases_ordered_pending,
    1635                                       row.units_ordered_pending,
     1634                return self.get_units(row.cases_shipped_pending,
     1635                                      row.units_shipped_pending,
    16361636                                      row.case_quantity)
    16371637            else: # negative
    1638                 return self.get_units(row.cases_ordered_claimed,
    1639                                       row.units_ordered_claimed,
     1638                return self.get_units(row.cases_shipped_claimed,
     1639                                      row.units_shipped_claimed,
    16401640                                      row.case_quantity)
    16411641
     
    16481648            if cases and units:
    16491649                if positive:
    1650                     if child_row.cases_ordered_pending == cases and child_row.units_ordered_pending == units:
     1650                    if child_row.cases_shipped_pending == cases and child_row.units_shipped_pending == units:
    16511651                        return child_row
    16521652                else: # negative
    1653                     if child_row.cases_ordered_claimed == cases and child_row.units_ordered_claimed == units:
     1653                    if child_row.cases_shipped_claimed == cases and child_row.units_shipped_claimed == units:
    16541654                        return child_row
    16551655            elif cases:
    16561656                if positive:
    1657                     if child_row.cases_ordered_pending == cases:
     1657                    if child_row.cases_shipped_pending == cases:
    16581658                        return child_row
    16591659                else: # negative
    1660                     if child_row.cases_ordered_claimed == cases:
     1660                    if child_row.cases_shipped_claimed == cases:
    16611661                        return child_row
    16621662            else: # units
    16631663                if positive:
    1664                     if child_row.units_ordered_pending == units:
     1664                    if child_row.units_shipped_pending == units:
    16651665                        return child_row
    16661666                else: # negative
    1667                     if child_row.units_ordered_claimed == units:
     1667                    if child_row.units_shipped_claimed == units:
    16681668                        return child_row
    16691669
     
    16731673            if cases and units:
    16741674                if positive:
    1675                     if child_row.cases_ordered_pending >= cases and child_row.units_ordered_pending >= units:
     1675                    if child_row.cases_shipped_pending >= cases and child_row.units_shipped_pending >= units:
    16761676                        return child_row
    16771677                else: # negative
    1678                     if child_row.cases_ordered_claimed >= -cases and child_row.units_ordered_claimed >= -units:
     1678                    if child_row.cases_shipped_claimed >= -cases and child_row.units_shipped_claimed >= -units:
    16791679                        return child_row
    16801680            elif cases:
    16811681                if positive:
    1682                     if child_row.cases_ordered_pending >= cases:
     1682                    if child_row.cases_shipped_pending >= cases:
    16831683                        return child_row
    16841684                else: # negative
    1685                     if child_row.cases_ordered_claimed >= -cases:
     1685                    if child_row.cases_shipped_claimed >= -cases:
    16861686                        return child_row
    16871687            else: # units
    16881688                if positive:
    1689                     if child_row.units_ordered_pending >= units:
     1689                    if child_row.units_shipped_pending >= units:
    16901690                        return child_row
    16911691                else: # negative
    1692                     if child_row.units_ordered_claimed >= -units:
     1692                    if child_row.units_shipped_claimed >= -units:
    16931693                        return child_row
    16941694
     
    16981698        for child_row in all_child_rows:
    16991699            if positive:
    1700                 pending_units = self.get_units(child_row.cases_ordered_pending,
    1701                                                child_row.units_ordered_pending,
     1700                pending_units = self.get_units(child_row.cases_shipped_pending,
     1701                                               child_row.units_shipped_pending,
    17021702                                               child_row.case_quantity)
    17031703                if pending_units >= incoming_units:
    17041704                    return child_row
    17051705            else: # negative
    1706                 claimed_units = self.get_units(child_row.cases_ordered_claimed,
    1707                                                child_row.units_ordered_claimed,
     1706                claimed_units = self.get_units(child_row.cases_shipped_claimed,
     1707                                               child_row.units_shipped_claimed,
    17081708                                               child_row.case_quantity)
    17091709                if claimed_units >= -incoming_units:
     
    17171717        for child_row in reversed(all_child_rows):
    17181718            if positive:
    1719                 if child_row.cases_ordered_pending or child_row.units_ordered_pending:
     1719                if child_row.cases_shipped_pending or child_row.units_shipped_pending:
    17201720                    return child_row
    17211721            else: # negative
    1722                 if child_row.cases_ordered_claimed or child_row.units_ordered_claimed:
     1722                if child_row.cases_shipped_claimed or child_row.units_shipped_claimed:
    17231723                    return child_row
    17241724
Note: See TracChangeset for help on using the changeset viewer.