send_locally_feed.py: get_product() use specific season
This commit is contained in:
@ -44,22 +44,30 @@ class Command(BaseCommand):
|
|||||||
writer = csv.writer(csvfile) #, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
writer = csv.writer(csvfile) #, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||||
writer.writerow(self.upc_headers())
|
writer.writerow(self.upc_headers())
|
||||||
for upc in upcs:
|
for upc in upcs:
|
||||||
prod = self.get_product(upc)
|
prod = self.get_product(upc, season)
|
||||||
if prod:
|
if prod:
|
||||||
writer.writerow(self.upc_data(season, upc, prod))
|
writer.writerow(self.upc_data(season, upc, prod))
|
||||||
else:
|
|
||||||
self.stdout.write(self.style.NOTICE(f'No prods for {upc.material} for {upc.upc}'))
|
|
||||||
|
|
||||||
|
|
||||||
def get_product(self, upc):
|
def get_product(self, upc, season):
|
||||||
# product may not be in current season, so find the most
|
prods = Product.objects.filter(sap=upc.material, season=season)
|
||||||
# recent one.
|
prod = None
|
||||||
prods = Product.objects.filter(sap=upc.material).order_by('-season_ranking')
|
if len(prods) == 1:
|
||||||
|
prod = prods[0]
|
||||||
|
elif len(prods) > 1:
|
||||||
|
self.notice(f'{upc.upc}: {len(prods)} prods for {upc.material}/{season} - using first')
|
||||||
|
prod = prods[0]
|
||||||
|
else:
|
||||||
|
# product may not be in current season, so find the most
|
||||||
|
# recent one. "shouldn't happen"
|
||||||
|
prods = Product.objects.filter(sap=upc.material).order_by('-season_ranking')
|
||||||
|
if len(prods) > 0:
|
||||||
|
self.notice(f'{upc.upc}: no prods for {upc.material}/{season} - {len(prods)} in all seasons')
|
||||||
|
prod = prods[0]
|
||||||
|
else:
|
||||||
|
self.notice(f'{upc.upc}: no prods for {upc.material} in any season')
|
||||||
|
|
||||||
if len(prods) < 1:
|
return prod
|
||||||
return None
|
|
||||||
|
|
||||||
return prods[0]
|
|
||||||
|
|
||||||
|
|
||||||
def upc_headers(self):
|
def upc_headers(self):
|
||||||
@ -123,3 +131,7 @@ class Command(BaseCommand):
|
|||||||
return paths[0]
|
return paths[0]
|
||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def notice(self, s):
|
||||||
|
self.stdout.write(self.style.NOTICE(s))
|
||||||
|
|||||||
Reference in New Issue
Block a user