Created
October 8, 2015 19:34
-
-
Save shofetim/a9bfba990417b0faf020 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
from products.models import Product | |
from reports.models import (OutOfStockReport, ProjectedStockTransfers, | |
ProjectedStockTransferScores, LandedCostReport) | |
from datetime import date, timedelta | |
now = date.today() | |
plus_1_month = now + timedelta(days=30) | |
plus_2_month = now + timedelta(days=60) | |
plus_3_month = now + timedelta(days=90) | |
LandedCostReport.objects.all().delete() | |
def foo(): | |
count = 0 | |
for p in Product.objects.all(): | |
if count > 50: | |
return | |
else: | |
count += 1 | |
try: | |
lcp = LandedCostReport( | |
code = p.code, | |
length = float(p.piece.length[:-1]), | |
width = float(p.piece.width[:-1]), | |
height = float(p.piece.height[:-1]), | |
weight = p.piece.shipping_weight_lb, | |
climate = p.piece.primary_location.climate_name.title(), | |
pick_area = p.piece.primary_location.small_or_bulk_pick_area_name, | |
repackeged = p.piece.is_repackaging, | |
name = p.name, | |
size = p.size, | |
retail_price = p.retail_price, | |
pack_quantity = p.quantity, | |
average_ancillaries = p.piece.expected_ancillaries() * p.quantity, | |
landed_cost = p.cost(), | |
vendor_cost = p.piece.base_cost() * p.quantity, | |
expected_landed_cost_now = p.piece.landed_cost( | |
when=now, expected=True) * p.quantity, | |
expected_landed_cost_30_days = p.piece.landed_cost( | |
when=plus_1_month, expected=True) * p.quantity, | |
expected_landed_cost_60_days = p.piece.landed_cost( | |
when=plus_2_month, expected=True) * p.quantity, | |
expected_landed_cost_90_days = p.piece.landed_cost( | |
when=plus_3_month, expected=True) * p.quantity | |
) | |
lcp.save() | |
except Exception as e: | |
# As we iterate over all products, we get _many_ types of | |
# exceptions. All of which amount to problems with that | |
# products data, which means it should be absent from the | |
# report | |
pass | |
%time foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment