def __invoice__str__(self): """__str__ method for Invoice""" from gnucash.gnucash_business import Invoice self = Invoice(instance=self) # This dict and the return statement can be changed according to individual needs fmt_dict = { "id_name": "ID:", "id_value": self.GetID(), "notes_name": "Notes:", "notes_value": self.GetNotes(), "active_name": "Active:", "active_value": str(self.GetActive()), "owner_name": "Owner Name:", "owner_value": self.GetOwner().GetName(), "total_name": "Total:", "total_value": str(self.GetTotal()), "currency_mnemonic": self.GetCurrency().get_mnemonic() } ret_invoice= ("{id_name:4}{id_value:10} {notes_name:7}{notes_value:20} {active_name:8}{active_value:7} {owner_name:12}{owner_value:20}"+ "{total_name:8}{total_value:10}{currency_mnemonic:3}").\ format(**all_as_classwithcutting__format__keys(**fmt_dict)) ret_entries = "" entry_list = self.GetEntries() for entry in entry_list: # Type of entry has to be checked if not (type(entry) == Entry): entry = Entry(instance=entry) ret_entries += " " + str(entry) + "\n" return ret_invoice + "\n" + ret_entries
def __entry__str__(self): """__str__ method for Entry class""" from gnucash.gnucash_business import Entry self=Entry(instance=self) return unicode(self).encode('utf-8')
def __entry__unicode__(self): """__unicode__ method for Entry""" from gnucash.gnucash_business import Entry self=Entry(instance=self) ### MWE: 2014-10-08 type error when using 'gnucash.GncNumeric' qty_val=gnucash.gnucash_core_c._gnc_numeric() qty_val=self.GetQuantity() inv_price=gnucash.gnucash_core_c._gnc_numeric() inv_price=self.GetInvPrice() ### # This dict and the return statement can be changed according to individual needs fmt_dict={ "date_name":"Date:", "date_value":unicode(self.GetDate()), "description_name":"Description:", "description_value":self.GetDescription(), "notes_name":"Notes:", "notes_value":self.GetNotes(), "quant_name":"Quantity:", ### MWE: "quant_value":unicode(gnucash.GncNumeric(instance=self.GetQuantity())), "quant_value":unicode(qty_val), "invprice_name":"InvPrice:", ### MWE: "invprice_value":unicode(gnucash.GncNumeric(instance=self.GetInvPrice()))} "invprice_value":unicode(inv_price)} return (u"{date_name:6}{date_value:15} {description_name:13}{description_value:20} {notes_name:7}{notes_value:20}"+ u"{quant_name:12}{quant_value:7} {invprice_name:10}{invprice_value:7}").\ format(**all_as_classwithcutting__format__keys(**fmt_dict))
def invoiceToDict(invoice): if invoice is None: return None else: simple_invoice = {} simple_invoice['id'] = invoice.GetID() simple_invoice['type'] = invoice.GetType() simple_invoice['date_opened'] = invoice.GetDateOpened().strftime( '%Y-%m-%d') simple_invoice['date_posted'] = invoice.GetDatePosted().strftime( '%Y-%m-%d') simple_invoice['date_due'] = invoice.GetDateDue().strftime('%Y-%m-%d') simple_invoice['notes'] = invoice.GetNotes() simple_invoice['active'] = invoice.GetActive() simple_invoice['currency'] = invoice.GetCurrency().get_mnemonic() simple_invoice['owner'] = vendorToDict(invoice.GetOwner()) simple_invoice['owner_type'] = invoice.GetOwnerType() simple_invoice['billing_id'] = invoice.GetBillingID() simple_invoice['to_charge_amount'] = invoice.GetToChargeAmount( ).to_double() simple_invoice['total'] = invoice.GetTotal().to_double() simple_invoice['total_subtotal'] = invoice.GetTotalSubtotal( ).to_double() simple_invoice['total_tax'] = invoice.GetTotalTax().to_double() simple_invoice['entries'] = {} for n, entry in enumerate(invoice.GetEntries()): if type(entry) != Entry: entry = Entry(instance=entry) simple_invoice['entries'][n] = entryToDict(entry) simple_invoice['posted'] = invoice.IsPosted() simple_invoice['paid'] = invoice.IsPaid() return simple_invoice
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)
def invoiceToDict(invoice): if invoice is None: return None else: simple_invoice = {} simple_invoice['id'] = invoice.GetID() simple_invoice['type'] = invoice.GetType() simple_invoice['date_opened'] = invoice.GetDateOpened().strftime( '%Y-%m-%d') # GetDatePosted might be null or 1970-01-01 # https://bugs.gnucash.org/show_bug.cgi?id=797147 if (invoice.GetDatePosted() is None or invoice.GetDatePosted().strftime('%Y-%m-%d') == '1970-01-01'): simple_invoice['date_posted'] = None else: simple_invoice['date_posted'] = invoice.GetDatePosted().strftime( '%Y-%m-%d') # GetDatePosted might be null or 1970-01-01 # https://bugs.gnucash.org/show_bug.cgi?id=797147 if (invoice.GetDateDue() is None or invoice.GetDateDue().strftime('%Y-%m-%d') == '1970-01-01'): simple_invoice['date_due'] = None else: simple_invoice['date_due'] = invoice.GetDateDue().strftime( '%Y-%m-%d') simple_invoice['notes'] = invoice.GetNotes() simple_invoice['active'] = invoice.GetActive() simple_invoice['currency'] = invoice.GetCurrency().get_mnemonic() owner = invoice.GetOwner() if type(owner) == gnucash.gnucash_business.Job: owner = owner.GetOwner() simple_invoice['owner'] = vendorToDict(owner) simple_invoice['owner_type'] = invoice.GetOwnerType() simple_invoice['billing_id'] = invoice.GetBillingID() simple_invoice['to_charge_amount'] = invoice.GetToChargeAmount( ).to_double() simple_invoice['posted_txn'] = transactionToDict( invoice.GetPostedTxn(), []) simple_invoice['total'] = invoice.GetTotal().to_double() simple_invoice['total_subtotal'] = invoice.GetTotalSubtotal( ).to_double() simple_invoice['total_tax'] = invoice.GetTotalTax().to_double() simple_invoice['entries'] = [] for n, entry in enumerate(invoice.GetEntries()): if type(entry) != Entry: entry = Entry(instance=entry) simple_invoice['entries'].append(entryToDict(entry)) simple_invoice['posted'] = invoice.IsPosted() simple_invoice['paid'] = invoice.IsPaid() return simple_invoice
def billToDict(bill): if bill is None: return None else: simple_bill = {} simple_bill['id'] = bill.GetID() simple_bill['type'] = bill.GetType() simple_bill['date_opened'] = bill.GetDateOpened().strftime('%Y-%m-%d') # GetDatePosted might be null or 1970-01-01 # https://bugs.gnucash.org/show_bug.cgi?id=797147 if bill.GetDatePosted() is None or bill.GetDatePosted().strftime( '%Y-%m-%d') == '1970-01-01': simple_bill['date_posted'] = None else: simple_bill['date_posted'] = bill.GetDatePosted().strftime( '%Y-%m-%d') # GetDatePosted might be null or 1970-01-01 # https://bugs.gnucash.org/show_bug.cgi?id=797147 if bill.GetDateDue() is None or bill.GetDateDue().strftime( '%Y-%m-%d') == '1970-01-01': simple_bill['date_due'] = None else: simple_bill['date_due'] = bill.GetDateDue().strftime('%Y-%m-%d') simple_bill['notes'] = bill.GetNotes() simple_bill['active'] = bill.GetActive() simple_bill['currency'] = bill.GetCurrency().get_mnemonic() simple_bill['owner'] = vendorToDict(bill.GetOwner()) simple_bill['owner_type'] = bill.GetOwnerType() simple_bill['billing_id'] = bill.GetBillingID() simple_bill['to_charge_amount'] = bill.GetToChargeAmount().to_double() simple_bill['total'] = bill.GetTotal().to_double() simple_bill['total_subtotal'] = bill.GetTotalSubtotal().to_double() simple_bill['total_tax'] = bill.GetTotalTax().to_double() simple_bill['entries'] = [] for n, entry in enumerate(bill.GetEntries()): if type(entry) != Entry: entry = Entry(instance=entry) simple_bill['entries'].append(entryToDict(entry)) simple_bill['posted'] = bill.IsPosted() simple_bill['paid'] = bill.IsPaid() return simple_bill
def __entry__str__(self): """__str__ method for Entry""" from gnucash.gnucash_business import Entry self = Entry(instance=self) # This dict and the return statement can be changed according to individual needs fmt_dict = { "date_name": "Date:", "date_value": str(self.GetDate()), "description_name": "Description:", "description_value": self.GetDescription(), "notes_name": "Notes:", "notes_value": self.GetNotes(), "quant_name": "Quantity:", "quant_value": str(self.GetQuantity()), "invprice_name": "InvPrice:", "invprice_value": str(self.GetInvPrice()) } return ("{date_name:6}{date_value:15} {description_name:13}{description_value:20} {notes_name:7}{notes_value:20}"+ "{quant_name:12}{quant_value:7} {invprice_name:10}{invprice_value:7}").\ format(**all_as_classwithcutting__format__keys(**fmt_dict))
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()
invoice_employee = Invoice(book, "6", CAD, new_employee) employee_extract = invoice_employee.GetOwner() assert (isinstance(employee_extract, Employee)) 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)
def invoice_to_lco(invoice): """returns a string which forms a lco-file for use with LaTeX""" lco_out = u"\ProvidesFile{data.lco}[]\n" def write_variable(ukey, uvalue, replace_linebreak=True): outstr = u"" if uvalue.endswith("\n"): uvalue = uvalue[0:len(uvalue) - 1] if not ukey in [u"fromaddress", u"toaddress", u"date"]: outstr += u'\\newkomavar{' outstr += ukey outstr += u"}\n" outstr += u"\\setkomavar{" outstr += ukey outstr += u"}{" if replace_linebreak: outstr += uvalue.replace(u"\n", u"\\\\") + "}" return outstr # Write owners address add_str = u"" owner = invoice.GetOwner() if owner.GetName() != "": add_str += owner.GetName().decode("UTF-8") + "\n" addr = owner.GetAddr() if addr.GetName() != "": add_str += addr.GetName().decode("UTF-8") + "\n" if addr.GetAddr1() != "": add_str += addr.GetAddr1().decode("UTF-8") + "\n" if addr.GetAddr2() != "": add_str += addr.GetAddr2().decode("UTF-8") + "\n" if addr.GetAddr3() != "": add_str += addr.GetAddr3().decode("UTF-8") + "\n" if addr.GetAddr4() != "": add_str += addr.GetAddr4().decode("UTF-8") + "\n" lco_out += write_variable("toaddress2", add_str) # Invoice number inr_str = invoice.GetID() lco_out += write_variable("rechnungsnummer", inr_str) # date date = invoice.GetDatePosted() udate = date.strftime("%d.%m.%Y") lco_out += write_variable("date", udate) + "\n" # date due date_due = invoice.GetDateDue() udate_due = date_due.strftime("%d.%m.%Y") lco_out += write_variable("date_due", udate_due) + "\n" # Write the entries ent_str = u"" locale.setlocale(locale.LC_ALL, "de_DE") for n, ent in enumerate(invoice.GetEntries()): line_str = u"" if type(ent) != Entry: ent = Entry(instance=ent) # Add to method_returns_list descr = ent.GetDescription() price = ent.GetInvPrice().to_double() n = ent.GetQuantity() uprice = locale.currency(price).rstrip(" EUR") un = unicode(int(float(n.num()) / n.denom()) ) # choose best way to format numbers according to locale line_str = u"\Artikel{" line_str += un line_str += u"}{" line_str += descr.decode("UTF-8") line_str += u"}{" line_str += uprice line_str += u"}" #print(line_str) ent_str += line_str lco_out += write_variable("entries", ent_str) return lco_out
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
def invoice_to_lco(invoice): """returns a string which forms a lco-file for use with LaTeX""" lco_out=u"\ProvidesFile{data.lco}[]\n\\usepackage[utf8]{inputenc}\n" def write_variable(ukey, uvalue, replace_linebreak=True): outstr = u"" if uvalue.endswith("\n"): uvalue=uvalue[0:len(uvalue)-1] if not ukey in [u"fromaddress",u"toaddress",u"date"]: outstr += u'\\newkomavar{' outstr += ukey outstr += u"}\n" outstr += u"\\setkomavar{" outstr += ukey outstr += u"}{" if replace_linebreak: outstr += uvalue.replace(u"\n",u"\\\\")+"}" return outstr # Write owners address add_str=u"" owner = invoice.GetOwner() if owner.GetName() != "": add_str += owner.GetName()+"\n" ### MWE: 2014-10-08 double? owner.GetName() vs. addr.GetName() # if addr.GetName() != "": # add_str += addr.GetName().decode("UTF-8")+"\n" def mkaddr(addr): result = u"" if addr == None: return u"" if addr.GetAddr1() != "": result += addr.GetAddr1().decode("UTF-8")+"\n" if addr.GetAddr2() != "": result += addr.GetAddr2().decode("UTF-8")+"\n" if addr.GetAddr3() != "": result += addr.GetAddr3().decode("UTF-8")+"\n" if addr.GetAddr4() != "": result += addr.GetAddr4().decode("UTF-8")+"\n" return result add_str += mkaddr(owner.GetAddr()) lco_out += write_variable("toaddress2",add_str) # Invoice number inr_str = invoice.GetID() lco_out += write_variable("rechnungsnummer",inr_str) # date date = invoice.GetDatePosted() udate = date.strftime("%d.%m.%Y") lco_out += write_variable("date",udate)+"\n" # date due date_due = invoice.GetDateDue() udate_due = date_due.strftime("%d.%m.%Y") lco_out += write_variable("date_due",udate_due)+"\n" lco_out += write_variable("description", str(invoice.GetNotes())) # Write the entries ent_str = u"" ### MWE: locale.setlocale(locale.LC_ALL,"de_DE") taxes = 0.0 bruto = 0.0 total = 0.0 for n,ent in enumerate(invoice.GetEntries()): line_str = u"" if type(ent) != Entry: ent=Entry(instance=ent) # Add to method_returns_list descr = ent.GetDescription() ### MWE: 2014-10-08 type error when using 'gnucash.GncNumeric' price = gnucash.gnucash_core_c._gnc_numeric() price = ent.GetInvPrice().to_double() taxval = ent.GetDocTaxValue(True,True,False) n = gnucash.gnucash_core_c._gnc_numeric() n = instance=ent.GetQuantity() # change gncucash_core.py locale.setlocale( locale.LC_ALL, '' ) uprice = locale.currency(price/1.21).rstrip(" EUR").rstrip(" €").strip("€ ") ### MWE: 2014-10-08 use float instead of int. ### Otherwise decimal places will be cut and nobody want to spend 0.75 h for nothing but stupid software. quantity = float(n.num())/n.denom() un = unicode(quantity) # choose best way to format numbers according to locale curtaxes = GncNumeric(taxval.num, taxval.denom).to_double() curprice = price*quantity taxes += curtaxes total += curprice bruto += curprice - curtaxes line_str = u"\Artikel{" line_str += un line_str += u"}{" line_str += descr.decode("UTF-8") line_str += u"}{" line_str += uprice line_str += u"}" print(ent.GetAction()) # Perhaps to add the action table?? line_str += u"{" line_str += "uur" if ent.GetAction() == "Uren" else "art." line_str += u"}" #print line_str ent_str += line_str lco_out += write_variable("taxes", str(round(taxes,2))) lco_out += write_variable("bruto", str(round(bruto,2))) lco_out += write_variable("total", str(round(total,2))) lco_out += write_variable("entries",ent_str) return lco_out