Changeset 7447357 in rattail


Ignore:
Timestamp:
03/27/19 21:04:19 (6 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
850c197
Parents:
3746c1b
Message:

Add can_declare_credit() method for purchase batch handler

only relevant for receiving batches? anyway needed for validating such an
action, prior to actually taking it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/purchase.py

    r3746c1b r7447357  
    980980                self.enum.PURCHASE_BATCH_MODE.get(batch.mode, "unknown ({})".format(batch.mode))))
    981981
     982    def can_declare_credit(self, row, credit_type='received', cases=None, units=None, **kwargs):
     983        """
     984        This method should be used to validate a potential declaration of
     985        credit, i.e. call this before calling :meth:`declare_credit()`.  See
     986        the latter for call signature documentation, as they are the same.
     987
     988        This method will use similar logic to confirm the proposed credit is
     989        valid, i.e. there is sufficient "received" quantity in place for it.
     990        """
     991        # make sure we have cases *or* units
     992        if not (cases or units):
     993            raise ValueError("must provide amount for cases *or* units")
     994        if cases and units:
     995            raise ValueError("must provide amount for cases *or* units (but not both)")
     996        if cases and cases < 0:
     997            raise ValueError("must provide *positive* amount for cases")
     998        if units and units < 0:
     999            raise ValueError("must provide *positive* amount for units")
     1000
     1001        # make sure we have a (non-executed) receiving batch
     1002        if row.batch.mode != self.enum.PURCHASE_BATCH_MODE_RECEIVING:
     1003            raise NotImplementedError("receive_row() is only for receiving batches")
     1004        if row.batch.executed:
     1005            raise NotImplementedError("receive_row() is only for *non-executed* batches")
     1006
     1007        if cases:
     1008            if row.cases_received and row.cases_received >= cases:
     1009                return True
     1010
     1011            if row.units_received:
     1012                units = cases * row.case_quantity
     1013                if row.units_received >= units:
     1014                    return True
     1015
     1016        if units:
     1017            if row.units_received and row.units_received >= units:
     1018                return True
     1019
     1020            if row.cases_received:
     1021                cases = units // row.case_quantity
     1022                if units % row.case_quantity:
     1023                    cases += 1
     1024                if row.cases_received >= cases:
     1025                    return True
     1026
     1027        raise ValueError("credit amount must be <= 'received' amount for the row")
     1028
    9821029    def declare_credit(self, row, credit_type='received', cases=None, units=None, **kwargs):
    9831030        """
     
    15511598                # TODO: should consult config to determine which product key to match on
    15521599                child_rows = [child_row for child_row in child_batch.active_rows()
    1553                               if not child.product_uuid and child_row.upc == parent_row.upc]
     1600                              if not child_row.product_uuid and child_row.upc == parent_row.upc]
    15541601
    15551602            for child_row in child_rows:
Note: See TracChangeset for help on using the changeset viewer.