Commit 1549fdb0 authored by Patrick's avatar Patrick
Browse files

Refactor code

parent eb725fbe
......@@ -358,7 +358,7 @@ def close_order_delivery(permanence, delivery, all_producers, producers_id=None)
update_or_create_purchase(
customer=purchase.customer,
offer_item_id=purchase.offer_item.id,
value_id=DECIMAL_ZERO,
q_order=DECIMAL_ZERO,
batch_job=True
)
if all_producers:
......@@ -381,14 +381,14 @@ def close_order_delivery(permanence, delivery, all_producers, producers_id=None)
for offer_item in OfferItem.objects.filter(permanence_id=permanence.id, # is_active=False,
order_unit=PRODUCT_ORDER_UNIT_DEPOSIT).order_by('?'):
permanence.producers.add(offer_item.producer_id)
create_or_update_one_purchase(customer, offer_item, 1, None, True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, 0, None, True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, q_order=1, batch_job=True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, q_order=0, batch_job=True, is_box_content=False)
# 4 - Add Membership fee Subscription
if repanier.apps.REPANIER_SETTINGS_MEMBERSHIP_FEE_DURATION > 0:
# There is a membership fee
if customer.membership_fee_valid_until < today:
permanence.producers.add(membership_fee_offer_item.producer_id)
create_or_update_one_purchase(customer, membership_fee_offer_item, 1, None, True,
create_or_update_one_purchase(customer, membership_fee_offer_item, q_order=1, batch_job=True,
is_box_content=False)
customer.membership_fee_valid_until = add_months(
customer.membership_fee_valid_until,
......@@ -402,7 +402,7 @@ def close_order_delivery(permanence, delivery, all_producers, producers_id=None)
for customer in Customer.objects.filter(is_active=True, may_order=True,
represent_this_buyinggroup=False).order_by('?'):
permanence.producers.add(offer_item.producer_id)
create_or_update_one_purchase(customer, offer_item, 1, None, True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, q_order=1, batch_job=True, is_box_content=False)
# 6 - Refresh the Purchase 'sum'
recalculate_order_amount(
permanence_id=permanence.id,
......@@ -448,16 +448,9 @@ def close_order(permanence, all_producers, producers_id=None):
update_or_create_purchase(
customer=purchase.customer,
offer_item_id=purchase.offer_item.id,
value_id=DECIMAL_ZERO,
q_order=DECIMAL_ZERO,
batch_job=True
)
# else:
# 0 - Delete unused purchases
# purchase_qs = Purchase.objects.filter(permanence_id=permanence.id, quantity_ordered=0,
# quantity_invoiced=0).order_by('?').delete()
# if not all_producers:
# purchase_qs = purchase_qs.filter(producer_id__in=producers_id)
# purchase_qs.delete()
# 1 - Round to multiple producer_order_by_quantity
offer_item_qs = OfferItem.objects.filter(
permanence_id=permanence.id,
......@@ -488,7 +481,7 @@ def close_order(permanence, all_producers, producers_id=None):
offer_item_qs = offer_item_qs.filter(producer_id__in=producers_id)
for offer_item in offer_item_qs:
buying_group = Customer.objects.filter(is_active=True, represent_this_buyinggroup=True).order_by('?').first()
create_or_update_one_purchase(buying_group, offer_item, 1, None, True, is_box_content=False)
create_or_update_one_purchase(buying_group, offer_item, q_order=1, batch_job=True, is_box_content=False)
membership_fee_product = Product.objects.filter(is_membership_fee=True, is_active=True).order_by('?').first()
membership_fee_product.producer_unit_price = repanier.apps.REPANIER_SETTINGS_MEMBERSHIP_FEE
# Update the prices
......@@ -512,14 +505,14 @@ def close_order(permanence, all_producers, producers_id=None):
if not all_producers:
offer_item_qs = offer_item_qs.filter(producer_id__in=producers_id)
for offer_item in offer_item_qs:
create_or_update_one_purchase(customer, offer_item, 1, None, True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, 0, None, True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, q_order=1, batch_job=True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, q_order=0, batch_job=True, is_box_content=False)
# 4 - Add Add Membership fee Subscription
if repanier.apps.REPANIER_SETTINGS_MEMBERSHIP_FEE_DURATION > 0:
# There is a membership fee
if customer.membership_fee_valid_until < today:
permanence.producers.add(membership_fee_offer_item.producer_id)
create_or_update_one_purchase(customer, membership_fee_offer_item, 1, None, True, is_box_content=False)
create_or_update_one_purchase(customer, membership_fee_offer_item, q_order=1, batch_job=True, is_box_content=False)
while customer.membership_fee_valid_until < today:
# Do not pay the membership fee if no order passed during a certain amount of time
customer.membership_fee_valid_until = add_months(
......@@ -539,7 +532,7 @@ def close_order(permanence, all_producers, producers_id=None):
represent_this_buyinggroup=False
).order_by('?'):
permanence.producers.add(offer_item.producer_id)
create_or_update_one_purchase(customer, offer_item, 1, None, True, is_box_content=False)
create_or_update_one_purchase(customer, offer_item, q_order=1, batch_job=True, is_box_content=False)
# Disable subscription for next permanence
Product.objects.filter(
order_unit=PRODUCT_ORDER_UNIT_SUBSCRIPTION, is_into_offer=True, is_membership_fee=False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment