Tweak how receiving rows are looked up when adding to the batch
i.e. locate the product first, and then try to find an existing row to match. previously we looked for a row based on product key match only, and it could cause new rows to be created for a product we already had in the batch (i.e. if the product was located via some secondary lookup other than product key)
This commit is contained in:
parent
5e49c2709b
commit
848b727b11
|
@ -705,6 +705,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
f.set_readonly('invoice_total')
|
f.set_readonly('invoice_total')
|
||||||
|
|
||||||
# claims
|
# claims
|
||||||
|
f.set_readonly('claims')
|
||||||
if batch.is_truck_dump_parent():
|
if batch.is_truck_dump_parent():
|
||||||
f.set_renderer('claims', self.render_parent_row_claims)
|
f.set_renderer('claims', self.render_parent_row_claims)
|
||||||
f.set_helptext('claims', "Parent row is claimed by these child rows.")
|
f.set_helptext('claims', "Parent row is claimed by these child rows.")
|
||||||
|
@ -994,11 +995,10 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def quick_locate_rows(self, batch, entry):
|
def quick_locate_rows(self, batch, entry, product):
|
||||||
rows = []
|
rows = []
|
||||||
|
|
||||||
# try to locate rows by product uuid match before other key
|
# try to locate rows by product uuid match before other key
|
||||||
product = self.Session.query(model.Product).get(entry)
|
|
||||||
if product:
|
if product:
|
||||||
rows = [row for row in batch.active_rows()
|
rows = [row for row in batch.active_rows()
|
||||||
if row.product_uuid == product.uuid]
|
if row.product_uuid == product.uuid]
|
||||||
|
@ -1050,8 +1050,11 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
batch = self.get_instance()
|
batch = self.get_instance()
|
||||||
entry = form.validated['quick_entry']
|
entry = form.validated['quick_entry']
|
||||||
|
|
||||||
# maybe try to locate existing row first
|
# first try to locate the product based on quick entry
|
||||||
rows = self.quick_locate_rows(batch, entry)
|
product = self.quick_locate_product(batch, entry)
|
||||||
|
|
||||||
|
# then try to locate existing row(s) which match product/entry
|
||||||
|
rows = self.quick_locate_rows(batch, entry, product)
|
||||||
if rows:
|
if rows:
|
||||||
|
|
||||||
# if aggregating, just re-use matching row
|
# if aggregating, just re-use matching row
|
||||||
|
@ -1072,8 +1075,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
self.handler.refresh_batch_status(batch)
|
self.handler.refresh_batch_status(batch)
|
||||||
return row
|
return row
|
||||||
|
|
||||||
# if product is easily located, add new row for it
|
# matching row(s) not found; add new row if product was identified
|
||||||
product = self.quick_locate_product(batch, entry)
|
|
||||||
# TODO: probably should be smarter about how we handle deleted?
|
# TODO: probably should be smarter about how we handle deleted?
|
||||||
if product and not product.deleted:
|
if product and not product.deleted:
|
||||||
row = model.PurchaseBatchRow()
|
row = model.PurchaseBatchRow()
|
||||||
|
|
Loading…
Reference in a new issue