示例#1
0
def get_taxprocessor(user):
    if user.is_authenticated:
        user = user
    else:
        user = None

    return get_tax_processor(user=user)
示例#2
0
def get_taxprocessor(user):
    if user.is_authenticated:
        user = user
    else:
        user = None

    return get_tax_processor(user=user)
示例#3
0
def _get_taxprocessor(request):
    taxprocessor = get_thread_variable("taxer", None)
    if not taxprocessor:
        user = request.user
        if user.is_authenticated:
            user = user
        else:
            user = None

        taxprocessor = get_tax_processor(user=user)
        set_thread_variable("taxer", taxprocessor)

    return taxprocessor
示例#4
0
def _get_taxprocessor(request):
    taxprocessor = get_thread_variable('taxer', None)
    if not taxprocessor:
        user = request.user
        if user.is_authenticated():
            user = user
        else:
            user = None

        taxprocessor = get_tax_processor(user=user)
        set_thread_variable('taxer', taxprocessor)

    return taxprocessor
示例#5
0
def _get_taxprocessor(request=None):
    taxprocessor = get_thread_variable("taxer", None)
    if not taxprocessor:
        if request:
            user = request.user
            if user.is_authenticated():
                user = user
            else:
                user = None
        else:
            user = get_current_user()

        taxprocessor = get_tax_processor(user=user)
        set_thread_variable("taxer", taxprocessor)

    return taxprocessor
示例#6
0
    def getRecurringChargeData(self, testing=False):
        """Build the list of dictionaries needed to process a recurring charge.
        
        Because Authorize can only take one subscription at a time, we build a list
        of the transaction dictionaries, for later sequential posting.
        """
        if not self.arb_enabled:
            return []
        
        # get all subscriptions from the order
        subscriptions = self.get_recurring_orderitems()
        
        if len(subscriptions) == 0:
            self.log_extra('No subscription items')
            return []

        settings = self.settings            
        # set up the base dictionary
        trans = {}

        if self.is_live():
            conn = settings.ARB_CONNECTION.value
            self.log_extra('Using live recurring charge connection.')
        else:
            conn = settings.ARB_CONNECTION_TEST.value
            self.log_extra('Using test recurring charge connection.')
        
        shop_config = Config.objects.get_current()
        
        trans['connection'] = conn
        trans['config'] = {
            'merchantID' : settings.LOGIN.value,
            'transactionKey' : settings.TRANKEY.value,
            'shop_name' : shop_config.store_name,
        }
        trans['order'] = self.order
        trans['card'] = self.order.credit_card
        trans['card_expiration'] =  "%4i-%02i" % (self.order.credit_card.expire_year, self.order.credit_card.expire_month)
        
        translist = []
        taxer = get_tax_processor(user = self.order.contact.user)
        
        for subscription in subscriptions:
            product = subscription.product
            subtrans = trans.copy()
            subtrans['subscription'] = subscription
            subtrans['product'] = product
            
            sub = product.subscriptionproduct
            
            trial = sub.get_trial_terms(0)
            if trial:
                price = trunc_decimal(trial.price, 2)
                trial_amount = price
                if price and subscription.product.taxable:
                    trial_amount = taxer.by_price(subscription.product.taxClass, price)
                    #todo, maybe add shipping for trial?
                amount = sub.recurring_price()
                trial_occurrences = trial.occurrences
                if not trial_occurrences:
                    self.log.warn("Trial expiration period is less than one recurring billing cycle. " +
                        "Authorize does not allow this, so the trial period has been adjusted to be equal to one recurring cycle.")
                    trial_occurrences = 1
            else:
                trial_occurrences = 0
                trial_amount = Decimal('0.00')
                amount = subscription.total_with_tax

            occurrences = sub.recurring_times + trial_occurrences
            if occurrences > 9999:
                occurrences = 9999

            subtrans['occurrences'] = occurrences
            subtrans['trial_occurrences'] = trial_occurrences
            subtrans['trial'] = trial
            subtrans['trial_amount'] = trunc_decimal(trial_amount, 2)
            subtrans['amount'] = trunc_decimal(amount, 2)
            if trial:
                charged_today = trial_amount
            else:
                charged_today = amount
            
            charged_today = trunc_decimal(charged_today, 2)
                
            subtrans['charged_today'] = charged_today
            translist.append(subtrans)
            
        return translist
示例#7
0
 def update_tax(self):
     taxclass = self.product.taxClass
     processor = get_tax_processor(order=self.order)
     self.unit_tax = processor.by_price(taxclass, self.unit_price)
     self.tax = processor.by_orderitem(self)
