Add "truck dump status" fields to receiving batch views

also refactor some code to use e.g. `batch.is_truck_dump_parent()` for clarity
This commit is contained in:
Lance Edgar 2019-03-01 12:12:00 -06:00
parent a2965d83af
commit b7a026a7e8

View file

@ -194,6 +194,7 @@ class ReceivingBatchView(PurchasingBatchView):
'created', 'created',
'created_by', 'created_by',
'status_code', 'status_code',
'truck_dump_status',
'rowcount', 'rowcount',
'order_quantities_known', 'order_quantities_known',
'complete', 'complete',
@ -222,6 +223,7 @@ class ReceivingBatchView(PurchasingBatchView):
'invoice_total', 'invoice_total',
'credits', 'credits',
'status_code', 'status_code',
'truck_dump_status',
] ]
row_form_fields = [ row_form_fields = [
@ -250,6 +252,7 @@ class ReceivingBatchView(PurchasingBatchView):
'invoice_unit_cost', 'invoice_unit_cost',
'invoice_total', 'invoice_total',
'status_code', 'status_code',
'truck_dump_status',
'claims', 'claims',
'credits', 'credits',
] ]
@ -290,9 +293,9 @@ class ReceivingBatchView(PurchasingBatchView):
def get_instance_title(self, batch): def get_instance_title(self, batch):
title = super(ReceivingBatchView, self).get_instance_title(batch) title = super(ReceivingBatchView, self).get_instance_title(batch)
if batch.truck_dump: if batch.is_truck_dump_parent():
title = "{} (TRUCK DUMP PARENT)".format(title) title = "{} (TRUCK DUMP PARENT)".format(title)
elif batch.truck_dump_batch: elif batch.is_truck_dump_child():
title = "{} (TRUCK DUMP CHILD)".format(title) title = "{} (TRUCK DUMP CHILD)".format(title)
return title return title
@ -318,30 +321,32 @@ class ReceivingBatchView(PurchasingBatchView):
if self.allow_truck_dump: if self.allow_truck_dump:
# truck_dump # truck_dump
if self.creating: if self.creating or not batch.is_truck_dump_parent():
f.remove_field('truck_dump')
elif batch.truck_dump_batch:
f.remove_field('truck_dump') f.remove_field('truck_dump')
else: else:
f.set_readonly('truck_dump') f.set_readonly('truck_dump')
# truck_dump_children_first # truck_dump_children_first
if self.creating or not batch.truck_dump: if self.creating or not batch.is_truck_dump_parent():
f.remove_field('truck_dump_children_first') f.remove_field('truck_dump_children_first')
# truck_dump_children # truck_dump_children
if self.viewing: if self.viewing and batch.is_truck_dump_parent():
if batch.truck_dump:
f.set_renderer('truck_dump_children', self.render_truck_dump_children) f.set_renderer('truck_dump_children', self.render_truck_dump_children)
else: else:
f.remove_field('truck_dump_children') f.remove_field('truck_dump_children')
else:
f.remove_field('truck_dump_children')
# truck_dump_ready # truck_dump_ready
if self.creating or not batch.truck_dump: if self.creating or not batch.is_truck_dump_parent():
f.remove_field('truck_dump_ready') f.remove_field('truck_dump_ready')
# truck_dump_status
if self.creating or not batch.is_truck_dump_parent():
f.remove_field('truck_dump_status')
else:
f.set_readonly('truck_dump_status')
f.set_enum('truck_dump_status', model.PurchaseBatch.STATUS)
# truck_dump_batch # truck_dump_batch
if self.creating: if self.creating:
f.replace('truck_dump_batch', 'truck_dump_batch_uuid') f.replace('truck_dump_batch', 'truck_dump_batch_uuid')
@ -356,9 +361,7 @@ class ReceivingBatchView(PurchasingBatchView):
batch_values.insert(0, ('', "(please choose)")) batch_values.insert(0, ('', "(please choose)"))
f.set_widget('truck_dump_batch_uuid', forms.widgets.JQuerySelectWidget(values=batch_values)) f.set_widget('truck_dump_batch_uuid', forms.widgets.JQuerySelectWidget(values=batch_values))
f.set_label('truck_dump_batch_uuid', "Truck Dump Parent") f.set_label('truck_dump_batch_uuid', "Truck Dump Parent")
elif batch.truck_dump: elif batch.is_truck_dump_child():
f.remove_field('truck_dump_batch')
elif batch.truck_dump_batch:
f.set_readonly('truck_dump_batch') f.set_readonly('truck_dump_batch')
f.set_renderer('truck_dump_batch', self.render_truck_dump_batch) f.set_renderer('truck_dump_batch', self.render_truck_dump_batch)
else: else:
@ -375,6 +378,7 @@ class ReceivingBatchView(PurchasingBatchView):
'truck_dump_children_first', 'truck_dump_children_first',
'truck_dump_children', 'truck_dump_children',
'truck_dump_ready', 'truck_dump_ready',
'truck_dump_status',
'truck_dump_batch') 'truck_dump_batch')
# invoice_file # invoice_file
@ -463,7 +467,7 @@ class ReceivingBatchView(PurchasingBatchView):
Delete all data (files etc.) for the batch. Delete all data (files etc.) for the batch.
""" """
truck_dump = batch.truck_dump_batch truck_dump = batch.truck_dump_batch
if batch.truck_dump: if batch.is_truck_dump_parent():
for child in batch.truck_dump_children: for child in batch.truck_dump_children:
self.delete_instance(child) self.delete_instance(child)
super(ReceivingBatchView, self).delete_instance(batch) super(ReceivingBatchView, self).delete_instance(batch)
@ -514,7 +518,7 @@ class ReceivingBatchView(PurchasingBatchView):
View for adding a child batch to a truck dump, from invoice file. View for adding a child batch to a truck dump, from invoice file.
""" """
batch = self.get_instance() batch = self.get_instance()
if not batch.truck_dump: if not batch.is_truck_dump_parent():
self.request.session.flash("Batch is not a truck dump: {}".format(batch)) self.request.session.flash("Batch is not a truck dump: {}".format(batch))
return self.redirect(self.get_action_url('view', batch)) return self.redirect(self.get_action_url('view', batch))
if batch.executed: if batch.executed:
@ -732,12 +736,12 @@ class ReceivingBatchView(PurchasingBatchView):
# truck_dump # truck_dump
if not self.creating: if not self.creating:
if not batch.truck_dump: if not batch.is_truck_dump_parent():
f.remove_field('truck_dump') f.remove_field('truck_dump')
# department # department
if not self.creating: if not self.creating:
if batch.truck_dump: if batch.is_truck_dump_parent():
f.remove_field('department') f.remove_field('department')
def configure_row_grid(self, g): def configure_row_grid(self, g):
@ -764,6 +768,12 @@ class ReceivingBatchView(PurchasingBatchView):
delete = g.main_actions.pop() delete = g.main_actions.pop()
g.more_actions.append(delete) g.more_actions.append(delete)
# truck_dump_status
if not batch.is_truck_dump_parent():
g.hide_column('truck_dump_status')
else:
g.set_enum('truck_dump_status', model.PurchaseBatchRow.STATUS)
def transform_unit_url(self, row, i): def transform_unit_url(self, row, i):
# grid action is shown only when we return a URL here # grid action is shown only when we return a URL here
if self.row_editable(row): if self.row_editable(row):
@ -841,6 +851,13 @@ class ReceivingBatchView(PurchasingBatchView):
else: else:
f.remove_field('claims') f.remove_field('claims')
# truck_dump_status
if self.creating or not batch.is_truck_dump_parent():
f.remove_field('truck_dump_status')
else:
f.set_readonly('truck_dump_status')
f.set_enum('truck_dump_status', model.PurchaseBatchRow.STATUS)
def render_parent_row_claims(self, row, field): def render_parent_row_claims(self, row, field):
items = [] items = []
for claim in row.claims: for claim in row.claims: