Ejemplo n.º 1
0
    def get_price_for_customer(self, cuID=None):
        """
        :param cuID: db.auth_user.id
        :return: product price for customer
        """
        from os_customer import Customer
        TODAY_LOCAL = current.globalenv['TODAY_LOCAL']

        price = self.workshop_product.Price
        if not cuID:
            return price


        customer = Customer(cuID)
        # Check subscription
        if customer.has_subscription_on_date(self.workshop.Startdate, from_cache=False):
            if self.workshop_product.PriceSubscription:
                price = self.workshop_product.PriceSubscription

            # Check subscription earlybird
            if ( self.workshop_product.PriceSubscriptionEarlybird
                 and TODAY_LOCAL <= self.workshop_product.EarlybirdUntil ):
                price = self.workshop_product.PriceSubscriptionEarlybird

            return price

        # Check earlybird
        if ( self.workshop_product.PriceEarlybird and
             TODAY_LOCAL <= self.workshop_product.EarlybirdUntil ):
            price = self.workshop_product.PriceEarlybird

        return price
Ejemplo n.º 2
0
    def customers_memberships_renew_expired(self, year, month):
        """
            Checks if a subscription exceeds the expiration of a membership.
            If so it creates a new membership and an invoice for it for the customer
        """
        from general_helpers import get_last_day_month
        from datetime import timedelta
        from os_customer import Customer
        from os_invoice import Invoice
        from os_school_membership import SchoolMembership

        T = current.T
        db = current.db
        DATE_FORMAT = current.DATE_FORMAT

        year = int(year)
        month = int(month)

        firstdaythismonth = datetime.date(year, month, 1)
        lastdaythismonth  = get_last_day_month(firstdaythismonth)
        firstdaynextmonth = lastdaythismonth + datetime.timedelta(days=1)

        query = (db.customers_memberships.Enddate >= firstdaythismonth) & \
                (db.customers_memberships.Enddate <= lastdaythismonth)

        rows = db(query).select(
            db.customers_memberships.ALL
        )

        renewed = 0

        for row in rows:
            new_cm_start = row.Enddate + datetime.timedelta(days=1)

            # Check if a subscription will be active next month for customer
            # if so, add another membership
            customer = Customer(row.auth_customer_id)

            # Check if a new membership hasn't ben added already
            if customer.has_membership_on_date(new_cm_start):
                continue

            # Ok all good, continue
            if customer.has_subscription_on_date(firstdaynextmonth, from_cache=False):
                new_cm_start = row.Enddate + datetime.timedelta(days=1)

                school_membership = SchoolMembership(row.school_memberships_id)

                school_membership.sell_to_customer(
                    row.auth_customer_id,
                    new_cm_start,
                    note=T("Renewal for membership %s" % row.id),
                    invoice=True,
                    payment_methods_id=row.payment_methods_id
                )

                renewed += 1
            # else:
            #
            #     print 'no subscription'
            # print renewed

        ##
        # For scheduled tasks db connection has to be committed manually
        ##
        db.commit()

        return T("Memberships renewed") + ': ' + unicode(renewed)