Fix timing bug when importing new product cost data
This commit is contained in:
parent
4eb6389cf1
commit
85ec60e933
|
@ -1584,6 +1584,18 @@ class ProductCostImporter(ToRattail):
|
|||
def update_object(self, cost, data, local_data=None):
|
||||
cost = super(ProductCostImporter, self).update_object(cost, data, local_data)
|
||||
|
||||
if 'vendor_id' in self.fields and 'vendor_uuid' not in self.fields:
|
||||
vendor_id = data['vendor_id']
|
||||
assert vendor_id, "Source data has no vendor_id value: {}".format(repr(data))
|
||||
vendor = self.get_vendor(vendor_id)
|
||||
if not vendor:
|
||||
vendor = model.Vendor()
|
||||
vendor.id = vendor_id
|
||||
self.session.add(vendor)
|
||||
self.session.flush()
|
||||
self.vendors[vendor.id] = vendor
|
||||
cost.vendor_uuid = vendor.uuid
|
||||
|
||||
if 'product_upc' in self.fields and 'product_uuid' not in self.fields:
|
||||
upc = data['product_upc']
|
||||
assert upc, "Source data has no product_upc value: {}".format(repr(data))
|
||||
|
@ -1598,17 +1610,6 @@ class ProductCostImporter(ToRattail):
|
|||
elif cost.product is not product:
|
||||
log.warning("duplicate products detected for UPC {}".format(upc.pretty()))
|
||||
|
||||
if 'vendor_id' in self.fields and 'vendor_uuid' not in self.fields:
|
||||
vendor_id = data['vendor_id']
|
||||
assert vendor_id, "Source data has no vendor_id value: {}".format(repr(data))
|
||||
vendor = self.get_vendor(vendor_id)
|
||||
if not vendor:
|
||||
vendor = model.Vendor()
|
||||
vendor.id = vendor_id
|
||||
self.session.add(vendor)
|
||||
self.vendors[vendor.id] = vendor
|
||||
cost.vendor = vendor
|
||||
|
||||
if 'preferred' in self.fields:
|
||||
if data['preferred'] and cost.preference != 1:
|
||||
product = cost.product
|
||||
|
|
Loading…
Reference in a new issue