def test_create(self): item = Item() item.Name = self.name item.Type = "Inventory" item.TrackQtyOnHand = True item.QtyOnHand = 10 item.InvStartDate = "2015-01-01" item.IncomeAccountRef = self.income_account.to_ref() item.ExpenseAccountRef = self.expense_account.to_ref() item.AssetAccountRef = self.asset_account.to_ref() item.save(qb=self.qb_client) query_item = Item.get(item.Id, qb=self.qb_client) self.assertEquals(query_item.Id, item.Id) self.assertEquals(query_item.Name, self.name) self.assertEquals(query_item.Type, "Inventory") self.assertEquals(query_item.TrackQtyOnHand, True) self.assertEquals(query_item.QtyOnHand, 10) self.assertEquals(query_item.IncomeAccountRef.value, self.income_account.Id) self.assertEquals(query_item.ExpenseAccountRef.value, self.expense_account.Id) self.assertEquals(query_item.AssetAccountRef.value, self.asset_account.Id)
def index(): client = create_qbc() item = Item() item.Name = "test" item.UnitPrice = 100 item.Type = "Service" item.save(qb=client) return item.Id
def qbo_create_item(soi): client = create_qbc() item = Item() print(soi.title) print(soi.price) item.Name = soi.title item.UnitPrice = soi.price item.Type = "Service" item.Sku = soi.sku account = Account.filter(Active=True, Name="Sales", qb=client) account_ref = Account.get(account[0].Id, qb=client).to_ref() item.IncomeAccountRef = account_ref item.save(qb=client) return item.Id
def send_to_quickbooks(self, request): # Before we ship to quickbooks, let's save the freshsheet used by this Order self.freshsheet = FreshSheet.objects.latest('published_at') self.save() client = get_qb_client() customer = Ref() # customer.value = 1 customer.value = self.created_by.qb_customer_id # customer.name = self.created_by.req_info.business_name customer.type = 'Customer' line_items = [] for item in self.items.all(): item_lookup = Item.where( f"Name = '{item.item.name}{item.unit_quantity}'", qb=client) if item_lookup: product = item_lookup[0] product.UnitPrice = item.unit_cost product.Type = 'NonInventory' product.IncomeAccountRef = Account.where( "Name = 'Sales'", qb=client)[0].to_ref() product.save(qb=client) else: product = Item() product.Name = f"{item.item.name}{item.unit_quantity}" product.UnitPrice = item.unit_cost product.Type = 'NonInventory' product.IncomeAccountRef = Account.where( "Name = 'Sales'", qb=client)[0].to_ref() product.save(qb=client) line_detail = SalesItemLineDetail() line_detail.ItemRef = product.to_ref() line_detail.UnitPrice = item.unit_cost # in dollars line_detail.Qty = item.quantity # quantity can be decimal # Need to change this date to be the DELIVERY DATE of shipment, # not the date on which it was created # Check if it's between Sunday and Tuesday (Yields Tuesday date().isoformat()) # Check if it's between Wednesday and Friday (Yields Friday date().isoformat()) line_detail.ServiceDate = get_next_service_date().isoformat() line = SalesItemLine() line.Id = '1' line.Amount = item.total_cost # in dollars line.Description = f"{item.quantity} {item.item.get_unit_verbose()} of {product.Name} from " \ f"{item.item.farm}." line.SalesItemLineDetail = line_detail line_items.append(line) invoice = Invoice() invoice.CustomerRef = customer invoice.Line = line_items invoice.save(qb=client) # NOTE: If we try to just save the user model, it _could_ overwrite some Quickbooks auth settings. # By getting a fresh model we'll for sure have the latest settings fresh_user_model = User.objects.get(pk=request.user.pk) fresh_user_model.cart = None fresh_user_model.save()