Tweaks for cost editing within a receiving batch

never show PO Cost column in row grid, since Invoice Cost is what
receiving is most concerned with

add "zig-zag" entry behavior when both catalog and invoice costs are editable
This commit is contained in:
Lance Edgar 2023-09-02 11:39:49 -05:00
parent 75caface6b
commit bd7e6f9f8a
2 changed files with 44 additions and 47 deletions

View file

@ -177,6 +177,7 @@
let ReceivingCostEditor = {
template: '#receiving-cost-editor-template',
mixins: [SimpleRequestMixin],
props: {
row: Object,
'field': String,
@ -232,41 +233,21 @@
submitEdit() {
let url = '${url('{}.update_row_cost'.format(route_prefix), uuid=batch.uuid)}'
// TODO: should get csrf token from parent component?
let csrftoken = ${json.dumps(request.session.get_csrf_token() or request.session.new_csrf_token())|n}
let headers = {'${csrf_header_name}': csrftoken}
let params = {
row_uuid: this.$props.row.uuid,
}
params[this.$props.field] = this.inputValue
this.$http.post(url, params, {headers: headers}).then(response => {
if (!response.data.error) {
this.simplePOST(url, params, response => {
// let parent know cost value has changed
// (this in turn will update data in *this*
// component, and display will refresh)
this.$emit('input', response.data.row[this.$props.field],
this.$props.row._index)
// let parent know cost value has changed
// (this in turn will update data in *this*
// component, and display will refresh)
this.$emit('input', response.data.row[this.$props.field],
this.$props.row._index)
// and hide the input box
this.editing = false
} else {
this.$buefy.toast.open({
message: "Submit failed: " + response.data.error,
type: 'is-warning',
duration: 4000, // 4 seconds
})
}
}, response => {
this.$buefy.toast.open({
message: "Submit failed: (unknown error)",
type: 'is-warning',
duration: 4000, // 4 seconds
})
// and hide the input box
this.editing = false
})
},
},
@ -289,11 +270,23 @@
// update display to indicate cost was confirmed
this.addRowClass(index, 'catalog_cost_confirmed')
// start editing next row, unless there are no more
let nextRow = index + 1
if (this.data.length > nextRow) {
nextRow = this.data[nextRow]
this.$refs['catalogUnitCost_' + nextRow.uuid].startEdit()
// advance to next editable cost input...
// first try invoice cost within same row
let thisRow = this.data[index]
let cost = this.$refs['invoiceUnitCost_' + thisRow.uuid]
if (!cost) {
// or, try catalog cost from next row
let nextRow = this.data[index + 1]
if (nextRow) {
cost = this.$refs['catalogUnitCost_' + nextRow.uuid]
}
}
// start editing next cost if found
if (cost) {
cost.startEdit()
}
}
@ -312,11 +305,24 @@
// update display to indicate cost was confirmed
this.addRowClass(index, 'invoice_cost_confirmed')
// start editing next row, unless there are no more
let nextRow = index + 1
if (this.data.length > nextRow) {
nextRow = this.data[nextRow]
this.$refs['invoiceUnitCost_' + nextRow.uuid].startEdit()
// advance to next editable cost input...
// nb. always advance to next row, regardless of field
let nextRow = this.data[index + 1]
if (nextRow) {
// first try catalog cost from next row
let cost = this.$refs['catalogUnitCost_' + nextRow.uuid]
if (!cost) {
// or, try invoice cost from next row
cost = this.$refs['invoiceUnitCost_' + nextRow.uuid]
}
// start editing next cost if found
if (cost) {
cost.startEdit()
}
}
}

View file

@ -162,7 +162,6 @@ class ReceivingBatchView(PurchasingBatchView):
'cases_received',
'units_received',
'catalog_unit_cost',
'po_unit_cost',
'invoice_unit_cost',
'invoice_total_calculated',
'credits',
@ -979,14 +978,6 @@ class ReceivingBatchView(PurchasingBatchView):
g.set_click_handler('invoice_unit_cost',
'this.invoiceUnitCostClicked')
# nb. only show PO *or* invoice cost; prefer the latter unless
# we have a PO and no invoice
if (self.batch_handler.has_purchase_order(batch)
and not self.batch_handler.has_invoice_file(batch)):
g.remove('invoice_unit_cost')
else:
g.remove('po_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