def setUp(self): BookSession.setUp(self) self.today = datetime.today() self.bank = Account(self.book) self.bank.SetType(ACCT_TYPE_BANK) self.bank.SetCommodity(self.currency) self.income = Account(self.book) self.income.SetType(ACCT_TYPE_INCOME) self.income.SetCommodity(self.currency) self.receivable = Account(self.book) self.receivable.SetType(ACCT_TYPE_RECEIVABLE) self.receivable.SetCommodity(self.currency) self.customer = Customer(self.book,'CustomerID',self.currency) self.vendor = Vendor(self.book,'VendorID',self.currency) self.employee = Employee(self.book,'EmployeeID',self.currency) self.job = Job(self.book,'JobID',self.customer) self.invoice = Invoice(self.book,'InvoiceID',self.currency,self.customer) self.invoice.SetDateOpened(self.today) entry = Entry(self.book) entry.SetDate(self.today) entry.SetDescription("Some income") entry.SetQuantity(GncNumeric(1)) entry.SetInvAccount(self.income) entry.SetInvPrice(GncNumeric(100)) self.invoice.AddEntry(entry) self.invoice.PostToAccount(self.receivable, self.today, self.today, "", True, False)
assert (employee_extract.GetName() == new_employee.GetName()) invoice_vendor = Invoice(book, "7", CAD, new_vendor) vendor_extract = invoice_vendor.GetOwner() assert (isinstance(vendor_extract, Vendor)) assert (vendor_extract.GetName() == new_vendor.GetName()) invoice_job = Invoice(book, "8", CAD, new_job) job_extract = invoice_job.GetOwner() assert (isinstance(job_extract, Job)) assert (job_extract.GetName() == new_job.GetName()) invoice_entry = Entry(book, invoice_customer) invoice_entry.SetInvTaxTable(tax_table) invoice_entry.SetInvTaxIncluded(False) invoice_entry.SetDescription("excellent product") invoice_entry.SetQuantity(GncNumeric(1)) invoice_entry.SetInvAccount(a3) invoice_entry.SetInvPrice(GncNumeric(1)) invoice_entry.SetDateEntered(datetime.datetime.now()) invoice_customer.PostToAccount(a2, datetime.date.today(), datetime.date.today(), "the memo", True, False) new_customer.ApplyPayment(None, None, a2, a6, GncNumeric(100, 100), GncNumeric(1), datetime.date.today(), "", "", True) invoice_customer.ApplyPayment(None, a6, GncNumeric(7, 100), GncNumeric(1), datetime.date.today(), "", "")
book = s.book root = book.get_root_account() commod_table = book.get_table() CAD = commod_table.lookup('CURRENCY', 'CAD') my_customer = book.CustomerLookupByID(argv[2]) assert (my_customer != None) assert (isinstance(my_customer, Customer)) assets = root.lookup_by_name("Assets") receivables = assets.lookup_by_name("Receivables") income = root.lookup_by_name("Income") invoice = Invoice(book, argv[3], CAD, my_customer) description = argv[4] invoice_value = gnc_numeric_from_decimal(Decimal(argv[5])) tax_table = book.TaxTableLookupByName('good tax') invoice_entry = Entry(book, invoice) invoice_entry.SetInvTaxTable(tax_table) invoice_entry.SetInvTaxIncluded(False) invoice_entry.SetDescription(description) invoice_entry.SetQuantity(GncNumeric(1)) invoice_entry.SetInvAccount(income) invoice_entry.SetInvPrice(invoice_value) invoice.PostToAccount(receivables, datetime.date.today(), datetime.date.today(), "", True, False) s.save() s.end()
def new_transaction(root, book, out, USD): # global existing_customers, existing_vendors # Assemble the invoice dictionary isinvoice = False isbill = False isinvpayment = False isbillpayment = False isentry = False for row in out: if 'type' in row.keys(): rtype = row['type'] else: rtype = '' if rtype: new_rtype, date_opened = get_rtype(row) new_rtype['entries'] = [] if rtype == 'Invoice': isinvoice = True elif rtype == 'Payment': isinvpayment = True elif rtype == 'Sales Tax Payment': isentry = True elif rtype == 'Paycheck': continue elif rtype == 'Bill': isbill = True elif rtype == 'Credit': isbill = True elif rtype == 'Bill Pmt -CCard': isbillpayment = True else: isentry = True elif 'account' in row.keys(): if row['account']: test, new_entry = get_entries(row, date_opened) if test == 'tax_table': new_rtype['tax_table'] = new_entry['tax_table'] new_rtype['tax_rate'] = new_entry['price'] elif test == 'entry': new_rtype['entries'].append(new_entry) # No account in total row, so process entries elif isentry: trans1 = Transaction(book) trans1.BeginEdit() trans1.SetCurrency(USD) if 'owner' in new_rtype.keys(): trans1.SetDescription(new_rtype['owner']) trans1.SetDateEnteredTS( new_rtype['date_opened'] + datetime.timedelta(microseconds=1)) trans1.SetDatePostedTS( new_rtype['date_opened'] + datetime.timedelta(microseconds=1)) if 'num' in new_rtype.keys(): trans1.SetNum(new_rtype['num']) if 'notes' in new_rtype.keys(): trans1.SetNotes = new_rtype['notes'] if new_rtype['account'] != '-SPLIT-': split1 = Split(book) split1.SetParent(trans1) # if new_rtype['type'] == 'Deposit': # new_rtype['amount'] = new_rtype['amount'].neg() split1.SetAccount(root.lookup_by_name(new_rtype['account'])) # if split1.GetAccount() == ACCT_TYPE_EQUITY: # isequity = True # new_rtype['amount'] = new_rtype['amount'].neg() # else: # isequity = False split1.SetValue(new_rtype['amount']) if 'owner' in new_rtype.keys(): split1.SetMemo(new_rtype['owner']) # split1.SetAction(get_action(new_rtype['type'])) for entry in new_rtype['entries']: if 'amount' in entry.keys(): split1 = Split(book) split1.SetParent(trans1) # if isequity: # entry['amount'] = entry['amount'].neg() split1.SetValue(entry['amount']) split1.SetAccount(root.lookup_by_name(entry['account'])) if 'description' in entry.keys(): split1.SetMemo(entry['description']) # split1.SetAction(get_action(new_rtype['type'])) trans1.CommitEdit() isentry = False elif isinvpayment: try: owner = GetCustomers.iscustomer(new_rtype['owner']) assert (isinstance(owner, Customer)) except AssertionError: print 'Customer %s does not exist; skipping' % \ new_rtype['owner'] continue xfer_acc = root.lookup_by_name(new_rtype['account']) date_opened = new_rtype['date_opened'] if 'notes' in new_rtype.keys(): notes = new_rtype['notes'] else: notes = '' if 'num' in new_rtype.keys(): num = new_rtype['num'] else: num = '' for entry in new_rtype['entries']: posted_acc = root.lookup_by_name(entry['account']) owner.ApplyPayment(None, None, posted_acc, xfer_acc, new_rtype['amount'], entry['amount'], date_opened, notes, num, False) isinvpayment = False elif isbillpayment: try: owner = GetVendors.isvendor(new_rtype['owner']) assert (isinstance(owner, Vendor)) except AssertionError: print 'Vendor %s does not exist; skipping' % \ new_rtype['owner'] continue xfer_acc = root.lookup_by_name(new_rtype['account']) date_opened = new_rtype['date_opened'] if 'notes' in new_rtype.keys(): notes = new_rtype['notes'] else: notes = '' if 'num' in new_rtype.keys(): num = new_rtype['num'] else: num = '' for entry in new_rtype['entries']: posted_acc = root.lookup_by_name(entry['account']) owner.ApplyPayment(None, None, posted_acc, xfer_acc, new_rtype['amount'], entry['amount'], date_opened, notes, num, False) isbillpayment = False # new_customer.ApplyPayment(self, invoice, posted_acc, xfer_acc, amount, # exch, date, memo, num) # new_customer.ApplyPayment(None, None, a2, a6, GncNumeric(100,100), # GncNumeric(1), datetime.date.today(), "", "", False) # invoice_customer.ApplyPayment(None, a6, GncNumeric(7,100), # GncNumeric(1), datetime.date.today(), "", "") elif isbill: # put item on entries!!! # Accumulate splits # QuickBooks Journal has a total row after splits, # which is used to detect the end of splits. try: owner = GetVendors.isvendor(new_rtype['owner']) assert (isinstance(owner, Vendor)) except AssertionError: print 'Vendor %s does not exist; skipping' % \ new_rtype['owner'] continue try: cid = book.BillNextID(owner) # save Bill ID and tax rate for xml overlay. # ReplaceTax.bill(cid, new_rtype['tax_rate']) except: raise bill_vendor = Bill(book, cid, USD, owner) vendor_extract = bill_vendor.GetOwner() assert (isinstance(vendor_extract, Vendor)) assert (vendor_extract.GetName() == owner.GetName()) if new_rtype['type'] == 'Credit': bill_vendor.SetIsCreditNote(True) bill_vendor.SetDateOpened(new_rtype['date_opened']) if 'notes' in new_rtype.keys(): bill_vendor.SetNotes(new_rtype['notes']) if 'num' in new_rtype.keys(): bill_vendor.SetBillingID(new_rtype['num']) if 'tax_table' in new_rtype.keys(): tax_table = book.TaxTableLookupByName(new_rtype['tax_table']) assert (isinstance(tax_table, TaxTable)) # Add the entries for entry in new_rtype['entries']: # skip entries that link COGS and Billentory if 'quantity' not in entry.keys(): continue bill_entry = Entry(book, bill_vendor) account = root.lookup_by_name(entry['account']) assert (isinstance(account, Account)) bill_entry.SetBillAccount(account) if 'tax_table' in new_rtype.keys(): bill_entry.SetBillTaxTable(tax_table) bill_entry.SetBillTaxIncluded(False) else: bill_entry.SetBillTaxable(False) if 'description' in entry.keys(): bill_entry.SetDescription(entry['description']) bill_entry.SetQuantity(entry['quantity']) bill_entry.SetBillPrice(entry['price']) bill_entry.SetDateEntered(entry['date']) bill_entry.SetDate(entry['date']) if 'notes' in entry.keys(): bill_entry.SetNotes(entry['notes']) isbill = False # Post bill account = root.lookup_by_name(new_rtype['account']) assert (isinstance(account, Account)) bill_vendor.PostToAccount(account, new_rtype['date_opened'], new_rtype['date_opened'], str(new_rtype['owner']), True, False) elif isinvoice: # put item on entries!!! # Accumulate splits # QuickBooks Journal has a total row after splits, # which is used to detect the end of splits. try: owner = GetCustomers.iscustomer(new_rtype['owner']) assert (isinstance(owner, Customer)) except AssertionError: print 'Customer %s does not exist; skipping' % \ new_rtype['owner'] continue try: cid = book.InvoiceNextID(owner) # save Invoice ID and tax rate for xml overlay. # ReplaceTax.invoice(cid, new_rtype['tax_rate']) except: raise invoice_customer = Invoice(book, cid, USD, owner) customer_extract = invoice_customer.GetOwner() assert (isinstance(customer_extract, Customer)) assert (customer_extract.GetName() == owner.GetName()) invoice_customer.SetDateOpened(new_rtype['date_opened']) if 'notes' in new_rtype.keys(): invoice_customer.SetNotes(new_rtype['notes']) if 'num' in new_rtype.keys(): invoice_customer.SetBillingID(new_rtype['num']) if 'tax_table' in new_rtype.keys(): tax_table = book.TaxTableLookupByName(new_rtype['tax_table']) assert (isinstance(tax_table, TaxTable)) # assert( not isinstance( \ # book.InvoiceLookupByID(new_rtype['id']), Invoice)) # Add the entries for entry in new_rtype['entries']: invoice_entry = Entry(book, invoice_customer) account = root.lookup_by_name(entry['account']) assert (isinstance(account, Account)) invoice_entry.SetInvAccount(account) if 'tax_table' in new_rtype.keys(): invoice_entry.SetInvTaxTable(tax_table) invoice_entry.SetInvTaxIncluded(False) else: invoice_entry.SetInvTaxable(False) invoice_entry.SetDescription(entry['description']) invoice_entry.SetQuantity(entry['quantity']) invoice_entry.SetInvPrice(entry['price']) invoice_entry.SetDateEntered(entry['date']) invoice_entry.SetDate(entry['date']) if 'notes' in entry.keys(): invoice_entry.SetNotes(entry['notes']) isinvoice = False # Post invoice account = root.lookup_by_name(new_rtype['account']) assert (isinstance(account, Account)) invoice_customer.PostToAccount(account, new_rtype['date_opened'], new_rtype['date_opened'], str(new_rtype['owner']), True, False) # ReplaceTax.replace(gnc_file.path) return 0