Created
June 25, 2015 20:10
-
-
Save shofetim/3d3eac116a52f123b34c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_landed_costs(): | |
path = os.path.join(settings.CACHE_ROOT, 'landed_costs.csv') | |
f = open(path, 'w') | |
w = UnicodeWriter(f) | |
w.writerow( | |
['Code', 'Length', 'Width', 'Height', 'Weight', | |
'Storage Climate', 'Pick Area', 'Repackaged', 'Name', 'Size', | |
'Retail Price', 'Pack Quantity', 'Average Ancillaries', | |
'Product Cost', | |
'Product Expected Landed Cost (now)', | |
'Product Expected Landed Cost (+30 days)', | |
'Product Expected Landed Cost (+60 days)', | |
'Product Expected Landed Cost (+90 days)', | |
]) | |
now = date.today() | |
plus_1_month = now + timedelta(days=30) | |
plus_2_month = now + timedelta(days=60) | |
plus_3_month = now + timedelta(days=90) | |
for p in Product.objects.all(): | |
try: | |
avg_ancillary = sum( | |
[l.unit_ancillary for l in | |
PurchaseLine.objects.filter( | |
quantity__gt=0, | |
vendor_piece__piece__in=p.piece.breakdown_family, | |
purchase__phase__gte=PHASE_TO_PAY | |
).order_by('purchase__reconciled_at')[0:3]]) | |
w.writerow( | |
[p.code, p.piece.length, p.piece.width, p.piece.height, | |
p.piece.weight, p.piece.primary_location.climate_name.title(), | |
p.piece.primary_location.small_or_bulk_pick_area_name, | |
p.piece.is_repackaging, p.name, p.size, p.retail_price, | |
p.quantity, | |
avg_ancillary, | |
p.cost(), | |
p.piece.landed_cost(when=now, expected=True), | |
p.piece.landed_cost(when=plus_1_month, expected=True), | |
p.piece.landed_cost(when=plus_2_month, expected=True), | |
p.piece.landed_cost(when=plus_3_month, expected=True), | |
]) | |
print 'Complete for %s' % p | |
except Exception as e: | |
print 'Exception for %s' % p | |
print e | |
#pass | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment