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:
parent
a2965d83af
commit
b7a026a7e8
|
@ -194,6 +194,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'created',
|
||||
'created_by',
|
||||
'status_code',
|
||||
'truck_dump_status',
|
||||
'rowcount',
|
||||
'order_quantities_known',
|
||||
'complete',
|
||||
|
@ -222,6 +223,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'invoice_total',
|
||||
'credits',
|
||||
'status_code',
|
||||
'truck_dump_status',
|
||||
]
|
||||
|
||||
row_form_fields = [
|
||||
|
@ -250,6 +252,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'invoice_unit_cost',
|
||||
'invoice_total',
|
||||
'status_code',
|
||||
'truck_dump_status',
|
||||
'claims',
|
||||
'credits',
|
||||
]
|
||||
|
@ -290,9 +293,9 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
def get_instance_title(self, 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)
|
||||
elif batch.truck_dump_batch:
|
||||
elif batch.is_truck_dump_child():
|
||||
title = "{} (TRUCK DUMP CHILD)".format(title)
|
||||
return title
|
||||
|
||||
|
@ -318,30 +321,32 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if self.allow_truck_dump:
|
||||
|
||||
# truck_dump
|
||||
if self.creating:
|
||||
f.remove_field('truck_dump')
|
||||
elif batch.truck_dump_batch:
|
||||
if self.creating or not batch.is_truck_dump_parent():
|
||||
f.remove_field('truck_dump')
|
||||
else:
|
||||
f.set_readonly('truck_dump')
|
||||
|
||||
# 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')
|
||||
|
||||
# truck_dump_children
|
||||
if self.viewing:
|
||||
if batch.truck_dump:
|
||||
f.set_renderer('truck_dump_children', self.render_truck_dump_children)
|
||||
else:
|
||||
f.remove_field('truck_dump_children')
|
||||
if self.viewing and batch.is_truck_dump_parent():
|
||||
f.set_renderer('truck_dump_children', self.render_truck_dump_children)
|
||||
else:
|
||||
f.remove_field('truck_dump_children')
|
||||
|
||||
# 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')
|
||||
|
||||
# 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
|
||||
if self.creating:
|
||||
f.replace('truck_dump_batch', 'truck_dump_batch_uuid')
|
||||
|
@ -356,9 +361,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
batch_values.insert(0, ('', "(please choose)"))
|
||||
f.set_widget('truck_dump_batch_uuid', forms.widgets.JQuerySelectWidget(values=batch_values))
|
||||
f.set_label('truck_dump_batch_uuid', "Truck Dump Parent")
|
||||
elif batch.truck_dump:
|
||||
f.remove_field('truck_dump_batch')
|
||||
elif batch.truck_dump_batch:
|
||||
elif batch.is_truck_dump_child():
|
||||
f.set_readonly('truck_dump_batch')
|
||||
f.set_renderer('truck_dump_batch', self.render_truck_dump_batch)
|
||||
else:
|
||||
|
@ -375,6 +378,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'truck_dump_children_first',
|
||||
'truck_dump_children',
|
||||
'truck_dump_ready',
|
||||
'truck_dump_status',
|
||||
'truck_dump_batch')
|
||||
|
||||
# invoice_file
|
||||
|
@ -463,7 +467,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
Delete all data (files etc.) for the batch.
|
||||
"""
|
||||
truck_dump = batch.truck_dump_batch
|
||||
if batch.truck_dump:
|
||||
if batch.is_truck_dump_parent():
|
||||
for child in batch.truck_dump_children:
|
||||
self.delete_instance(child)
|
||||
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.
|
||||
"""
|
||||
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))
|
||||
return self.redirect(self.get_action_url('view', batch))
|
||||
if batch.executed:
|
||||
|
@ -732,12 +736,12 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
# truck_dump
|
||||
if not self.creating:
|
||||
if not batch.truck_dump:
|
||||
if not batch.is_truck_dump_parent():
|
||||
f.remove_field('truck_dump')
|
||||
|
||||
# department
|
||||
if not self.creating:
|
||||
if batch.truck_dump:
|
||||
if batch.is_truck_dump_parent():
|
||||
f.remove_field('department')
|
||||
|
||||
def configure_row_grid(self, g):
|
||||
|
@ -764,6 +768,12 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
delete = g.main_actions.pop()
|
||||
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):
|
||||
# grid action is shown only when we return a URL here
|
||||
if self.row_editable(row):
|
||||
|
@ -841,6 +851,13 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
else:
|
||||
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):
|
||||
items = []
|
||||
for claim in row.claims:
|
||||
|
|
Loading…
Reference in a new issue