diff --git a/tailbone/templates/receiving/view.mako b/tailbone/templates/receiving/view.mako index f6b3205a..30bfd3a9 100644 --- a/tailbone/templates/receiving/view.mako +++ b/tailbone/templates/receiving/view.mako @@ -199,7 +199,9 @@ }, 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.$nextTick(() => { this.$refs.input.focus() diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 23bb27fe..0cef3a37 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -989,12 +989,14 @@ class ReceivingBatchView(PurchasingBatchView): g.filters['vendor_code'].default_verb = 'contains' # catalog_unit_cost + g.set_renderer('catalog_unit_cost', self.render_simple_unit_cost) if 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', 'this.catalogUnitCostClicked') # invoice_unit_cost + g.set_renderer('invoice_unit_cost', self.render_simple_unit_cost) if self.allow_edit_invoice_unit_cost(batch): g.set_raw_renderer('invoice_unit_cost', self.render_invoice_unit_cost) g.set_click_handler('invoice_unit_cost', @@ -1049,6 +1051,19 @@ class ReceivingBatchView(PurchasingBatchView): else: 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): return HTML.tag('receiving-cost-editor', **{ 'field': 'catalog_unit_cost', @@ -1871,11 +1886,13 @@ class ReceivingBatchView(PurchasingBatchView): # okay, update our row self.handler.update_row_cost(row, **data) + self.Session.flush() + self.Session.refresh(row) return { '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, - '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_total_calculated': '{:0.2f}'.format(row.invoice_total_calculated), },