def buy(request): """ a function to commit the cart that will be reflected on the sales. :param request: :return: """ #verify that the customer logged in session is active customer = None if request.session.has_key("cust_id"): try: customer = Customer.objects.get(id=request.session.get('cust_id')) except: pass if customer is None: return HttpResponseRedirect('/customer/login') #Get all the cart items that is to be bought and identify the farmer associated with the tarkari item. Save the transaction to the sales c = Cart.objects.filter(customer=customer) for cart in c: tarkari = Tarkari.objects.get(id=cart.tarkari.id) godam = Godam.objects.get(tarkari=tarkari) farmer = Farmer.objects.get(id=godam.farmer_id) # sales = Sales.objects.get(customer=customer, tarkari=tarkari, farmer=farmer) # if sales is not None: # sales.number += number # else: sales = Sales(tarkari=tarkari, customer=customer, farmer=farmer, number=cart.tarkari_count) sales.save() cart.delete() #Redirect to view all other lists of tarkaris return HttpResponseRedirect('/listTarkari')
def test_sales_model(self): sales = Sales(code="51081789", date="2020-12-15", salesman_id=1, value=8900.0) sales.save() self.assertEqual(sales.code, "51081789") self.assertEqual(sales.date, datetime.date(2020, 12, 15)) self.assertEqual(sales.salesman.id, 1) self.assertEqual(sales.value, 8900.0)
def load_sales(csv_file, sheet): book = xlrd.open_workbook(csv_file) # Open an .xls file sheet = book.sheet_by_index(sheet) # Get the first sheet for counter in range(21): # Loop for five times if counter: # grab the current row rows = sheet.row_values(counter) sales = Sales(sr_no=rows[0], transaction_id=rows[1], item_id=rows[2], transaction_obj=Transaction.objects.get(transaction_id=rows[1]), item_obj=Item.objects.get(item_id=rows[2])) sales.save() return True
def new(request): if request.method == 'GET': return render_to_response( 'sale/new.html', RequestContext(request, { 'sale_active': 1, 'customs': get_customs(), 'stocks': get_stocks() })) else: data = request.POST.get('data') print data if not data: return failed_response('参数错误') else: all = json.loads(data) s = Sales() s.custom = Custom.objects.get(id=all['custom']) s.stock = Stock.objects.get(id=all['stock']) s.save() for item in all['detail']: pro = SalesDetail() pro.product = Product.objects.get(id=item['pid']) pro.num = int(item['pnum']) pro.price = float(item['pprice']) pro.scale = float(item['pscale']) pro.save() s.detail.add(pro) s.save() return success_response('添加成功')
def test_check_comission_without_notification_more_months(self): Sales(month=4, seller=self.seller, amount=700.0, comission=17.5).save() Sales(month=5, seller=self.seller, amount=650.0, comission=16.2).save() Sales(month=6, seller=self.seller, amount=800.0, comission=20).save() current_sales = { 'seller': self.seller.id, 'amount': 841.0, } response = self.client.post('/check_commision/', current_sales) self.assertEqual(response.status_code, status.HTTP_200_OK) # Parses response body and check data. body = response.json() self.assertFalse(body['should_notify']) self.assertEqual(len(mail.outbox), 0)
def add_sales(request): if request.method == 'POST': customer_s = Sales() emailID = request.POST.get('ID') date = request.POST.get('Date') billNo = request.POST.get('Bill No.') customer = request.POST.get('Customer_name') phone_number = request.POST.get('Contact') address = request.POST.get('Address') product = request.POST.get('Product_name') quantity = request.POST.get('Quantity') rate = request.POST.get('Rate') avail = request.POST.get('Avail_Qty') total = request.POST.get('Total') payment = request.POST.get('Payment') description = request.POST.get('Description') balance = request.POST.get('balance') duedate = request.POST.get('Due_date') mode = request.POST.get('Mode') customer_s.customer = customer customer_s.emailID = emailID customer_s.billNo = billNo customer_s.date = date customer_s.phone_number = phone_number customer_s.address = address customer_s.product = product customer_s.quantity = quantity customer_s.rate = rate customer_s.avail = avail customer_s.total = total customer_s.payment = payment customer_s.description = description customer_s.balance = balance customer_s.duedate = duedate customer_s.mode = mode customer_s.save() return render(request, 'add_sales.html', {})
def setUp(self): self.comission_plan = ComissionPlan(lower_percentage=2.5, upper_percentage=10.5, min_value=5000.0) self.comission_plan.save() self.seller_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller_address.save() self.seller = models.Seller(cpf="12345678910", name="José", last_name="Vendedor", age=30, email="*****@*****.**", phone="48012345678", address=self.seller_address, comission_plan=self.comission_plan) self.seller.save() self.seller2_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller2_address.save() self.seller2 = models.Seller(cpf="12345612396", name="Joao", last_name="Vendedor", age=27, email="*****@*****.**", phone="48012345678", address=self.seller2_address, comission_plan=self.comission_plan) self.seller2.save() self.seller3_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller3_address.save() self.seller3 = models.Seller(cpf="74185296346", name="Luis", last_name="Vendedor", age=27, email="*****@*****.**", phone="48012345678", address=self.seller3_address, comission_plan=self.comission_plan) self.seller3.save() Sales(month=1, seller=self.seller, amount=1000.0, comission=25).save() Sales(month=2, seller=self.seller, amount=500.0, comission=12).save() Sales(month=3, seller=self.seller, amount=1100.0, comission=27).save() Sales(month=1, seller=self.seller2, amount=500.0, comission=12).save() Sales(month=2, seller=self.seller2, amount=1100.0, comission=27).save() Sales(month=3, seller=self.seller2, amount=1000.0, comission=25).save() Sales(month=1, seller=self.seller3, amount=1100.0, comission=27).save() Sales(month=2, seller=self.seller3, amount=1000.0, comission=25).save() Sales(month=3, seller=self.seller3, amount=500.0, comission=12).save()
def setUp(self): self.seller = _set_up_seller() Sales(month=1, seller=self.seller, amount=1000.0, comission=25).save() Sales(month=2, seller=self.seller, amount=500.0, comission=12.5).save() Sales(month=3, seller=self.seller, amount=1100.0, comission=27).save()
def execute(self): import os import sys import csv import re import datetime from sales.models import App, Date, Sales, Country from django.core.mail import mail_admins print self.help for i in ACCOUNT_INFO: print "Processing directory : %s" % i['DATA_DIR'] if (i['DATA_DIR'] != '' and not os.path.exists(i['DATA_DIR'])): os.makedirs(i['DATA_DIR']) filenames = [os.path.join(i['DATA_DIR'], f) for f in os.listdir(i['DATA_DIR']) if f.startswith(DAILY_SALES_PREFIX)] for f in filenames: match = re.findall('S_D_(.*)\.txt', f) try: date = datetime.datetime.strptime(match[0], '%m-%d-%Y').date() except ValueError: # for old format data try: date = datetime.datetime.strptime(match[0], '%m%d%Y').date() except ValueError: continue d_id, created = Date.objects.get_or_create(account=i['APPSTORE_ID'], date=date) if created: d_id.populated = False else: if d_id.populated == True: continue print "[%s] is now processing..." % d_id reader = csv.DictReader(open(f), delimiter='\t') data_set = [] for row in reader: data = {} if 'Title' in row: appname = row['Title'].strip() elif 'Title / Episode / Season' in row: appname = row['Title / Episode / Season'].strip() else: raise ValueError data['appname'] = appname data['date'] = datetime.datetime.strptime(row['Begin Date'].strip(), '%m/%d/%Y').date() data['units'] = int(row['Units']) if 'Developer Proceeds' in row: proceeds = float(row['Developer Proceeds']) elif 'Royalty Price' in row: proceeds = float(row['Royalty Price']) else: raise ValueError data['proceeds'] = float(proceeds) country_code = row['Country Code'].strip() try: country = Country.objects.get(code=country_code) except: country = Country.objects.get(code='ZZ') # unknown data['country'] = country if 'Currency of Proceeds' in row: currency = row['Currency of Proceeds'].strip() elif 'Royalty Currency' in row: currency = row['Royalty Currency'].strip() else: raise ValueError data['currency'] = currency data['price'] = float(row['Customer Price'].strip()) data['ptype'] = row['Product Type Identifier'].strip() if 'SKU' in row: sku = row['SKU'].strip() elif 'Vendor Identifier' in row: sku = row['Vendor Identifier'].strip() else: raise ValueError data['sku'] = sku if 'Apple Identifier' in row: appleid = row['Apple Identifier'] else: raise ValueError data['appleid'] = appleid data_set.append(data) for data in data_set: app_id, created = App.objects.get_or_create(sku=data['sku']) if created: app_id.name = data['appname'] app_id.appleid = data['appleid'] app_id.save() else: if app_id.appleid is None: app_id.appleid = data['appleid'] app_id.save() sales = Sales() sales.app = app_id sales.date = data['date'] sales.units = data['units'] sales.proceeds = data['proceeds'] sales.country = data['country'] sales.currency = data['currency'] sales.price = data['price'] sales.ptype = data['ptype'] sales.category = sales.calc_category(data['ptype'], data['price']) sales.save() d_id.populated = True d_id.save() pass