Show catalog/invoice costs as 2-decimal currency in receiving

This commit is contained in:
Lance Edgar 2023-09-19 15:03:16 -05:00
parent 8b15f1304f
commit 510b8383a4
2 changed files with 22 additions and 3 deletions

View file

@ -199,7 +199,9 @@
}, },
startEdit() { startEdit() {
this.inputValue = this.value // nb. must strip $ sign etc. to get the real value
let value = this.value.replace(/[^\-\d\.]/g, '')
this.inputValue = parseFloat(value) || null
this.editing = true this.editing = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.input.focus() this.$refs.input.focus()

View file

@ -989,12 +989,14 @@ class ReceivingBatchView(PurchasingBatchView):
g.filters['vendor_code'].default_verb = 'contains' g.filters['vendor_code'].default_verb = 'contains'
# catalog_unit_cost # catalog_unit_cost
g.set_renderer('catalog_unit_cost', self.render_simple_unit_cost)
if self.allow_edit_catalog_unit_cost(batch): if self.allow_edit_catalog_unit_cost(batch):
g.set_raw_renderer('catalog_unit_cost', self.render_catalog_unit_cost) g.set_raw_renderer('catalog_unit_cost', self.render_catalog_unit_cost)
g.set_click_handler('catalog_unit_cost', g.set_click_handler('catalog_unit_cost',
'this.catalogUnitCostClicked') 'this.catalogUnitCostClicked')
# invoice_unit_cost # invoice_unit_cost
g.set_renderer('invoice_unit_cost', self.render_simple_unit_cost)
if self.allow_edit_invoice_unit_cost(batch): if self.allow_edit_invoice_unit_cost(batch):
g.set_raw_renderer('invoice_unit_cost', self.render_invoice_unit_cost) g.set_raw_renderer('invoice_unit_cost', self.render_invoice_unit_cost)
g.set_click_handler('invoice_unit_cost', g.set_click_handler('invoice_unit_cost',
@ -1049,6 +1051,19 @@ class ReceivingBatchView(PurchasingBatchView):
else: else:
g.set_enum('truck_dump_status', model.PurchaseBatchRow.STATUS) g.set_enum('truck_dump_status', model.PurchaseBatchRow.STATUS)
def render_simple_unit_cost(self, row, field):
value = getattr(row, field)
if value is None:
return
# TODO: if anyone ever wants to see "raw" costs displayed,
# should make this configurable, b/c some folks already wanted
# the shorter 2-decimal display
#return str(value)
app = self.get_rattail_app()
return app.render_currency(value)
def render_catalog_unit_cost(self): def render_catalog_unit_cost(self):
return HTML.tag('receiving-cost-editor', **{ return HTML.tag('receiving-cost-editor', **{
'field': 'catalog_unit_cost', 'field': 'catalog_unit_cost',
@ -1871,11 +1886,13 @@ class ReceivingBatchView(PurchasingBatchView):
# okay, update our row # okay, update our row
self.handler.update_row_cost(row, **data) self.handler.update_row_cost(row, **data)
self.Session.flush()
self.Session.refresh(row)
return { return {
'row': { 'row': {
'catalog_unit_cost': '{:0.3f}'.format(row.catalog_unit_cost), 'catalog_unit_cost': self.render_simple_unit_cost(row, 'catalog_unit_cost'),
'catalog_cost_confirmed': row.catalog_cost_confirmed, 'catalog_cost_confirmed': row.catalog_cost_confirmed,
'invoice_unit_cost': '{:0.3f}'.format(row.invoice_unit_cost), 'invoice_unit_cost': self.render_simple_unit_cost(row, 'invoice_unit_cost'),
'invoice_cost_confirmed': row.invoice_cost_confirmed, 'invoice_cost_confirmed': row.invoice_cost_confirmed,
'invoice_total_calculated': '{:0.2f}'.format(row.invoice_total_calculated), 'invoice_total_calculated': '{:0.2f}'.format(row.invoice_total_calculated),
}, },