def make_test_order(country, state, site=None, orderitems=None): if not orderitems: orderitems = [ ('formaggio-fresco-di-carmasciano', 5), ] if not site: site = Site.objects.get_current() c = Contact(first_name="Order", last_name="Tester", role=ContactRole.objects.get(pk='Customer'), email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact = country) ad = AddressBook(contact=c, description="home", street1 = "via prova 123", state=state, city="Napoli", country = country, is_default_shipping=True, is_default_billing=True) ad.save() o = Order(contact=c, shipping_cost=Decimal('10.00'), site = site) o.save() for slug, qty in orderitems: p = Product.objects.get(slug=slug) price = p.unit_price item = OrderItem(order=o, product=p, quantity=qty, unit_price=price, line_item_price=price*qty) item.save() return o
def make_test_order(country, state): c = Contact(first_name="Gift", last_name="Tester", role=ContactRole.objects.get(pk='Customer'), email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact = country) ad = AddressBook(contact=c, description="home", street1 = "test", state=state, city="Portland", country = country, is_default_shipping=True, is_default_billing=True) ad.save() site = Site.objects.get_current() o = Order(contact=c, shipping_cost=Decimal('0.00'), site=site) o.save() p = Product.objects.get(slug='GIFT10') price = p.unit_price log.debug("creating with price: %s", price) item1 = OrderItem(order=o, product=p, quantity='2.0', unit_price=price, line_item_price=price*2) item1.save() detl = OrderItemDetail(name = 'email', value='*****@*****.**', sort_order=0, item=item1) detl.save() detl = OrderItemDetail(name = 'message', value='hello there', sort_order=0, item=item1) detl.save() return o
def get_or_create_order(request, working_cart, contact, data): """Get the existing order from the session, else create using the working_cart, contact and data""" shipping = data.get('shipping', None) discount = data.get('discount', None) notes = data.get('notes', None) try: order = Order.objects.from_request(request) if order.status != '': # This order is being processed. We should not touch it! order = None except Order.DoesNotExist: order = None update = bool(order) if order: # make sure to copy/update addresses - they may have changed order.copy_addresses() order.save() if discount is None and order.discount_code: discount = order.discount_code else: # Create a new order. order = Order(contact=contact) pay_ship_save(order, working_cart, contact, shipping=shipping, discount=discount, notes=notes, update=update) request.session['orderID'] = order.id return order
def one_step(request): payment_module = config_get_group('PAYMENT_AUTOSUCCESS') #First verify that the customer exists try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: url = lookup_url(payment_module, 'satchmo_checkout-step1') return HttpResponseRedirect(url) #Verify we still have items in the cart tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: template = lookup_template(payment_module, 'shop/checkout/empty_cart.html') return render(request, template) # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping="", discount="", notes="") request.session['orderID'] = newOrder.id processor = get_processor_by_key('PAYMENT_AUTOSUCCESS') processor.prepare_data(newOrder) payment = processor.process(newOrder) tempCart.empty() success = lookup_url(payment_module, 'satchmo_checkout-success') return HttpResponseRedirect(success)
def make_test_order(site, orderitems, shipping_cost='10.00', contact_info={}): default_contact_info = { 'first_name': "Order", 'last_name': "Tester", 'role': ContactRole.objects.get(pk='Customer'), 'email': "*****@*****.**", 'address': { 'description': 'home', 'street1': 'Via delle Chiaie 21', 'city': 'Napoli', 'state': 'NA', 'country': Country.objects.get(iso2_code__iexact='IT'), 'is_default_shipping': True, 'is_default_billing': True } } default_contact_info.update(contact_info) address_info = default_contact_info.pop('address') contact = Contact(**default_contact_info) contact.save() address_info['contact'] = contact address_book = AddressBook(**address_info) address_book.save() order = Order( contact=contact, shipping_cost=Decimal(shipping_cost), site = site ) order.save() for slug, quantity in orderitems: product = Product.objects.get(slug=slug) price = product.unit_price item = OrderItem( order=order, product=product, quantity=quantity, unit_price=price, line_item_price=price*quantity ) item.save() return order
def make_test_order(country, state): c = Contact(first_name="Gift", last_name="Tester", role=ContactRole.objects.get(pk='Customer'), email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact=country) ad = AddressBook(contact=c, description="home", street1="test", state=state, city="Portland", country=country, is_default_shipping=True, is_default_billing=True) ad.save() site = Site.objects.get_current() o = Order(contact=c, shipping_cost=Decimal('0.00'), site=site) o.save() p = Product.objects.get(slug='GIFT10') price = p.unit_price log.debug("creating with price: %s", price) item1 = OrderItem(order=o, product=p, quantity='2.0', unit_price=price, line_item_price=price * 2) item1.save() detl = OrderItemDetail(name='email', value='*****@*****.**', sort_order=0, item=item1) detl.save() detl = OrderItemDetail(name='message', value='hello there', sort_order=0, item=item1) detl.save() return o
def make_test_order(country, state, site=None, orderitems=None): if not orderitems: orderitems = [ ('formaggio-fresco-di-carmasciano', 5), ] if not site: site = Site.objects.get_current() c = Contact(first_name="Order", last_name="Tester", role=ContactRole.objects.get(pk='Customer'), email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact=country) ad = AddressBook(contact=c, description="home", street1="via prova 123", state=state, city="Napoli", country=country, is_default_shipping=True, is_default_billing=True) ad.save() o = Order(contact=c, shipping_cost=Decimal('10.00'), site=site) o.save() for slug, qty in orderitems: p = Product.objects.get(slug=slug) price = p.unit_price item = OrderItem(order=o, product=p, quantity=qty, unit_price=price, line_item_price=price * qty) item.save() return o
def make_test_order(site, orderitems, shipping_cost='10.00', contact_info={}): default_contact_info = { 'first_name': "Order", 'last_name': "Tester", 'role': ContactRole.objects.get(pk='Customer'), 'email': "*****@*****.**", 'address': { 'description': 'home', 'street1': 'Via delle Chiaie 21', 'city': 'Napoli', 'state': 'NA', 'country': Country.objects.get(iso2_code__iexact='IT'), 'is_default_shipping': True, 'is_default_billing': True } } default_contact_info.update(contact_info) address_info = default_contact_info.pop('address') contact = Contact(**default_contact_info) contact.save() address_info['contact'] = contact address_book = AddressBook(**address_info) address_book.save() order = Order(contact=contact, shipping_cost=Decimal(shipping_cost), site=site) order.save() for slug, quantity in orderitems: product = Product.objects.get(slug=slug) price = product.unit_price item = OrderItem(order=order, product=product, quantity=quantity, unit_price=price, line_item_price=price * quantity) item.save() return order
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 Order.add_to_class("shipping_extimated_date", shipping_extimated_date) import signals # pylint: disable=W0611
Add a new field to the django.contrib.sites.Site which indicates whether the respective site represents a normal shop (is_multishop = False) or a new 'multishop' (is_multishop = True). Default is False. """ Site.add_to_class('is_multishop', models.BooleanField(default=False)) # # Order changes and additions. # def belongs_to_multishop(self): """Returns True when the order belongs to a multishop.""" return self.site.is_multishop Order.add_to_class('belongs_to_multishop', belongs_to_multishop) @property def is_multishoporder(self): """Property alias for belongs_to_multishop""" return self.belongs_to_multishop() Order.add_to_class('is_multishoporder', is_multishoporder) """ Add a reference from normal orders to their parent multishoporder (if present). """ Order.add_to_class('multishop_order', models.ForeignKey("self", verbose_name=_('Multishop Order'), blank=True, null=True, related_name='childorder_set'))
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 Order.add_to_class("shipping_extimated_date", shipping_extimated_date) import signals # pylint: disable=W0611