Add "discarded" flag when receiving DMG/EXP products; add view for purchase credits

This commit is contained in:
Lance Edgar 2016-12-30 12:37:07 -06:00
parent 55973bf30a
commit e13e2cfaaf
3 changed files with 122 additions and 5 deletions

View file

@ -64,6 +64,7 @@ class ReceivingForm(forms.Schema):
cases = fe.validators.Number()
units = fe.validators.Number()
expiration_date = fe.validators.DateValidator()
trash = fe.validators.Bool()
ordered_product = forms.validators.ValidProduct()
@ -685,7 +686,7 @@ class PurchaseBatchView(BatchMasterView):
'batch_po_total': '${:0,.2f}'.format(batch.po_total),
}
def attach_credit(self, row, credit_type, cases, units, expiration_date=None, mispick_product=None):
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
@ -710,6 +711,7 @@ class PurchaseBatchView(BatchMasterView):
credit.invoice_case_cost = row.invoice_case_cost
credit.invoice_unit_cost = row.invoice_unit_cost
credit.invoice_total = row.invoice_total
credit.product_discarded = discarded
if credit_type == 'expired':
credit.expiration_date = expiration_date
elif credit_type == 'mispick' and mispick_product:
@ -768,6 +770,7 @@ class PurchaseBatchView(BatchMasterView):
if mode in ('damaged', 'expired', 'mispick'):
self.attach_credit(row, mode, cases, units,
expiration_date=form.data['expiration_date'],
discarded=form.data['trash'],
mispick_product=shipped_product)
self.handler.refresh_row(row)

View file

@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2016 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Views for "true" purchase credits
"""
from __future__ import unicode_literals, absolute_import
from rattail.db import model
from tailbone import forms
from tailbone.views import MasterView
class PurchaseCreditView(MasterView):
"""
Master view for purchase credits
"""
model_class = model.PurchaseCredit
route_prefix = 'purchases.credits'
url_prefix = '/purchases/credits'
creatable = False
editable = False
def _preconfigure_grid(self, g):
g.joiners['vendor'] = lambda q: q.outerjoin(model.Vendor)
g.sorters['vendor'] = g.make_sorter(model.Vendor.name)
g.default_sortkey = 'date_received'
g.default_sortdir = 'desc'
g.upc.set(label="UPC")
g.brand_name.set(label="Brand")
g.cases_shorted.set(label="Cases", renderer=forms.renderers.QuantityFieldRenderer)
g.units_shorted.set(label="Units", renderer=forms.renderers.QuantityFieldRenderer)
g.credit_type.set(label="Type")
g.date_received.set(label="Date")
def configure_grid(self, g):
g.configure(
include=[
g.vendor,
g.upc,
g.brand_name,
g.description,
g.size,
g.cases_shorted,
g.units_shorted,
g.credit_type,
g.date_received,
g.status,
],
readonly=True)
def includeme(config):
PurchaseCreditView.defaults(config)