def are_line_item_codes_valid(self, codes): code_unique = list(set(codes)) print("unique codes", code_unique) items = Item.choose(code_unique, qb=self.client) if len(items) not in [len(code_unique)]: return False return True
def get_items_from_list(self, codes): code_unique = list(set(codes)) print("unique codes", code_unique) items = Item.choose(code_unique, qb=self.client) items_result = dict() for item in items: items_result[item.Id] = item return items_result
def list(self, request): wheres = [] # prefer the "name" prefix, then the general "search" # replace spaces with hyphen, like "bottle cage" should return "Bottle-Cage-AL-Blk" name = '-'.join(request.query_params.get('name', '').split(' ')) search = '-'.join(request.query_params.get('search', '').split(' ')) if name: wheres.append("Name LIKE '{}%'".format(name)) elif search: wheres.append("Name LIKE '%{}%'".format(search)) if wheres: # always include the item type wheres.append("Type='{}'".format(self.item_type)) objects = Item.where(" and ".join(wheres), qb=self.qbo_client) else: objects = Item.filter(Type=self.item_type, qb=self.qbo_client) return Response([o.to_dict() for o in objects])
def get_item(product): """ Return the Quickbooks item object from our Product object Creates a new product if one does not exist. """ account = get_item_account(product.account_name).to_ref() item = Item.filter( max_results=1, Type="Service", Name=product.account_name, qb=client, ) if item: item = item[0] else: item = Item() item.Name = product.account_name item.Type = "Service" item.IncomeAccountRef = account item.save(qb=client) return item
def test_create(self): refund_receipt = RefundReceipt() refund_receipt.DocNumber = "DocNum123" refund_receipt.TotalAmt = 100 refund_receipt.Balance = 100 refund_receipt.PrivateNote = "Private Note" refund_receipt.PaymentType = "Check" memo = CustomerMemo() memo.value = "Customer Memo" refund_receipt.CustomerMemo = memo refund_receipt.CheckPayment = RefundReceiptCheckPayment() refund_receipt.CheckPayment.CheckNum = "1001" refund_receipt.CheckPayment.NameOnAcct = "John Smith" refund_receipt.CheckPayment.AcctNum = "0000000000" refund_receipt.CheckPayment.BankName = "Bank" item = Item.all(max_results=1, qb=self.qb_client)[0] line = DetailLine() line.DetailType = "SalesItemLineDetail" line.Amount = 200 line.SalesItemLineDetail = SalesItemLineDetail() line.SalesItemLineDetail.ItemRef = item.to_ref() refund_receipt.Line.append(line) account = Account.where("Name = 'checking'", max_results=1, qb=self.qb_client)[0] refund_receipt.DepositToAccountRef = account.to_ref() refund_receipt.save(qb=self.qb_client) query_refund_receipt = RefundReceipt.get(refund_receipt.Id, qb=self.qb_client) self.assertEqual(query_refund_receipt.DocNumber, refund_receipt.DocNumber) self.assertEqual(query_refund_receipt.Line[0].Amount, 200) self.assertEqual(refund_receipt.DepositToAccountRef.value, account.Id)
def find_or_create_item(self, name, description, income_account, category_ref): existing_items = Item.filter(Name=name, qb=self.client) if len(existing_items) == 0: logger.debug("did not find item matching '%s'" % name) logger.debug("creating new item...") new_item = Item() new_item.Name = name new_item.Description = description new_item.SubItem = True new_item.Type = "Service" new_item.ParentRef = category_ref new_item.IncomeAccountRef = income_account.to_ref() new_item.save(qb=self.client) return new_item elif len(existing_items) == 1: logger.debug("using existing item for %s" % name) value = existing_items[0] return value
def create_daily_sales(txdate, daily_reports): refresh_session() pattern = re.compile(r"\d+\.\d\d") store_refs = {x.Name: x.to_ref() for x in Department.all()} existing_receipts = { x.DepartmentRef.name if x.DepartmentRef else "20025": x for x in SalesReceipt.filter(TxnDate=qb_date_format(txdate)) } new_receipts = {} for store, sref in store_refs.items(): if store in existing_receipts: new_receipts[store] = existing_receipts[store] # clear old lines new_receipts[store].Line.clear() else: new_receipts[store] = SalesReceipt() for store, new_receipt in new_receipts.items(): if not (store in daily_reports): continue new_receipts[store].DepartmentRef = store_refs[store] new_receipt.TxnDate = qb_date_format(txdate) new_receipt.CustomerRef = Customer.all()[0].to_ref() daily_report = daily_reports[store] line_num = 1 amount_total = Decimal(0.0) for line_item, line_id in detail_map.items(): daily_report[line_item] line = SalesItemLine() line.LineNum = line_num line.Description = "{} imported from ({})".format( line_item, daily_report[line_item]) if daily_report[line_item]: if daily_report[line_item].startswith("N"): line.Amount = 0 else: line.Amount = atof( daily_report[line_item].strip("$")) * line_id[1] amount_total += Decimal(line.Amount) else: line.Amount = 0 line.SalesItemLineDetail = SalesItemLineDetail() item = Item.query("select * from Item where id = '{}'".format( line_id[0]))[0] line.SalesItemLineDetail.ItemRef = item.to_ref() line.SalesItemLineDetail.ServiceDate = None new_receipt.Line.append(line) line_num += 1 # Payin line = SalesItemLine() line.LineNum = line_num line_num += 1 line.Description = daily_report["Payins"].strip() if line.Description.count("\n") > 0: amount = Decimal(0) for payin_line in line.Description.split("\n")[1:]: if payin_line.startswith("TOTAL"): continue amount = amount + Decimal( atof(pattern.search(payin_line).group())) line.Amount = amount.quantize(TWOPLACES) amount_total += amount else: line.Amount = 0 line.SalesItemLineDetail = SalesItemLineDetail() item = Item.query("select * from Item where id = '{}'".format(43))[0] line.SalesItemLineDetail.ItemRef = item.to_ref() line.SalesItemLineDetail.ServiceDate = None new_receipt.Line.append(line) # Register Audit line = SalesItemLine() line.LineNum = line_num line_num += 1 line.Description = daily_report["Bank Deposits"].strip() # test if there was a recorded deposit if line.Description: line.Amount = Decimal(atof(line.Description.split()[4])) - Decimal( amount_total).quantize(TWOPLACES) else: line.Amount = 0 line.SalesItemLineDetail = SalesItemLineDetail() item = Item.query("select * from Item where id = '{}'".format(31))[0] line.SalesItemLineDetail.ItemRef = item.to_ref() line.SalesItemLineDetail.ServiceDate = None new_receipt.Line.append(line) new_receipt.PrivateNote = json.dumps(daily_report, indent=1) new_receipt.save() return
def get_items(self): items = Item.all(qb=self.client) for item in items: print(item.to_ref().name, item.to_ref().value) return items