Refactor purchase views per master4

This commit is contained in:
Lance Edgar 2018-02-04 12:04:27 -06:00
parent 7cee515187
commit 533b491124

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar # Copyright © 2010-2018 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -28,12 +28,10 @@ from __future__ import unicode_literals, absolute_import
from rattail.db import model from rattail.db import model
import formalchemy as fa
from webhelpers2.html import HTML, tags from webhelpers2.html import HTML, tags
from tailbone import forms
from tailbone.db import Session from tailbone.db import Session
from tailbone.views import MasterView3 as MasterView from tailbone.views import MasterView4 as MasterView
class PurchaseView(MasterView): class PurchaseView(MasterView):
@ -77,6 +75,13 @@ class PurchaseView(MasterView):
'batches', 'batches',
] ]
row_labels = {
'vendor_code': "Vendor Item Code",
'upc': "UPC",
'po_unit_cost': "PO Unit Cost",
'po_total': "PO Total",
}
row_grid_columns = [ row_grid_columns = [
'sequence', 'sequence',
'upc', 'upc',
@ -92,6 +97,27 @@ class PurchaseView(MasterView):
'invoice_total', 'invoice_total',
] ]
row_form_fields = [
'sequence',
'vendor_code',
'upc',
'product',
'department',
'case_quantity',
'cases_ordered',
'units_ordered',
'cases_received',
'units_received',
'cases_damaged',
'units_damaged',
'cases_expired',
'units_expired',
'po_unit_cost',
'po_total',
'invoice_unit_cost',
'invoice_total',
]
def get_instance_title(self, purchase): def get_instance_title(self, purchase):
if purchase.status >= self.enum.PURCHASE_STATUS_COSTED: if purchase.status >= self.enum.PURCHASE_STATUS_COSTED:
if purchase.invoice_date: if purchase.invoice_date:
@ -268,38 +294,20 @@ class PurchaseView(MasterView):
self.enum.PURCHASE_STATUS_COSTED): self.enum.PURCHASE_STATUS_COSTED):
g.hide_column('po_total') g.hide_column('po_total')
def _preconfigure_row_fieldset(self, fs): def configure_row_form(self, f):
fs.vendor_code.set(label="Vendor Item Code") super(PurchaseView, self).configure_row_form(f)
fs.upc.set(label="UPC")
fs.po_unit_cost.set(label="PO Unit Cost", renderer=forms.renderers.CurrencyFieldRenderer)
fs.po_total.set(label="PO Total", renderer=forms.renderers.CurrencyFieldRenderer)
fs.invoice_unit_cost.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.invoice_total.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.append(fa.Field('department', value=lambda i: '{} {}'.format(i.department_number, i.department_name)))
def configure_row_fieldset(self, fs): # currency fields
f.set_type('po_unit_cost', 'currency')
f.set_type('po_total', 'currency')
f.set_type('invoice_unit_cost', 'currency')
f.set_type('invoice_total', 'currency')
fs.configure( # department
include=[ f.set_renderer('department', self.render_row_department)
fs.sequence,
fs.vendor_code, def render_row_department(self, row, field):
fs.upc, return "{} {}".format(row.department_number, row.department_name)
fs.product,
fs.department,
fs.case_quantity,
fs.cases_ordered,
fs.units_ordered,
fs.cases_received,
fs.units_received,
fs.cases_damaged,
fs.units_damaged,
fs.cases_expired,
fs.units_expired,
fs.po_unit_cost,
fs.po_total,
fs.invoice_unit_cost,
fs.invoice_total,
])
def receiving_worksheet(self): def receiving_worksheet(self):
purchase = self.get_instance() purchase = self.get_instance()