recalculate_order_amount.py 5.22 KB
Newer Older
Patrick's avatar
Patrick committed
1 2
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
Patrick's avatar
Patrick committed
3

Patrick's avatar
Patrick committed
4 5
from repanier.const import PERMANENCE_CLOSED, \
    PERMANENCE_INVOICED, PERMANENCE_ARCHIVED, PERMANENCE_SEND
Patrick Colmant's avatar
Patrick Colmant committed
6
from repanier.models import Permanence
Patrick's avatar
Patrick committed
7 8 9 10 11 12 13


class Command(BaseCommand):
    args = '<none>'
    help = 'Recalculate order amount'

    def handle(self, *args, **options):
Patrick's avatar
Patrick committed
14 15 16 17 18
        for permanence in Permanence.objects.filter(
            id=229
        ).order_by('permanence_date'):
            print ("Cancel %s %s" % (permanence.permanence_date, permanence.get_status_display()))
            permanence.recalculate_order_amount(re_init=True)
Patrick's avatar
Patrick committed
19

Patrick's avatar
Patrick committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        # latest_total = BankAccount.objects.filter(
        #     producer__isnull=True,
        #     customer__isnull=True,
        #     permanence__isnull=False
        # ).only(
        #     "permanence"
        # ).order_by(
        #     "-id"
        # ).first()
        # while latest_total:
        #     permanence = latest_total.permanence
        #     if permanence.status == PERMANENCE_INVOICED:
        #         print ("Cancel %s %s" % (permanence.permanence_date, permanence.get_status_display()))
        #         task_invoice.admin_cancel(permanence)
        #     else:
        #         latest_total.delete()
        #     latest_total = BankAccount.objects.filter(
        #         producer__isnull=True,
        #         customer__isnull=True,
        #         permanence__isnull=False
        #     ).only(
        #         "permanence"
        #     ).order_by(
        #         "-id"
        #     ).first()
        #
        # for permanence in Permanence.objects.filter(
        #         status=PERMANENCE_ARCHIVED
        # ).order_by('permanence_date'):
        #     print ("Cancel %s %s" % (permanence.permanence_date, permanence.get_status_display()))
        #     task_invoice.admin_cancel(permanence)
        #
        # for permanence in Permanence.objects.filter(
        #     status__lt=PERMANENCE_CLOSED
        # ).order_by('permanence_date'):
        #     print ("Recalculate %s %s" % (permanence.permanence_date, permanence.get_status_display()))
        #     recalculate_order_amount(
        #         permanence_id=permanence.id,
        #         re_init=True
        #     )
        #     reorder_offer_items(permanence.id)
        #     for customer_invoice in CustomerInvoice.objects.filter(permanence_id=permanence.id):
        #         delivery_point = LUT_DeliveryPoint.objects.filter(
        #             customer_responsible=customer_invoice.customer_id
        #         ).order_by('?').first()
        #         if delivery_point is not None:
        #             delivery = DeliveryBoard.objects.filter(
        #                 delivery_point_id=delivery_point.id,
        #                 permanence_id=permanence.id,
        #             ).order_by('?').first()
        #             customer_invoice.delivery = delivery
        #         customer_invoice.set_delivery(customer_invoice.delivery)
        #         if customer_invoice.is_order_confirm_send:
        #             customer_invoice.confirm_order()
        #         customer_invoice.save()
        #         # if customer_invoice.is_order_confirm_send:
        #         #     confirm_customer_invoice(permanence.id, customer_invoice.customer_id)
        # for permanence in Permanence.objects.filter(
        #     status__gte=PERMANENCE_CLOSED,
        #     status__lt=PERMANENCE_INVOICED
        # ).order_by('permanence_date'):
        #     # Important : Do not reclaculte if permanence is invoiced or archived.
        #     # First, cancel the invoice / archiving.
        #     print ("Recalculate %s %s" % (permanence.permanence_date, permanence.get_status_display()))
        #     status = permanence.status
        #     permanence.set_status(status)
        #     # if status >= PERMANENCE_SEND:
        #     recalculate_order_amount(
        #         permanence_id=permanence.id,
        #         re_init=True
        #     )
        #     reorder_offer_items(permanence.id)
        #     for customer_invoice in CustomerInvoice.objects.filter(permanence_id=permanence.id):
        #         delivery_point = LUT_DeliveryPoint.objects.filter(
        #             customer_responsible=customer_invoice.customer_id
        #         ).order_by('?').first()
        #         if delivery_point is not None:
        #             print("---- %s" % delivery_point)
        #             delivery = DeliveryBoard.objects.filter(
        #                 delivery_point_id=delivery_point.id,
        #                 permanence_id=permanence.id,
        #             ).order_by('?').first()
        #             customer_invoice.delivery = delivery
        #         customer_invoice.set_delivery(customer_invoice.delivery)
        #         if customer_invoice.is_order_confirm_send:
        #             customer_invoice.confirm_order()
        #         customer_invoice.save()
        #
        # for permanence in Permanence.objects.filter(
        #     status=PERMANENCE_SEND,
        #     highest_status__in=[PERMANENCE_INVOICED, PERMANENCE_ARCHIVED]
        # ).order_by(
        #     "payment_date", "is_updated_on"
        # ):
        #     # if permanence.highest_status == PERMANENCE_INVOICED:
        #     # else:
        #     pass
Patrick's avatar
Patrick committed
117

Patrick's avatar
Patrick committed
118