Refactor "receive row" and "declare credit" tools per buefy theme
This commit is contained in:
parent
ae76ceea04
commit
10e34b83ed
10 changed files with 313 additions and 89 deletions
|
@ -637,6 +637,11 @@ class PurchasingBatchView(BatchMasterView):
|
|||
g.set_label('catalog_unit_cost', "Catalog Cost")
|
||||
g.filters['catalog_unit_cost'].label = "Catalog Unit Cost"
|
||||
|
||||
# po_unit_cost
|
||||
g.set_renderer('po_unit_cost', self.render_row_grid_cost)
|
||||
g.set_label('po_unit_cost', "PO Cost")
|
||||
g.filters['po_unit_cost'].label = "PO Unit Cost"
|
||||
|
||||
# invoice_unit_cost
|
||||
g.set_renderer('invoice_unit_cost', self.render_row_grid_cost)
|
||||
g.set_label('invoice_unit_cost', "Invoice Cost")
|
||||
|
|
|
@ -144,6 +144,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'cases_received',
|
||||
'units_received',
|
||||
'catalog_unit_cost',
|
||||
'po_unit_cost',
|
||||
'invoice_unit_cost',
|
||||
'invoice_total_calculated',
|
||||
'credits',
|
||||
|
@ -152,6 +153,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
]
|
||||
|
||||
row_form_fields = [
|
||||
'sequence',
|
||||
'item_entry',
|
||||
'upc',
|
||||
'item_id',
|
||||
|
@ -487,6 +489,14 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if self.creating:
|
||||
f.remove('invoice_total_calculated')
|
||||
|
||||
# hide all invoice fields if batch does not have invoice file
|
||||
if not self.creating and not self.handler.has_invoice_file(batch):
|
||||
f.remove('invoice_file',
|
||||
'invoice_date',
|
||||
'invoice_number',
|
||||
'invoice_total',
|
||||
'invoice_total_calculated')
|
||||
|
||||
# receiving_complete
|
||||
if self.creating:
|
||||
f.remove('receiving_complete')
|
||||
|
@ -506,8 +516,12 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
elif workflow == 'from_po':
|
||||
f.remove('truck_dump_batch_uuid',
|
||||
'date_ordered',
|
||||
'po_number',
|
||||
'invoice_file',
|
||||
'invoice_parser_key')
|
||||
'invoice_parser_key',
|
||||
'invoice_date',
|
||||
'invoice_number')
|
||||
|
||||
elif workflow == 'from_po_with_invoice':
|
||||
f.remove('truck_dump_batch_uuid')
|
||||
|
@ -736,11 +750,25 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
def configure_row_grid(self, g):
|
||||
super(ReceivingBatchView, self).configure_row_grid(g)
|
||||
batch = self.get_instance()
|
||||
|
||||
# vendor_code
|
||||
g.filters['vendor_code'].default_active = True
|
||||
g.filters['vendor_code'].default_verb = 'contains'
|
||||
|
||||
# catalog_unit_cost
|
||||
if (self.handler.has_purchase_order(batch)
|
||||
or self.handler.has_invoice_file(batch)):
|
||||
g.remove('catalog_unit_cost')
|
||||
|
||||
# po_unit_cost
|
||||
if self.handler.has_invoice_file(batch):
|
||||
g.remove('po_unit_cost')
|
||||
|
||||
# invoice_unit_cost
|
||||
if not self.handler.has_invoice_file(batch):
|
||||
g.remove('invoice_unit_cost')
|
||||
|
||||
# credits
|
||||
# note that sorting by credits involves a subquery with group by clause.
|
||||
# seems likely there may be a better way? but this seems to work fine
|
||||
|
@ -753,7 +781,6 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
# hide 'ordered' columns for truck dump parent, if its "children first"
|
||||
# flag is set, since that batch type is only concerned with receiving
|
||||
batch = self.get_instance()
|
||||
if batch.is_truck_dump_parent() and not batch.truck_dump_children_first:
|
||||
g.remove('cases_ordered',
|
||||
'units_ordered')
|
||||
|
@ -788,6 +815,11 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
return css_class
|
||||
|
||||
def get_row_instance_title(self, row):
|
||||
if row.upc:
|
||||
return row.upc.pretty()
|
||||
return super(ReceivingBatchView, self).get_row_instance_title(row)
|
||||
|
||||
def transform_unit_url(self, row, i):
|
||||
# grid action is shown only when we return a URL here
|
||||
if self.row_editable(row):
|
||||
|
@ -795,6 +827,18 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if row.product and row.product.is_pack_item():
|
||||
return self.get_row_action_url('transform_unit', row)
|
||||
|
||||
def vuejs_convert_quantity(self, cstruct):
|
||||
result = dict(cstruct)
|
||||
if result['cases'] is colander.null:
|
||||
result['cases'] = None
|
||||
elif isinstance(result['cases'], decimal.Decimal):
|
||||
result['cases'] = float(result['cases'])
|
||||
if result['units'] is colander.null:
|
||||
result['units'] = None
|
||||
elif isinstance(result['units'], decimal.Decimal):
|
||||
result['units'] = float(result['units'])
|
||||
return result
|
||||
|
||||
def receive_row(self, **kwargs):
|
||||
"""
|
||||
Primary desktop view for row-level receiving.
|
||||
|
@ -830,14 +874,24 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
schema = ReceiveRowForm().bind(session=self.Session())
|
||||
form = forms.Form(schema=schema, request=self.request, use_buefy=use_buefy)
|
||||
form.cancel_url = self.get_row_action_url('view', row)
|
||||
|
||||
# mode
|
||||
mode_values = [(mode, mode) for mode in possible_modes]
|
||||
if use_buefy:
|
||||
form.set_widget('mode', dfwidget.SelectWidget(values=mode_values))
|
||||
mode_widget = dfwidget.SelectWidget(values=mode_values)
|
||||
else:
|
||||
form.set_widget('mode', forms.widgets.JQuerySelectWidget(values=mode_values))
|
||||
mode_widget = forms.widgets.JQuerySelectWidget(values=mode_values)
|
||||
form.set_widget('mode', mode_widget)
|
||||
|
||||
# quantity
|
||||
form.set_widget('quantity', forms.widgets.CasesUnitsWidget(amount_required=True,
|
||||
one_amount_only=True))
|
||||
form.set_vuejs_field_converter('quantity', self.vuejs_convert_quantity)
|
||||
|
||||
# expiration_date
|
||||
form.set_type('expiration_date', 'date_jquery')
|
||||
|
||||
# TODO: what is this one about again?
|
||||
form.remove_field('quick_receive')
|
||||
|
||||
if form.validate(newstyle=True):
|
||||
|
@ -946,6 +1000,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
View for declaring a credit, i.e. converting some "received" or similar
|
||||
quantity, to a credit of some sort.
|
||||
"""
|
||||
use_buefy = self.get_use_buefy()
|
||||
row = self.get_row_instance()
|
||||
batch = row.batch
|
||||
possible_credit_types = [
|
||||
|
@ -965,11 +1020,23 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
}
|
||||
|
||||
schema = DeclareCreditForm()
|
||||
form = forms.Form(schema=schema, request=self.request)
|
||||
form.set_widget('credit_type', forms.widgets.JQuerySelectWidget(
|
||||
values=[(m, m) for m in possible_credit_types]))
|
||||
form = forms.Form(schema=schema, request=self.request,
|
||||
use_buefy=use_buefy)
|
||||
|
||||
# credit_type
|
||||
values = [(m, m) for m in possible_credit_types]
|
||||
if use_buefy:
|
||||
widget = dfwidget.SelectWidget(values=values)
|
||||
else:
|
||||
widget = forms.widgets.JQuerySelectWidget(values=values)
|
||||
form.set_widget('credit_type', widget)
|
||||
|
||||
# quantity
|
||||
form.set_widget('quantity', forms.widgets.CasesUnitsWidget(
|
||||
amount_required=True, one_amount_only=True))
|
||||
form.set_vuejs_field_converter('quantity', self.vuejs_convert_quantity)
|
||||
|
||||
# expiration_date
|
||||
form.set_type('expiration_date', 'date_jquery')
|
||||
|
||||
if form.validate(newstyle=True):
|
||||
|
@ -1554,6 +1621,15 @@ class ReceiveRowForm(colander.MappingSchema):
|
|||
|
||||
quick_receive = colander.SchemaNode(colander.Boolean())
|
||||
|
||||
def deserialize(self, *args):
|
||||
result = super(ReceiveRowForm, self).deserialize(*args)
|
||||
|
||||
if result['mode'] == 'expired' and not result['expiration_date']:
|
||||
msg = "Expiration date is required for items with 'expired' mode."
|
||||
self.raise_invalid(msg, node=self.get('expiration_date'))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class DeclareCreditForm(colander.MappingSchema):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue