Changeset 6927d74 in rattail


Ignore:
Timestamp:
03/07/19 12:20:33 (7 weeks ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
7b4d418
Parents:
2cb67eb
git-author:
Lance Edgar <ledgar@…> (03/07/19 12:20:00)
git-committer:
Lance Edgar <ledgar@…> (03/07/19 12:20:33)
Message:

Fix logic for calculating "credit total"

also copy receiving date from truck dump parent to child, and fix output of
str(PurchaseCredit)

Location:
rattail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/purchase.py

    r2cb67eb r6927d74  
    7474                                                 self.enum.PURCHASE_BATCH_MODE_COSTING)
    7575        batch.order_quantities_known = True
     76
     77        # maybe copy receiving date from parent
     78        if batch.is_truck_dump_child() and not batch.date_received:
     79            batch.date_received = batch.truck_dump_batch.date_received
    7680
    7781        def append(item, i):
     
    11091113        self.populate_credit(credit, row)
    11101114        credit.credit_type = mode
    1111         credit.cases_shorted = cases
    1112         credit.units_shorted = units
     1115        credit.cases_shorted = cases or None
     1116        credit.units_shorted = units or None
     1117
     1118        # calculate credit total
     1119        # TODO: should this leverage case cost if present?
     1120        credit_units = self.get_units(credit.cases_shorted,
     1121                                      credit.units_shorted,
     1122                                      credit.case_quantity)
     1123        credit.credit_total = credit_units * (credit.invoice_unit_cost or 0)
    11131124
    11141125        # apply other attributes to credit, per caller kwargs
     
    11541165        credit.invoice_unit_cost = row.invoice_unit_cost
    11551166        credit.invoice_total = row.invoice_total
    1156 
    1157         # calculate credit total
    1158         # TODO: should this leverage case cost if present?
    1159         credit_units = self.get_units(credit.cases_shorted,
    1160                                       credit.units_shorted,
    1161                                       credit.case_quantity)
    1162         credit.credit_total = credit_units * (credit.invoice_unit_cost or 0)
    11631167
    11641168    def receiving_update_row_children(self, row, mode, cases, units, **kwargs):
     
    18331837                    credit.cases_shorted = cases or None
    18341838                    credit.units_shorted = units or None
     1839
     1840                    # calculate credit total
     1841                    # TODO: should this leverage case cost if present?
     1842                    credit_units = self.get_units(credit.cases_shorted,
     1843                                                  credit.units_shorted,
     1844                                                  credit.case_quantity)
     1845                    credit.credit_total = credit_units * (credit.invoice_unit_cost or 0)
     1846
    18351847                    credit.status = self.enum.PURCHASE_CREDIT_STATUS_NEW
    18361848                    if not credit.date_received:
  • rattail/db/model/batch/purchase.py

    r2cb67eb r6927d74  
    33#
    44#  Rattail -- Retail Software Framework
    5 #  Copyright © 2010-2018 Lance Edgar
     5#  Copyright © 2010-2019 Lance Edgar
    66#
    77#  This file is part of Rattail.
     
    3636                              Purchase, PurchaseItem)
    3737from rattail.db.core import uuid_column, filename_column
    38 from rattail.util import pretty_quantity
    3938
    4039
     
    332331
    333332
    334 @six.python_2_unicode_compatible
    335333class PurchaseBatchCredit(PurchaseCreditBase, Base):
    336334    """
     
    359357            List of :class:`PurchaseBatchCredit` instances for the row.
    360358            """))
    361 
    362     def __str__(self):
    363         if self.cases_shorted is not None and self.units_shorted is not None:
    364             qty = "{} cases, {} units".format(
    365                 pretty_quantity(self.cases_shorted),
    366                 pretty_quantity(self.units_shorted))
    367         elif self.cases_shorted is not None:
    368             qty = "{} cases".format(pretty_quantity(self.cases_shorted))
    369         elif self.units_shorted is not None:
    370             qty = "{} units".format(pretty_quantity(self.units_shorted))
    371         else:
    372             qty = "??"
    373         qty += " {}".format(self.credit_type)
    374         if self.credit_type == 'expired' and self.expiration_date:
    375             qty += " ({})".format(self.expiration_date)
    376         if self.credit_type == 'mispick' and self.mispick_product:
    377             qty += " ({})".format(self.mispick_product)
    378         if self.invoice_total:
    379             return "{} = ${:0.2f}".format(qty, self.invoice_total)
    380         return qty
  • rattail/db/model/purchase.py

    r2cb67eb r6927d74  
    3636from rattail.db.model import Base, uuid_column, Store, Department, Vendor, Employee, User, Product
    3737from rattail.db.types import GPCType
     38from rattail.util import pretty_quantity
    3839
    3940
     
    298299
    299300
     301@six.python_2_unicode_compatible
    300302class PurchaseCreditBase(object):
    301303    """
     
    467469    """)
    468470
     471    def __str__(self):
     472        if self.cases_shorted is not None and self.units_shorted is not None:
     473            qty = "{} cases, {} units".format(
     474                pretty_quantity(self.cases_shorted),
     475                pretty_quantity(self.units_shorted))
     476        elif self.cases_shorted is not None:
     477            qty = "{} cases".format(pretty_quantity(self.cases_shorted))
     478        elif self.units_shorted is not None:
     479            qty = "{} units".format(pretty_quantity(self.units_shorted))
     480        else:
     481            qty = "??"
     482        qty += " {}".format(self.credit_type)
     483        if self.credit_type == 'expired' and self.expiration_date:
     484            qty += " ({})".format(self.expiration_date)
     485        if self.credit_type == 'mispick' and self.mispick_product:
     486            qty += " ({})".format(self.mispick_product)
     487        if self.invoice_total:
     488            return "{} = ${:0.2f}".format(qty, self.invoice_total)
     489        return qty
     490
    469491
    470492class Purchase(PurchaseBase, Base):
Note: See TracChangeset for help on using the changeset viewer.