def create_order(self, request, form=None): if request.session.get(settings.ORDER_KEY): uid = request.session[settings.ORDER_KEY] try: order = Order.objects.get(uid=uid) order.delete() except: pass #try to search if contact already exists in database try: contact = get_object_or_404(Client, email=self.cleaned_data['email']) self.instance = contact #print "he trobat instancia %s" % self.instance except: contact = None; #contact = save_instance(self, contact) if self.instance: contact = save_instance(self, self.instance, construct=True) else: self.save() c = cart_from_session(request) pay_type = self.cleaned_data['pago'] order = order_from_cart(c, contact, pay_type, form) return order
def test_order_from_cart(self): """ Tests that 1 + 1 always equals 2. """ self.assertEqual(1 + 1, 2) client = Client.objects.get(pk=1) self.assertEqual(client.email, '*****@*****.**') c = Cart() c.add((12, 37, 2)) c.add((1, None, 1)) l = cart_list(c) order = order_from_cart(c, client, 'paypal') self.assertEqual(len(order.line_set.all()), 3) # this test fails because not shipping costs ship_cost = Decimal(calc_shipping_costs(c, '08695', cart_total(l))) self.assertEqual(order.total(), cart_total(l) + ship_cost ) self.assertEqual(order.line_set.all()[2].types, 'ship' ) self.assertEqual(order.pay_type, 'paypal' )
def test_order_from_cart(self): """ Tests that 1 + 1 always equals 2. """ self.assertEqual(1 + 1, 2) client = Client.objects.get(pk=1) self.assertEqual(client.email, '*****@*****.**') c = Cart() c.add((12, 37, 2)) c.add((1, None, 1)) l = cart_list(c) order = order_from_cart(c, client, 'paypal') self.assertEqual(len(order.line_set.all()), 3) # this test fails because not shipping costs ship_cost = Decimal(calc_shipping_costs(c, '08695', cart_total(l))) self.assertEqual(order.total(), cart_total(l) + ship_cost) self.assertEqual(order.line_set.all()[2].types, 'ship') self.assertEqual(order.pay_type, 'paypal')