示例#1
0
def multiorder_update_shipping(order):
	"""Set the shipping for this order"""
	# raise an exception when called with a non-multishop order
	if not order.is_multishoporder:
		raise Exception("called multiorder_update_shipping with normal order")
	
	# Set a default for when no shipping module is used
	order.shipping_cost = Decimal("0.00")
	shipping = order.shipping_model
	contact = order.contact
	
	# iterate over all child orders
	for child_order in order.childorder_set.all():
		# create a DummyCart
		cart = DummyCart(child_order.orderitem_set.all())
		
		# Save the shipping info
		shipper = shipping_method_by_key(shipping)
		shipper.calculate(cart, contact)
		child_order.shipping_description = shipper.description().encode("utf-8")
		child_order.shipping_method = shipper.method()
		child_order.shipping_cost = shipper.cost()
		child_order.shipping_model = shipping
		child_order.save()
		
		# update the parent's shipping cost
		order.shipping_cost = Decimal(order.shipping_cost + child_order.shipping_cost)
	
	order.shipping_description = shipper.description().encode("utf-8")
	order.shipping_method = shipper.method()
	order.shipping_model = shipping
	order.save()
示例#2
0
def shipping_extimated_date(self):
    order = self
    method = shipping_method_by_key(order.shipping_model)
    if method.valid():
        expected_delivery = method.expectedDelivery(order.contact)

    try:
        shipment = Shipment.objects.get(order=order)
        humanize_times = HumanizeTimes()
        start = shipment.mission.starts
        end = shipment.mission.ends
        start_str = start.strftime("%H:%M")
        end_str = end.strftime("%H:%M")
        now = datetime.datetime.utcnow().date()
        if now < shipment.date:
            expected_delivery = humanize_times.humanizeTimeDiffLeft(
                shipment.date)
        else:
            expected_delivery = humanize_times.humanizeTimeDiffAgo(
                shipment.date)

        return u"%(date)s, %(start)s - %(end)s" % {
            'date': expected_delivery,
            'start': start_str,
            'end': end_str
        }

    except Shipment.DoesNotExist:
        pass

    return expected_delivery
示例#3
0
def create_shipping_details(sender, instance, **kwargs):
    """
    Create a ShippingDetail object and link it to the order being saved
    """
    from shipping.config import shipping_method_by_key
    order = instance
    if not (order.shipping_model is not None and
            order.shipping_model.startswith("canadapost-dev-prog-")):
        return
    # we don't want more than one of these, so we overwrite
    shipping_detail, new = OrderShippingService.objects.get_or_create(
        order=order)
    if new:
        shipping_detail.save()
    else:
        # clean old parcel descriptions
        shipping_detail.parceldescription_set.all().delete()

    shipper = shipping_method_by_key(order.shipping_model)
    shipper.calculate(OrderCart(order), order.contact)

    for service, parcel, packs in shipper.services:
        # these will be the same every time, but whatever
        shipping_detail.code = service.code

        box = Box.objects.get(length=parcel.length, width=parcel.width,
                              height=parcel.height)
        parcel_description = ParcelDescription(
            shipping_detail=shipping_detail, box=box, packs=packs)
        parcel_description.save()
    shipping_detail.save()
def create_shipping_details(sender, instance, **kwargs):
    """
    Create a ShippingDetail object and link it to the order being saved
    """
    from shipping.config import shipping_method_by_key
    order = instance
    if not (order.shipping_model is not None
            and order.shipping_model.startswith("canadapost-dp-")):
        return
    # we don't want more than one of these, so we overwrite
    shipping_detail, new = OrderShippingService.objects.get_or_create(
        order=order)
    if new:
        shipping_detail.save()
    else:
        # clean old parcel descriptions
        shipping_detail.parceldescription_set.all().delete()

    shipper = shipping_method_by_key(order.shipping_model)
    shipper.calculate(OrderCart(order), order.contact)

    for service, parcel, packs in shipper.services:
        # these will be the same every time, but whatever
        shipping_detail.code = service.code

        box = Box.objects.get(length=parcel.length,
                              width=parcel.width,
                              height=parcel.height)
        parcel_description = ParcelDescription(shipping_detail=shipping_detail,
                                               box=box,
                                               packs=packs)
        parcel_description.save()
    shipping_detail.save()
示例#5
0
文件: models.py 项目: hnejadi/EShop-2
def shipping_extimated_date(self):
    order = self
    method = shipping_method_by_key(order.shipping_model)
    if method.valid():
        expected_delivery = method.expectedDelivery(order.contact)

    try:
        shipment = Shipment.objects.get(order=order)
        humanize_times = HumanizeTimes()
        start = shipment.mission.starts
        end = shipment.mission.ends
        start_str = start.strftime("%H:%M")
        end_str = end.strftime("%H:%M")
        now = datetime.datetime.utcnow().date()
        if now < shipment.date:
            expected_delivery = humanize_times.humanizeTimeDiffLeft(
                                                            shipment.date)
        else:
            expected_delivery = humanize_times.humanizeTimeDiffAgo(
                                                            shipment.date)

        return u"%(date)s, %(start)s - %(end)s" % {
            'date': expected_delivery,
            'start': start_str,
            'end': end_str}

    except Shipment.DoesNotExist:
        pass

    return expected_delivery
示例#6
0
文件: utils.py 项目: 34/T
def update_shipping(order, shipping, contact, cart):
    """Set the shipping for this order"""
    # Set a default for when no shipping module is used
    order.shipping_cost = Decimal("0.00")

    # Save the shipping info
    shipper = shipping_method_by_key(shipping)
    shipper.calculate(cart, contact)
    order.shipping_description = shipper.description().encode("utf-8")
    order.shipping_method = shipper.method()
    order.shipping_cost = shipper.cost()
    order.shipping_model = shipping
示例#7
0
文件: utils.py 项目: tcv1/satchmo
def update_shipping(order, shipping, contact, cart):
    """Set the shipping for this order"""
    # Set a default for when no shipping module is used
    order.shipping_cost = Decimal("0.00")

    # Save the shipping info
    shipper = shipping_method_by_key(shipping)
    shipper.calculate(cart, contact)
    order.shipping_description = shipper.description().encode("utf-8")
    order.shipping_method = shipper.method()
    order.shipping_cost = shipper.cost()
    order.shipping_model = shipping
示例#8
0
文件: forms.py 项目: hnejadi/xerobis
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False):
    """Iterate through legal shipping modules, building the list for display to the user.
    
    Returns the shipping choices list, along with a dictionary of shipping choices, useful
    for building javascript that operates on shipping choices.
    """
    shipping_options = []
    shipping_dict = {}
    
    if not cart.is_shippable:
        methods = [shipping_method_by_key('NoShipping'),]
    else:
        methods = shipping_methods()
    
    for method in methods:
        method.calculate(cart, contact)
        if method.valid():
            template = lookup_template(paymentmodule, 'shipping/options.html')
            t = loader.get_template(template)
            shipcost = method.cost()
            shipping_tax = None
            taxed_shipping_price = None
            if config_value_safe('TAX','TAX_SHIPPING', False):
                shipping_tax = TaxClass.objects.get(title=config_value('TAX', 'TAX_CLASS'))
                taxer = _get_taxprocessor(request)
                total = shipcost + taxer.by_price(shipping_tax, shipcost)
                taxed_shipping_price = moneyfmt(total)
            c = RequestContext(request, {
                'amount': shipcost,
                'description' : method.description(),
                'method' : method.method(),
                'expected_delivery' : method.expectedDelivery(),
                'default_view_tax' : default_view_tax,
                'shipping_tax': shipping_tax,
                'taxed_shipping_price': taxed_shipping_price})
            shipping_options.append((method.id, t.render(c)))
            shipping_dict[method.id] = shipcost
    
    return shipping_options, shipping_dict
示例#9
0
文件: forms.py 项目: mpango/satchmo
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False, order=None):
    """Iterate through legal shipping modules, building the list for display to the user.

    Returns the shipping choices list, along with a dictionary of shipping choices, useful
    for building javascript that operates on shipping choices.
    """
    shipping_options = []
    shipping_dict = {}
    rendered = {}
    if not order:
        try:
            order = Order.objects.from_request(request)
        except Order.DoesNotExist:
            pass

    discount = None
    if order:
        try:
            discount = Discount.objects.by_code(order.discount_code)
        except Discount.DoesNotExist:
            pass

    if not cart.is_shippable:
        methods = [shipping_method_by_key('NoShipping'),]
    else:
        methods = shipping_methods()

    tax_shipping = config_value_safe('TAX','TAX_SHIPPING', False)
    shipping_tax = None

    if tax_shipping:
        taxer = _get_taxprocessor(request)
        shipping_tax = TaxClass.objects.get(title=config_value('TAX', 'TAX_CLASS'))

    for method in methods:
        method.calculate(cart, contact)
        if method.valid():
            template = lookup_template(paymentmodule, 'shipping/options.html')
            t = loader.get_template(template)
            shipcost = finalcost = method.cost()

            if discount and order:
                order.shipping_cost = shipcost
                discount.calc(order)
                shipdiscount = discount.item_discounts.get('Shipping', 0)
            else:
                shipdiscount = 0

            # set up query to determine shipping price to show
            shipprice = Price()
            shipprice.price = shipcost
            shipadjust = PriceAdjustmentCalc(shipprice)
            if shipdiscount:
                shipadjust += PriceAdjustment('discount', _('Discount'), shipdiscount)

            satchmo_shipping_price_query.send(cart, adjustment=shipadjust)
            shipdiscount = shipadjust.total_adjustment()

            if shipdiscount:
                finalcost -= shipdiscount

            shipping_dict[method.id] = {'cost' : shipcost, 'discount' : shipdiscount, 'final' : finalcost}

            taxed_shipping_price = None
            if tax_shipping:
                taxcost = taxer.by_price(shipping_tax, finalcost)
                total = finalcost + taxcost
                taxed_shipping_price = moneyfmt(total)
                shipping_dict[method.id]['taxedcost'] = total
                shipping_dict[method.id]['tax'] = taxcost

            c = RequestContext(request, {
                'amount': finalcost,
                'description' : method.description(),
                'method' : method.method(),
                'expected_delivery' : method.expectedDelivery(),
                'default_view_tax' : default_view_tax,
                'shipping_tax': shipping_tax,
                'taxed_shipping_price': taxed_shipping_price})
            rendered[method.id] = t.render(c)

    #now sort by price, low to high
    sortme = [(value['cost'], key) for key, value in shipping_dict.items()]
    sortme.sort()

    shipping_options = [(key, rendered[key]) for cost, key in sortme]

    shipping_choices_query.send(sender=cart, cart=cart,
        paymentmodule=paymentmodule, contact=contact,
        default_view_tax=default_view_tax, order=order,
        shipping_options = shipping_options,
        shipping_dict = shipping_dict)
    return shipping_options, shipping_dict
