Expose catalog cost, allow updating, for receiving batch rows
This commit is contained in:
parent
3e1409afc5
commit
675660e130
2 changed files with 162 additions and 42 deletions
|
@ -223,7 +223,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'units_shipped',
|
||||
'cases_received',
|
||||
'units_received',
|
||||
# 'po_total',
|
||||
'catalog_unit_cost',
|
||||
'invoice_unit_cost',
|
||||
'invoice_total_calculated',
|
||||
'credits',
|
||||
|
@ -789,9 +789,14 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
g.filters['vendor_code'].default_active = True
|
||||
g.filters['vendor_code'].default_verb = 'contains'
|
||||
|
||||
# catalog_unit_cost
|
||||
g.set_renderer('catalog_unit_cost', self.render_row_grid_cost)
|
||||
g.set_label('catalog_unit_cost', "Catalog Cost")
|
||||
g.filters['catalog_unit_cost'].label = "Catalog Unit Cost"
|
||||
|
||||
# invoice_unit_cost
|
||||
g.set_renderer('invoice_unit_cost', self.render_row_grid_unit_cost)
|
||||
g.set_label('invoice_unit_cost', "Unit Cost")
|
||||
g.set_renderer('invoice_unit_cost', self.render_row_grid_cost)
|
||||
g.set_label('invoice_unit_cost', "Invoice Cost")
|
||||
g.filters['invoice_unit_cost'].label = "Invoice Unit Cost"
|
||||
|
||||
# credits
|
||||
|
@ -833,12 +838,15 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
def row_grid_extra_class(self, row, i):
|
||||
css_class = super(ReceivingBatchView, self).row_grid_extra_class(row, i)
|
||||
|
||||
if row.catalog_cost_confirmed:
|
||||
css_class = '{} catalog_cost_confirmed'.format(css_class or '')
|
||||
|
||||
if row.invoice_cost_confirmed:
|
||||
css_class = '{} invoice_cost_confirmed'.format(css_class or '')
|
||||
|
||||
return css_class
|
||||
|
||||
def render_row_grid_unit_cost(self, row, field):
|
||||
def render_row_grid_cost(self, row, field):
|
||||
cost = getattr(row, field)
|
||||
if cost is None:
|
||||
return ""
|
||||
|
@ -1419,7 +1427,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
AJAX view for updating the invoice (actual) unit cost for a row.
|
||||
"""
|
||||
batch = self.get_instance()
|
||||
data = self.request.POST
|
||||
data = dict(self.request.POST)
|
||||
|
||||
# validate row
|
||||
uuid = data.get('row_uuid')
|
||||
|
@ -1427,20 +1435,26 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if not row or row.batch is not batch:
|
||||
return {'error': "Row not found"}
|
||||
|
||||
# validate cost
|
||||
cost = data.get('invoice_unit_cost')
|
||||
if cost is None:
|
||||
return {'error': "You must specify a cost"}
|
||||
try:
|
||||
cost = decimal.Decimal(six.text_type(cost))
|
||||
except decimal.InvalidOperation:
|
||||
return {'error': "Cost is not valid!"}
|
||||
# validate/normalize cost value(s)
|
||||
for field in ('catalog_unit_cost', 'invoice_unit_cost'):
|
||||
if field in data:
|
||||
cost = data[field]
|
||||
if cost == '':
|
||||
return {'error': "You must specify a cost"}
|
||||
try:
|
||||
cost = decimal.Decimal(six.text_type(cost))
|
||||
except decimal.InvalidOperation:
|
||||
return {'error': "Cost is not valid!"}
|
||||
else:
|
||||
data[field] = cost
|
||||
|
||||
# okay, update our row
|
||||
self.handler.update_row_cost(row, invoice_unit_cost=cost)
|
||||
self.handler.update_row_cost(row, **data)
|
||||
|
||||
return {
|
||||
'row': {
|
||||
'catalog_unit_cost': '{:0.3f}'.format(row.catalog_unit_cost),
|
||||
'catalog_cost_confirmed': row.catalog_cost_confirmed,
|
||||
'invoice_unit_cost': '{:0.3f}'.format(row.invoice_unit_cost),
|
||||
'invoice_cost_confirmed': row.invoice_cost_confirmed,
|
||||
'invoice_total_calculated': '{:0.2f}'.format(row.invoice_total_calculated),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue