def setUp(self): super(TestConvertingAFulfillmentLineToItemDict, self).setUp() self.line = mwsm.FulfillmentOrderLine(order_item_id='123', quantity=5) self.line.line = Line() self.line.line.product = Product() self.line.line.product.amazon_profile = mwsm.AmazonProfile( sku='MY-SKU')
def test_all_statuses_class_method(self): self.assertEqual(['A', 'B'], sorted(Line.all_statuses()))
def test_all_statuses_class_method(self): self.assertEqual(['A', 'B'], sorted(Line.all_statuses()))
def test_all_statuses_class_method(self): self.assertEqual(["A", "B"], Line.all_statuses())
def post(self, request, *args, **kwargs): quote_id = request.POST.get('quote_id', '') line_ids = request.POST.get('ids', '').split(',') payment_method = request.POST.get('payment_method', 'payondelivery') quote = models.Quote.objects.get(pk=quote_id) if self.request.user.id != quote.search_request.owner.id: raise PermissionDenied() response_data = {} if quote and line_ids and len(line_ids)>0: base_total = 0 for line_id in line_ids: line = models.QuoteItem.objects.get(pk=line_id) base_total += line.base_total_excl_tax # create order order = Order() order.number = quote.id order.user = request.user order.site = Site.objects.get_current() order.currency = 'EUR' order.status = 'pending_payment' # get totals order.total_excl_tax = base_total order.total_incl_tax = float(base_total) + float(base_total*settings.TPC_TAX/100) order.shipping_excl_tax = quote.shipping_total_excl_tax order.shipping_incl_tax = quote.shipping_total_incl_tax # payment method order.payment_method = payment_method if payment_method == 'transfer': order.bank_account = quote.owner.iban order.save() # create order lines for line_id in line_ids: order_line = Line() order_line.order = order line = models.QuoteItem.objects.get(pk=line_id) # check if owner is partner, if not, create it try: partner = Partner.objects.get(code=quote.owner.cif) except: partner = Partner() partner.code = quote.owner.cif partner.name = quote.owner.commercial_name partner.save() order_line.partner = partner order_line.partner_name = quote.owner.commercial_name order_line.partner_sku = quote.owner.cif order_line.title = line.search_item_request order_line.upc = line.search_item_request.id order_line.product = line.search_item_request.piece order_line.quantity = 1 order_line.unit_price_excl_tax = line.base_total_excl_tax order_line.line_price_excl_tax = line.base_total_excl_tax order_line.line_price_incl_tax = float(line.base_total_excl_tax) + float(line.base_total_excl_tax*settings.TPC_TAX/100) order_line.line_price_before_discounts_incl_tax = float(line.base_total_excl_tax) + float(line.base_total_excl_tax*settings.TPC_TAX/100) order_line.line_price_before_discounts_excl_tax = line.base_total_excl_tax order_line.save() # create addresses shipping_address = ShippingAddress() shipping_address.__dict__ = request.user.get_default_shipping_address().__dict__ shipping_address.save() order.shipping_address = shipping_address # get user address billing_address = BillingAddress() if request.user.get_default_billing_address(): billing_address.__dict__ = request.user.get_default_billing_address().__dict__ else: billing_address.__dict__ = request.user.get_default_shipping_address().__dict__ billing_address.save() order.billing_address = billing_address order.save() # associate order with quote quote.order = order quote.state = 'accepted' quote.date_accepted = datetime.now() quote.save() # mark all the lines as accepted or rejected for line in quote.lines: if unicode(line.id) in line_ids: line.state = 'accepted' else: line.state = 'rejected' line.save() response_data['result'] = 'OK' else: response_data['result'] = 'KO' response_data['error'] = _('There has been an error processing your request. Please try again.') return HttpResponse(json.dumps(response_data), content_type="application/json")