Changeset 3336da3 in rattail


Ignore:
Timestamp:
02/18/19 18:19:11 (7 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
874cbc4
Parents:
0bf04a7
Message:

Aggregate when adding truck dump child row already present in parent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/purchase.py

    r0bf04a7 r3336da3  
    135135            def append(child_row, i):
    136136                if not child_row.out_of_stock:
     137
     138                    # if row for this product already exists in parent, must aggregate
    137139                    parent_row = self.locate_parent_row_for_child(parent_batch, child_row)
    138140                    if parent_row:
    139                         raise NotImplementedError("TODO: add some aggregation logic")
    140                     else:
     141
     142                        # confirm 'case_quantity' matches
     143                        if parent_row.case_quantity != child_row.case_quantity:
     144                            raise ValueError("differing 'case_quantity' for item {}: {}".format(
     145                                child_row.item_entry, child_row.description))
     146
     147                        # confirm 'out_of_stock' matches
     148                        if parent_row.out_of_stock != child_row.out_of_stock:
     149                            raise ValueError("differing 'out_of_stock' for item {}: {}".format(
     150                                cihld_row.item_entry, child_row.description))
     151
     152                        # confirm 'invoice_unit_cost' matches
     153                        if parent_row.invoice_unit_cost != child_row.invoice_unit_cost:
     154                            raise ValueError("differing 'invoice_unit_cost' for item {}: {}".format(
     155                                cihld_row.item_entry, child_row.description))
     156
     157                        # confirm 'invoice_case_cost' matches
     158                        if parent_row.invoice_case_cost != child_row.invoice_case_cost:
     159                            raise ValueError("differing 'invoice_case_cost' for item {}: {}".format(
     160                                cihld_row.item_entry, child_row.description))
     161
     162                        # add 'ordered' quantities
     163                        if child_row.cases_ordered:
     164                            parent_row.cases_ordered = (parent_row.cases_ordered or 0) + child_row.cases_ordered
     165                        if child_row.units_ordered:
     166                            parent_row.units_ordered = (parent_row.units_ordered or 0) + child_row.units_ordered
     167
     168                        # add 'shipped' quantities
     169                        if child_row.cases_shipped:
     170                            parent_row.cases_shipped = (parent_row.cases_shipped or 0) + child_row.cases_shipped
     171                        if child_row.units_shipped:
     172                            parent_row.units_shipped = (parent_row.units_shipped or 0) + child_row.units_shipped
     173
     174                        # add 'invoice_total' quantities
     175                        if child_row.invoice_total:
     176                            parent_row.invoice_total = (parent_row.invoice_total or 0) + child_row.invoice_total
     177
     178                    else: # new product; simply add new row to parent
    141179                        parent_row = self.make_parent_row_from_child(child_row)
    142180                        self.add_row(parent_batch, parent_row)
Note: See TracChangeset for help on using the changeset viewer.