Changeset 1242a5e in rattail


Ignore:
Timestamp:
03/07/19 18:57:04 (6 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
405a50b
Parents:
7b4d418
Message:

Fix how some "receive row" logic worked, for aggregated product rows

also fix the batch invoice total aggregation, hopefully

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/purchase.py

    r7b4d418 r1242a5e  
    179179                        if child_row.invoice_total:
    180180                            parent_row.invoice_total = (parent_row.invoice_total or 0) + child_row.invoice_total
     181                            parent_batch.invoice_total = (parent_batch.invoice_total or 0) + child_row.invoice_total
    181182                        if child_row.invoice_total_calculated:
    182183                            parent_row.invoice_total_calculated = (parent_row.invoice_total_calculated or 0) + child_row.invoice_total_calculated
     184                            parent_batch.invoice_total_calculated = (parent_batch.invoice_total_calculated or 0) + child_row.invoice_total_calculated
    183185
    184186                    else: # new product; simply add new row to parent
     
    10691071        # update calculated invoice totals if normal received amounts
    10701072        if mode == 'received':
     1073            # TODO: should round invoice amount to 2 places here?
    10711074            invoice_amount = 0
    10721075            if cases:
     
    13181321            if cases and units and (child_row.cases_ordered_pending
    13191322                                    and child_row.units_ordered_pending):
    1320                 update(child_row.cases_ordered_pending, child_row.units_ordered_pending)
    1321                 return (cases - child_row.cases_ordered_pending,
    1322                         units - child_row.units_ordered_pending)
     1323                pending = (child_row.cases_ordered_pending,
     1324                           child_row.units_ordered_pending)
     1325                update(pending[0], pending[1])
     1326                return cases - pending[0], units - pending[1]
    13231327            if cases and child_row.cases_ordered_pending:
    1324                 update(child_row.cases_ordered_pending, 0)
    1325                 return cases - child_row.cases_ordered_pending, 0
     1328                pending = child_row.cases_ordered_pending
     1329                update(pending, 0)
     1330                return cases - pending, 0
    13261331            if units and child_row.units_ordered_pending:
    1327                 update(0, child_row.units_ordered_pending)
    1328                 return 0, units - child_row.units_ordered_pending
     1332                pending = child_row.units_ordered_pending
     1333                update(0, pending)
     1334                return 0, units - pending
    13291335        else: # negative
    13301336            if cases and units and (child_row.cases_ordered_claimed
    13311337                                    and child_row.units_ordered_claimed):
    1332                 update(-child_row.cases_ordered_claimed, -child_row.units_ordered_claimed)
    1333                 return (cases + child_row.cases_ordered_claimed,
    1334                         units + child_row.units_ordered_claimed)
     1338                claimed = (child_row.cases_ordered_claimed,
     1339                           child_row.units_ordered_claimed)
     1340                update(-claimed[0], -claimed[1])
     1341                return cases + claimed[0], units + claimed[1]
    13351342            if cases and child_row.cases_ordered_claimed:
    1336                 update(-child_row.cases_ordered_claimed, 0)
    1337                 return cases + child_row.cases_ordered_claimed, 0
     1343                claimed = child_row.cases_ordered_claimed
     1344                update(-claimed, 0)
     1345                return cases + claimed, 0
    13381346            if units and child_row.units_ordered_claimed:
    1339                 update(0, -child_row.units_ordered_claimed)
    1340                 return 0, units + child_row.units_ordered_claimed
     1347                claimed = child_row.units_ordered_claimed
     1348                update(0, -claimed)
     1349                return 0, units + claimed
    13411350
    13421351        # looks like we're gonna have to split some cases, one way or another
     
    13541363                        return cases - unit_cases, units
    13551364                else: # units_pending < case_size
    1356                     update(0, child_row.units_ordered_pending)
     1365                    pending = child_row.units_ordered_pending
     1366                    update(0, pending)
    13571367                    return (cases - 1,
    1358                             (units or 0) + parent_row.case_quantity - child_row.units_ordered_pending)
     1368                            (units or 0) + parent_row.case_quantity - pending)
    13591369            if units and child_row.cases_ordered_pending:
    13601370                if units >= parent_row.case_quantity:
     
    13641374                        return 0, units - (unit_cases * parent_row.case_quantity)
    13651375                    else: # unit_cases > cases_pending
    1366                         update(child_row.cases_ordered_pending, 0)
    1367                         return 0, units - (child_row.cases_ordered_pending * parent_row.case_quantity)
     1376                        pending = child_row.cases_ordered_pending
     1377                        update(pending, 0)
     1378                        return 0, units - (pending * parent_row.case_quantity)
    13681379                else: # units < case_size
    13691380                    update(0, units)
     
    13801391                        return cases + unit_cases, units
    13811392                else: # units_claimed < case_size
    1382                     update(0, -child_row.units_ordered_claimed)
     1393                    claimed = child_row.units_ordered_claimed
     1394                    update(0, -claimed)
    13831395                    return (cases + 1,
    1384                             (units or 0) - parent_row.case_quantity + child_row.units_ordered_claimed)
     1396                            (units or 0) - parent_row.case_quantity + claimed)
    13851397            if units and child_row.cases_ordered_claimed:
    13861398                if -units >= parent_row.case_quantity:
     
    13901402                        return 0, units + (unit_cases * parent_row.case_quantity)
    13911403                    else: # unit_cases > cases_claimed
    1392                         update(-child_row.cases_ordered_claimed, 0)
    1393                         return 0, units + (child_row.cases_ordered_claimed * parent_row.case_quantity)
     1404                        claimed = child_row.cases_ordered_claimed
     1405                        update(-claimed, 0)
     1406                        return 0, units + (claimed * parent_row.case_quantity)
    13941407                else: # -units < case_size
    13951408                    update(0, units)
Note: See TracChangeset for help on using the changeset viewer.