Remove logic for "receiving a row" and invoke handler instead
i.e. for receiving batch
This commit is contained in:
parent
a5df9a2b3d
commit
b1c77afc81
|
@ -1321,37 +1321,10 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
cases = update_form.validated['cases']
|
||||
units = update_form.validated['units']
|
||||
|
||||
# add values as-is to existing case/unit amounts. note
|
||||
# that this can sometimes give us negative values! e.g. if
|
||||
# user scans 1 CS and then subtracts 2 EA, then we would
|
||||
# have 1 / -2 for our counts. but we consider that to be
|
||||
# expected, and other logic must allow for the possibility
|
||||
if cases:
|
||||
setattr(row, 'cases_{}'.format(mode),
|
||||
(getattr(row, 'cases_{}'.format(mode)) or 0) + cases)
|
||||
if units:
|
||||
setattr(row, 'units_{}'.format(mode),
|
||||
(getattr(row, 'units_{}'.format(mode)) or 0) + units)
|
||||
|
||||
# if mode in ('damaged', 'expired', 'mispick'):
|
||||
if mode in ('damaged', 'expired'):
|
||||
self.attach_credit(row, mode, cases, units,
|
||||
expiration_date=update_form.validated['expiration_date'],
|
||||
# discarded=update_form.data['trash'],
|
||||
# mispick_product=shipped_product)
|
||||
)
|
||||
|
||||
# first undo any totals previously in effect for the row, then refresh
|
||||
if row.invoice_total:
|
||||
batch.invoice_total -= row.invoice_total
|
||||
self.handler.refresh_row(row)
|
||||
|
||||
# if current batch is a truck dump parent with "children last"
|
||||
# then we now must let handler "make claims" between them
|
||||
if (batch.is_truck_dump_parent()
|
||||
and batch.truck_dump_children_first
|
||||
and row.product):
|
||||
self.handler.make_truck_dump_claims_for_parent_row(row)
|
||||
# handler takes care of the row receiving logic for us
|
||||
kwargs = dict(update_form.validated)
|
||||
del kwargs['row']
|
||||
self.handler.receive_row(row, **kwargs)
|
||||
|
||||
# keep track of last-used uom, although we just track
|
||||
# whether or not it was 'CS' since the unit_uom can vary
|
||||
|
@ -1474,53 +1447,6 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
progress.session['success_url'] = success_url
|
||||
progress.session.save()
|
||||
|
||||
def attach_credit(self, row, credit_type, cases, units, expiration_date=None, discarded=None, mispick_product=None):
|
||||
batch = row.batch
|
||||
credit = model.PurchaseBatchCredit()
|
||||
credit.credit_type = credit_type
|
||||
credit.store = batch.store
|
||||
credit.vendor = batch.vendor
|
||||
credit.date_ordered = batch.date_ordered
|
||||
credit.date_shipped = batch.date_shipped
|
||||
credit.date_received = batch.date_received
|
||||
credit.invoice_number = batch.invoice_number
|
||||
credit.invoice_date = batch.invoice_date
|
||||
credit.product = row.product
|
||||
credit.upc = row.upc
|
||||
credit.vendor_item_code = row.vendor_code
|
||||
credit.brand_name = row.brand_name
|
||||
credit.description = row.description
|
||||
credit.size = row.size
|
||||
credit.department_number = row.department_number
|
||||
credit.department_name = row.department_name
|
||||
credit.case_quantity = row.case_quantity
|
||||
credit.cases_shorted = cases
|
||||
credit.units_shorted = units
|
||||
credit.invoice_line_number = row.invoice_line_number
|
||||
credit.invoice_case_cost = row.invoice_case_cost
|
||||
credit.invoice_unit_cost = row.invoice_unit_cost
|
||||
credit.invoice_total = row.invoice_total
|
||||
|
||||
# calculate credit total
|
||||
# TODO: should this leverage case cost if present?
|
||||
credit_units = self.handler.get_units(credit.cases_shorted,
|
||||
credit.units_shorted,
|
||||
credit.case_quantity)
|
||||
credit.credit_total = credit_units * (credit.invoice_unit_cost or 0)
|
||||
|
||||
credit.product_discarded = discarded
|
||||
if credit_type == 'expired':
|
||||
credit.expiration_date = expiration_date
|
||||
elif credit_type == 'mispick' and mispick_product:
|
||||
credit.mispick_product = mispick_product
|
||||
credit.mispick_upc = mispick_product.upc
|
||||
if mispick_product.brand:
|
||||
credit.mispick_brand_name = mispick_product.brand.name
|
||||
credit.mispick_description = mispick_product.description
|
||||
credit.mispick_size = mispick_product.size
|
||||
row.credits.append(credit)
|
||||
return credit
|
||||
|
||||
@classmethod
|
||||
def _receiving_defaults(cls, config):
|
||||
rattail_config = config.registry.settings.get('rattail_config')
|
||||
|
|
Loading…
Reference in a new issue