示例#10
0
def _get_shipping_choices(request,
                          paymentmodule,
                          cart,
                          contact,
                          default_view_tax=False,
                          order=None):
    """Iterate through legal shipping modules, building the list for display to the user.

    Returns the shipping choices list, along with a dictionary of shipping choices, useful
    for building javascript that operates on shipping choices.
    """
    shipping_options = []
    shipping_dict = {}
    rendered = {}
    if not order:
        try:
            order = Order.objects.from_request(request)
        except Order.DoesNotExist:
            pass

    discount = None
    if order:
        try:
            discount = Discount.objects.by_code(order.discount_code)
        except Discount.DoesNotExist:
            pass

    if not cart.is_shippable:
        methods = [
            shipping_method_by_key('NoShipping'),
        ]
    else:
        methods = shipping_methods()

    tax_shipping = config_value_safe('TAX', 'TAX_SHIPPING', False)
    shipping_tax = None

    if tax_shipping:
        taxer = _get_taxprocessor(request)
        shipping_tax = TaxClass.objects.get(
            title=config_value('TAX', 'TAX_CLASS'))

    for method in methods:
        method.calculate(cart, contact)
        if method.valid(order=order):
            template = lookup_template(paymentmodule, 'shipping/options.html')
            t = loader.get_template(template)
            shipcost = finalcost = method.cost()

            if discount and order:
                order.shipping_cost = shipcost
                discount.calc(order)
                shipdiscount = discount.item_discounts.get('Shipping', 0)
            else:
                shipdiscount = 0

            # set up query to determine shipping price to show
            shipprice = Price()
            shipprice.price = shipcost
            shipadjust = PriceAdjustmentCalc(shipprice)
            if shipdiscount:
                shipadjust += PriceAdjustment('discount', _('Discount'),
                                              shipdiscount)

            satchmo_shipping_price_query.send(cart, adjustment=shipadjust)
            shipdiscount = shipadjust.total_adjustment()

            if shipdiscount:
                finalcost -= shipdiscount

            shipping_dict[method.id] = {
                'cost': shipcost,
                'discount': shipdiscount,
                'final': finalcost
            }

            taxed_shipping_price = None
            if tax_shipping:
                taxcost = taxer.by_price(shipping_tax, finalcost)
                total = finalcost + taxcost
                taxed_shipping_price = moneyfmt(total)
                shipping_dict[method.id]['taxedcost'] = total
                shipping_dict[method.id]['tax'] = taxcost

            c = RequestContext(
                request, {
                    'amount': finalcost,
                    'description': method.description(),
                    'method': method.method(),
                    'expected_delivery': method.expectedDelivery(),
                    'default_view_tax': default_view_tax,
                    'shipping_tax': shipping_tax,
                    'taxed_shipping_price': taxed_shipping_price
                })
            rendered[method.id] = t.render(c)

    #now sort by price, low to high
    sortme = [(value['cost'], key) for key, value in shipping_dict.items()]
    sortme.sort()

    shipping_options = [(key, rendered[key]) for cost, key in sortme]

    shipping_choices_query.send(sender=cart,
                                cart=cart,
                                paymentmodule=paymentmodule,
                                contact=contact,
                                default_view_tax=default_view_tax,
                                order=order,
                                shipping_options=shipping_options,
                                shipping_dict=shipping_dict)
    return shipping_options, shipping_dict