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

This commit is contained in:
Lance Edgar 2022-12-05 16:25:55 -06:00
parent 36a5f2ab49
commit cceb66e500
3 changed files with 85 additions and 16 deletions

View file

@ -133,6 +133,15 @@
</b-checkbox> </b-checkbox>
</b-field> </b-field>
<b-field>
<b-checkbox name="rattail.batch.purchase.receiving.allow_edit_invoice_unit_cost"
v-model="simpleSettings['rattail.batch.purchase.receiving.allow_edit_invoice_unit_cost']"
native-value="true"
@input="settingsNeedSaved = true">
Allow edit of Invoice Unit Cost
</b-checkbox>
</b-field>
</div> </div>
<h3 class="block is-size-3">Mobile Interface</h3> <h3 class="block is-size-3">Mobile Interface</h3>

View file

@ -264,19 +264,26 @@
<%def name="extra_styles()"> <%def name="extra_styles()">
${parent.extra_styles()} ${parent.extra_styles()}
% if use_buefy and allow_edit_catalog_unit_cost: % if use_buefy:
<style type="text/css"> <style type="text/css">
% if allow_edit_catalog_unit_cost:
td.catalog_unit_cost { td.catalog_unit_cost {
cursor: pointer; cursor: pointer;
background-color: #fcc; background-color: #fcc;
} }
tr.catalog_cost_confirmed td.catalog_unit_cost { tr.catalog_cost_confirmed td.catalog_unit_cost {
/* cursor: pointer; */
background-color: #cfc; background-color: #cfc;
} }
% endif
% if allow_edit_invoice_unit_cost:
td.invoice_unit_cost {
cursor: pointer;
background-color: #fcc;
}
tr.invoice_cost_confirmed td.invoice_unit_cost {
background-color: #cfc;
}
% endif
</style> </style>
% elif not use_buefy and not batch.executed and master.has_perm('edit_row'): % elif not use_buefy and not batch.executed and master.has_perm('edit_row'):
<style type="text/css"> <style type="text/css">
@ -374,7 +381,7 @@
<%def name="render_this_page_template()"> <%def name="render_this_page_template()">
${parent.render_this_page_template()} ${parent.render_this_page_template()}
% if allow_edit_catalog_unit_cost: % if allow_edit_catalog_unit_cost or allow_edit_invoice_unit_cost:
<script type="text/x-template" id="receiving-cost-editor-template"> <script type="text/x-template" id="receiving-cost-editor-template">
<div> <div>
<span v-show="!editing"> <span v-show="!editing">
@ -452,12 +459,13 @@
% endif % endif
% if allow_edit_catalog_unit_cost: % if allow_edit_catalog_unit_cost or allow_edit_invoice_unit_cost:
let ReceivingCostEditor = { let ReceivingCostEditor = {
template: '#receiving-cost-editor-template', template: '#receiving-cost-editor-template',
props: { props: {
row: Object, row: Object,
'field': String,
value: String, value: String,
}, },
data() { data() {
@ -510,8 +518,8 @@
let params = { let params = {
row_uuid: this.$props.row.uuid, row_uuid: this.$props.row.uuid,
catalog_unit_cost: this.inputValue,
} }
params[this.$props.field] = this.inputValue
this.$http.post(url, params, {headers: headers}).then(response => { this.$http.post(url, params, {headers: headers}).then(response => {
if (!response.data.error) { if (!response.data.error) {
@ -519,7 +527,7 @@
// let parent know cost value has changed // let parent know cost value has changed
// (this in turn will update data in *this* // (this in turn will update data in *this*
// component, and display will refresh) // component, and display will refresh)
this.$emit('input', response.data.row.catalog_unit_cost, this.$emit('input', response.data.row[this.$props.field],
this.$props.row._index) this.$props.row._index)
// and hide the input box // and hide the input box
@ -546,6 +554,10 @@
Vue.component('receiving-cost-editor', ReceivingCostEditor) Vue.component('receiving-cost-editor', ReceivingCostEditor)
% endif
% if allow_edit_catalog_unit_cost:
${rows_grid.component_studly}.methods.catalogUnitCostClicked = function(row) { ${rows_grid.component_studly}.methods.catalogUnitCostClicked = function(row) {
// start edit for clicked cell // start edit for clicked cell
@ -567,6 +579,29 @@
% endif % endif
% if allow_edit_invoice_unit_cost:
${rows_grid.component_studly}.methods.invoiceUnitCostClicked = function(row) {
// start edit for clicked cell
this.$refs['invoiceUnitCost_' + row.uuid].startEdit()
}
${rows_grid.component_studly}.methods.invoiceCostConfirmed = function(amount, index) {
// 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()
}
}
% endif
</script> </script>
</%def> </%def>

View file

@ -724,6 +724,11 @@ class ReceivingBatchView(PurchasingBatchView):
and self.has_perm('edit_row') and self.has_perm('edit_row')
and self.batch_handler.allow_receiving_edit_catalog_unit_cost()) and self.batch_handler.allow_receiving_edit_catalog_unit_cost())
def allow_edit_invoice_unit_cost(self, batch):
return (not batch.executed
and self.has_perm('edit_row')
and self.batch_handler.allow_receiving_edit_invoice_unit_cost())
def template_kwargs_view(self, **kwargs): def template_kwargs_view(self, **kwargs):
kwargs = super(ReceivingBatchView, self).template_kwargs_view(**kwargs) kwargs = super(ReceivingBatchView, self).template_kwargs_view(**kwargs)
batch = kwargs['instance'] batch = kwargs['instance']
@ -749,6 +754,7 @@ class ReceivingBatchView(PurchasingBatchView):
columns=['title', 'count']) columns=['title', 'count'])
kwargs['allow_edit_catalog_unit_cost'] = self.allow_edit_catalog_unit_cost(batch) kwargs['allow_edit_catalog_unit_cost'] = self.allow_edit_catalog_unit_cost(batch)
kwargs['allow_edit_invoice_unit_cost'] = self.allow_edit_invoice_unit_cost(batch)
return kwargs return kwargs
@ -960,6 +966,12 @@ class ReceivingBatchView(PurchasingBatchView):
g.set_click_handler('catalog_unit_cost', g.set_click_handler('catalog_unit_cost',
'catalogUnitCostClicked(props.row)') 'catalogUnitCostClicked(props.row)')
# invoice_unit_cost
if use_buefy and 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',
'invoiceUnitCostClicked(props.row)')
# nb. only show PO *or* invoice cost; prefer the latter unless # nb. only show PO *or* invoice cost; prefer the latter unless
# we have a PO and no invoice # we have a PO and no invoice
if (self.batch_handler.has_purchase_order(batch) if (self.batch_handler.has_purchase_order(batch)
@ -1019,12 +1031,22 @@ class ReceivingBatchView(PurchasingBatchView):
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',
'v-model': 'props.row.catalog_unit_cost', 'v-model': 'props.row.catalog_unit_cost',
':ref': "'catalogUnitCost_' + props.row.uuid", ':ref': "'catalogUnitCost_' + props.row.uuid",
':row': 'props.row', ':row': 'props.row',
'@input': 'catalogCostConfirmed', '@input': 'catalogCostConfirmed',
}) })
def render_invoice_unit_cost(self):
return HTML.tag('receiving-cost-editor', **{
'field': 'invoice_unit_cost',
'v-model': 'props.row.invoice_unit_cost',
':ref': "'invoiceUnitCost_' + props.row.uuid",
':row': 'props.row',
'@input': 'invoiceCostConfirmed',
})
def row_grid_extra_class(self, row, i): def row_grid_extra_class(self, row, i):
css_class = super(ReceivingBatchView, self).row_grid_extra_class(row, i) css_class = super(ReceivingBatchView, self).row_grid_extra_class(row, i)
@ -1966,6 +1988,9 @@ class ReceivingBatchView(PurchasingBatchView):
{'section': 'rattail.batch', {'section': 'rattail.batch',
'option': 'purchase.receiving.allow_edit_catalog_unit_cost', 'option': 'purchase.receiving.allow_edit_catalog_unit_cost',
'type': bool}, 'type': bool},
{'section': 'rattail.batch',
'option': 'purchase.receiving.allow_edit_invoice_unit_cost',
'type': bool},
# mobile interface # mobile interface
{'section': 'rattail.batch', {'section': 'rattail.batch',