Changeset 4db05e9 in rattail


Ignore:
Timestamp:
07/10/18 12:38:23 (2 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
7ab16a0
Parents:
5100eed
Message:

Refactor truck dump "claiming" a bit, add "case quantity differs" status

Location:
rattail
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/purchase.py

    r5100eed r4db05e9  
    132132        truck_dump_by_product = {}
    133133        truck_dump_by_upc = {}
    134         for row in truck_dump_rows:
     134
     135        def organize_parent(row, i):
    135136            if row.product:
    136137                truck_dump_by_product.setdefault(row.product.uuid, []).append(row)
     
    138139                truck_dump_by_upc.setdefault(row.upc, []).append(row)
    139140
     141        self.progress_loop(organize_parent, truck_dump_rows, progress,
     142                           message="Organizing truck dump parent rows")
     143
    140144        # organize child batch by product and UPC
    141145        child_by_product = {}
    142146        child_by_upc = {}
    143         for row in child_rows:
     147
     148        def organize_child(row, i):
    144149            if row.product:
    145150                child_by_product.setdefault(row.product.uuid, []).append(row)
     
    147152                child_by_upc.setdefault(row.upc, []).append(row)
    148153
     154        self.progress_loop(organize_child, child_rows, progress,
     155                           message="Organizing truck dump child rows")
     156
    149157        # first pass looks only for exact product and quantity match
    150         for uuid, child_product_rows in six.iteritems(child_by_product):
     158        def first_pass(child_product, i):
     159            uuid, child_product_rows = child_product
    151160            if uuid not in truck_dump_by_product:
    152                 continue
     161                return
    153162
    154163            # inspect truck dump to find exact match on child 'ordered' count
     
    175184                        break
    176185
    177                 # maybe also look at the aggregate child counts
     186                # if no "exact" match, fall back to arbitrary matching where we can
    178187                if not matched_child_rows:
    179                     ordered = sum([self.get_units_ordered(row)
    180                                    for row in child_product_rows])
    181                     if ordered == available:
    182                         matched_child_rows = child_product_rows
     188                    matched_child_rows = child_product_rows
    183189
    184190                # did we find a match?
     
    212218                else:
    213219                    index += 1
     220
     221        self.progress_loop(first_pass, child_by_product.items(), progress,
     222                           message="Claiming parent rows for child") # (pass #1)
    214223
    215224        # TODO: second pass to look for inexact and UPC matches, yes?
     
    324333                    ordered -= total
    325334
    326                 if ordered:
    327                     raise NotImplementedError("TODO: can't yet handle match with mixture of received/damaged/expired (?)")
    328 
    329335            self.refresh_row(truck_dump_row)
    330336            claims.append(claim)
     
    413419            row.department_name = None
    414420        row.vendor_code = cost.code if cost else None
    415         new_case_quantity = cost.case_size if cost else None
    416         if new_case_quantity:
    417             row.case_quantity = new_case_quantity
     421
     422        case_quantity_differs = False
     423        if cost and cost.case_size:
     424            if not row.case_quantity:
     425                row.case_quantity = cost.case_size
     426            elif row.case_quantity != cost.case_size:
     427                if batch.truck_dump:
     428                    # always overwrite case quantity for truck dump, since its
     429                    # value should only come from master cost (right?)
     430                    row.case_quantity = cost.case_size
     431                else:
     432                    case_quantity_differs = True
    418433
    419434        self.refresh_totals(row, cost, initial)
     
    441456                        raise NotImplementedError
    442457                else: # not truck_dump
    443                     if self.get_units_ordered(row) != self.get_units_accounted_for(row):
     458                    if case_quantity_differs:
     459                        row.status_code = row.STATUS_CASE_QUANTITY_DIFFERS
     460                        row.status_text = "batch has {} but master cost has {}".format(
     461                            repr(row.case_quantity), repr(cost.case_size))
     462                    elif self.get_units_ordered(row) != self.get_units_accounted_for(row):
    444463                        row.status_code = row.STATUS_ORDERED_RECEIVED_DIFFER
    445464                    else:
  • rattail/db/model/batch/purchase.py

    r5100eed r4db05e9  
    139139    STATUS_TRUCKDUMP_CLAIMED            = 8
    140140    STATUS_TRUCKDUMP_OVERCLAIMED        = 9
     141    STATUS_CASE_QUANTITY_DIFFERS        = 10
    141142
    142143    STATUS = {
     
    145146        STATUS_COST_NOT_FOUND           : "product found but not cost",
    146147        STATUS_CASE_QUANTITY_UNKNOWN    : "case quantity not known",
     148        STATUS_CASE_QUANTITY_DIFFERS    : "case quantity differs",
    147149        STATUS_INCOMPLETE               : "incomplete",
    148150        STATUS_ORDERED_RECEIVED_DIFFER  : "ordered / received differ",
Note: See TracChangeset for help on using the changeset viewer.