Must pass rows to make_new_order() for custorder batch

also allow passing `new_order_id` if `batch.id` is not wanted for order
This commit is contained in:
Lance Edgar 2023-09-10 13:20:38 -05:00
parent f81ddb113a
commit f81da39fd2

View file

@ -886,7 +886,7 @@ class CustomerOrderBatchHandler(BatchHandler):
customer record. Override as needed.
"""
rows = batch.active_rows()
order = self.make_new_order(batch, user=user, progress=progress, **kwargs)
order = self.make_new_order(batch, rows, user=user, progress=progress, **kwargs)
self.update_contact_info(batch, user)
self.mark_pending_things_ready(batch, rows)
return order
@ -939,7 +939,7 @@ class CustomerOrderBatchHandler(BatchHandler):
'email_address': batch.email_address,
})
def make_new_order(self, batch, user=None, progress=None, **kwargs):
def make_new_order(self, batch, rows, user=None, progress=None, **kwargs):
"""
Create and return a new rattail Customer Order based on the
batch contents.
@ -961,6 +961,10 @@ class CustomerOrderBatchHandler(BatchHandler):
for field in batch_fields:
setattr(order, field, getattr(batch, field))
new_order_id = kwargs.get('new_order_id')
if new_order_id:
order.id = new_order_id
session = self.app.get_session(batch)
session.add(order)
session.flush()
@ -999,7 +1003,7 @@ class CustomerOrderBatchHandler(BatchHandler):
# set initial status and attach events
self.set_initial_item_status(item, user)
self.progress_loop(convert, batch.active_rows(), progress,
self.progress_loop(convert, rows, progress,
message="Converting batch rows to order items")
session.flush()