Add support for editing catalog cost in receiving batch, per new theme

had to add several "under the hood" features to make this work, to
embed a Vue component within grid `<td>` cells, etc.
This commit is contained in:
Lance Edgar 2022-12-05 14:03:03 -06:00
parent ec71f532a1
commit 2e3823364c
7 changed files with 296 additions and 27 deletions

View file

@ -46,6 +46,7 @@ from pyramid import httpexceptions
from webhelpers2.html import tags, HTML
from tailbone import forms, grids
from tailbone.util import get_form_data
from tailbone.views.purchasing import PurchasingBatchView
@ -715,6 +716,11 @@ class ReceivingBatchView(PurchasingBatchView):
return breakdown
def allow_edit_catalog_unit_cost(self, batch):
return (not batch.executed
and self.has_perm('edit_row')
and self.batch_handler.allow_receiving_edit_catalog_unit_cost())
def template_kwargs_view(self, **kwargs):
kwargs = super(ReceivingBatchView, self).template_kwargs_view(**kwargs)
batch = kwargs['instance']
@ -739,6 +745,8 @@ class ReceivingBatchView(PurchasingBatchView):
data=breakdown,
columns=['title', 'count'])
kwargs['allow_edit_catalog_unit_cost'] = self.allow_edit_catalog_unit_cost(batch)
return kwargs
def get_context_credits(self, row):
@ -933,6 +941,7 @@ class ReceivingBatchView(PurchasingBatchView):
def configure_row_grid(self, g):
super(ReceivingBatchView, self).configure_row_grid(g)
use_buefy = self.get_use_buefy()
batch = self.get_instance()
# vendor_code
@ -943,6 +952,10 @@ class ReceivingBatchView(PurchasingBatchView):
if (self.handler.has_purchase_order(batch)
or self.handler.has_invoice_file(batch)):
g.remove('catalog_unit_cost')
elif use_buefy and self.allow_edit_catalog_unit_cost(batch):
g.set_raw_renderer('catalog_unit_cost', self.render_catalog_unit_cost)
g.set_click_handler('catalog_unit_cost',
'catalogUnitCostClicked(props.row)')
# po_unit_cost
if self.handler.has_invoice_file(batch):
@ -1001,6 +1014,14 @@ class ReceivingBatchView(PurchasingBatchView):
else:
g.set_enum('truck_dump_status', model.PurchaseBatchRow.STATUS)
def render_catalog_unit_cost(self):
return HTML.tag('receiving-cost-editor', **{
'v-model': 'props.row.catalog_unit_cost',
':ref': "'catalogUnitCost_' + props.row.uuid",
':row': 'props.row',
'@input': 'catalogCostConfirmed',
})
def row_grid_extra_class(self, row, i):
css_class = super(ReceivingBatchView, self).row_grid_extra_class(row, i)
@ -1790,10 +1811,10 @@ class ReceivingBatchView(PurchasingBatchView):
def update_row_cost(self):
"""
AJAX view for updating the invoice (actual) unit cost for a row.
AJAX view for updating various cost fields in a data row.
"""
batch = self.get_instance()
data = dict(self.request.POST)
data = dict(get_form_data(self.request))
# validate row
uuid = data.get('row_uuid')
@ -1939,6 +1960,9 @@ class ReceivingBatchView(PurchasingBatchView):
{'section': 'rattail.batch',
'option': 'purchase.receiving.should_autofix_invoice_case_vs_unit',
'type': bool},
{'section': 'rattail.batch',
'option': 'purchase.receiving.allow_edit_catalog_unit_cost',
'type': bool},
# mobile interface
{'section': 'rattail.batch',