示例#8
0
    def force_recalculate_total(self, save=True):
        """Calculates sub_total, taxes and total."""
        from satchmo.discount.utils import find_discount_for_code

        zero = Decimal("0.0000000000")
        discount = find_discount_for_code(self.discount_code)
        discount.calc(self)
        self.discount = discount.total
        discounts = discount.item_discounts
        itemprices = []
        fullprices = []
        for lineitem in self.orderitem_set.all():
            lid = lineitem.id
            if lid in discounts:
                lineitem.discount = discounts[lid]
            else:
                lineitem.discount = zero
            if save:
                lineitem.save()

            itemprices.append(lineitem.sub_total)
            fullprices.append(lineitem.line_item_price)

        if 'Shipping' in discounts:
            self.shipping_discount = discounts['Shipping']
        else:
            self.shipping_discount = zero

        if itemprices:
            item_sub_total = reduce(operator.add, itemprices)
        else:
            item_sub_total = zero

        if fullprices:
            full_sub_total = reduce(operator.add, fullprices)
        else:
            full_sub_total = zero

        self.sub_total = full_sub_total

        taxProcessor = get_tax_processor(self)
        totaltax, taxrates = taxProcessor.process()
        self.tax = totaltax

        # clear old taxes
        for taxdetl in self.taxes.all():
            taxdetl.delete()

        for taxdesc, taxamt in taxrates.items():
            taxdetl = OrderTaxDetail(order=self, tax=taxamt, description=taxdesc, method=taxProcessor.method)
            taxdetl.save()

        log.debug("Order #%i, recalc: sub_total=%s, shipping=%s, discount=%s, tax=%s",
            self.id,
            moneyfmt(item_sub_total), 
            moneyfmt(self.shipping_sub_total),
            moneyfmt(self.discount), 
            moneyfmt(self.tax))

        self.total = Decimal(item_sub_total + self.shipping_sub_total + self.tax)

        if save:
            self.save()
示例#9
0
    def getRecurringChargeData(self, testing=False):
        """Build the list of dictionaries needed to process a recurring charge.
        
        Because Authorize can only take one subscription at a time, we build a list
        of the transaction dictionaries, for later sequential posting.
        """
        if not self.arb_enabled:
            return []

        # get all subscriptions from the order
        subscriptions = self.get_recurring_orderitems()

        if len(subscriptions) == 0:
            self.log_extra('No subscription items')
            return []

        settings = self.settings
        # set up the base dictionary
        trans = {}

        if self.is_live():
            conn = settings.ARB_CONNECTION.value
            self.log_extra('Using live recurring charge connection.')
        else:
            conn = settings.ARB_CONNECTION_TEST.value
            self.log_extra('Using test recurring charge connection.')

        shop_config = Config.objects.get_current()

        trans['connection'] = conn
        trans['config'] = {
            'merchantID': settings.LOGIN.value,
            'transactionKey': settings.TRANKEY.value,
            'shop_name': shop_config.store_name,
        }
        trans['order'] = self.order
        trans['card'] = self.order.credit_card
        trans['card_expiration'] = "%4i-%02i" % (
            self.order.credit_card.expire_year,
            self.order.credit_card.expire_month)

        translist = []
        taxer = get_tax_processor(user=self.order.contact.user)

        for subscription in subscriptions:
            product = subscription.product
            subtrans = trans.copy()
            subtrans['subscription'] = subscription
            subtrans['product'] = product

            sub = product.subscriptionproduct

            trial = sub.get_trial_terms(0)
            if trial:
                price = trunc_decimal(trial.price, 2)
                trial_amount = price
                if price and subscription.product.taxable:
                    trial_amount = taxer.by_price(
                        subscription.product.taxClass, price)
                    #todo, maybe add shipping for trial?
                amount = sub.recurring_price()
                trial_occurrences = trial.occurrences
                if not trial_occurrences:
                    self.log.warn(
                        "Trial expiration period is less than one recurring billing cycle. "
                        +
                        "Authorize does not allow this, so the trial period has been adjusted to be equal to one recurring cycle."
                    )
                    trial_occurrences = 1
            else:
                trial_occurrences = 0
                trial_amount = Decimal('0.00')
                amount = subscription.total_with_tax

            occurrences = sub.recurring_times + trial_occurrences
            if occurrences > 9999:
                occurrences = 9999

            subtrans['occurrences'] = occurrences
            subtrans['trial_occurrences'] = trial_occurrences
            subtrans['trial'] = trial
            subtrans['trial_amount'] = trunc_decimal(trial_amount, 2)
            subtrans['amount'] = trunc_decimal(amount, 2)
            if trial:
                charged_today = trial_amount
            else:
                charged_today = amount

            charged_today = trunc_decimal(charged_today, 2)

            subtrans['charged_today'] = charged_today
            translist.append(subtrans)

        return translist