コード例 #1
0
ファイル: tax.py プロジェクト: jfishe/qb2gnc
    def isvendor(company):
        book = GncFile.book
        query = Query()
        query.search_for('gncVendor')
        query.set_book(book)

        for result in query.run():
            vendor = Vendor(instance=result)
            if vendor.GetName() == company:
                query.destroy()
                return vendor
        query.destroy()
        return None
コード例 #2
0
ファイル: test_business.py プロジェクト: zkw03/gnucash
    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)
コード例 #3
0
ファイル: Copy.py プロジェクト: srouden/gnucash-toolset
def CopyVendors(session, session_new):
    attributes = [
        'TaxTableOverride', 'Active', 'TaxIncluded', 'Notes', 'TaxTable'
    ]

    commodtable = session_new.book.get_table()
    for vendor in Query.getVendors(session.book):
        commod = commodtable.lookup('CURRENCY',
                                    vendor.GetCurrency().get_mnemonic())

        vendor_new = Vendor(session_new.book, vendor.GetID(), commod,
                            vendor.GetName())
        for attrib in attributes:
            getattr(vendor_new,
                    'Set' + attrib)(getattr(vendor, 'Get' + attrib)())

        _CopyAddress(vendor.GetAddr(), vendor_new.GetAddr())
コード例 #4
0
    a.append_child(a6)
    a6.SetName('Bank')
    a6.SetType(ACCT_TYPE_ASSET)
    a6.SetCommodity(CAD)

    # name isn't required, ID and currency are
    new_customer = Customer(book, "1", CAD, "Bill & Bob Industries")

    # not required, but a good idea because the GUI insists on basic address info
    address = new_customer.GetAddr()
    address.SetName("Bill & Bob")
    address.SetAddr1("201 Nowhere street")

    new_employee = Employee(book, "2", CAD, "Reliable employee")

    new_vendor = Vendor(book, "3", CAD, "Dependable vendor")

    new_job = Job(book, "4", new_vendor, "Good clean, fun")

    # 7% tax
    tax_table = TaxTable(book, "good tax",
                         TaxTableEntry(a5, True, GncNumeric(700000, 100000)))

    invoice_customer = Invoice(book, "5", CAD, new_customer)
    customer_extract = invoice_customer.GetOwner()
    assert (isinstance(customer_extract, Customer))
    assert (customer_extract.GetName() == new_customer.GetName())

    invoice_employee = Invoice(book, "6", CAD, new_employee)
    employee_extract = invoice_employee.GetOwner()
    assert (isinstance(employee_extract, Employee))
コード例 #5
0
ファイル: tax.py プロジェクト: jfishe/qb2gnc
def new_vendor(book, row, USD):
    # Assume vendomer exists. Check id and company for new vendor.
    cid = ''
    testcompany = None

    if 'company' in row.keys():
        company = row['company']
    else:
        print "Company missing in %s" % row
        return 1
        # Get company and ID from existing Vendors
    try:
        testcompany = GetVendors.isvendor(company)
        cid = testcompany.GetID()
    except AttributeError:
        pass

    if 'id' in row.keys():
        if row['id'] != cid:
            cid = row['id']
            testid = book.VendorLookupByID(cid)
        else:
            testid = testcompany
    else:
        testid = None

    if testid is None and testcompany is None:
        # If ID missing, create one
        if not cid:
            cid = book.VendorNextID()
        # Vendor not found, create.
        vend_acct = Vendor(book, cid, USD, company)
    elif testid == testcompany:
        # ID and Company match, use.
        vend_acct = testid
    elif testid is not None and testcompany is None:
        # Vendor found by ID, update Company
        vend_acct = testid
        vend_acct.SetCompany(company)
    # elif testid is None and testcompany is not None:
    else:
        if not cid:
            # Vendor found by Company, ID missing, use.
            vend_acct = testcompany
        else:
            # Vendor found by Company, update ID
            vend_acct = testcompany
            vend_acct.SetID(cid)

    try:
        assert (isinstance(vend_acct, Vendor))
    except AssertionError:
        print vend_acct, " didn't work"
        return 2

    # Update the rest if they're in the row
    address = vend_acct.GetAddr()
    if 'name' in row.keys():
        address.SetName(row['name'])
    if 'addr1' in row.keys():
        address.SetAddr1(row['addr1'])
    if 'addr2' in row.keys():
        address.SetAddr2(row['addr2'])
    if 'addr3' in row.keys():
        address.SetAddr3(row['addr3'])
    if 'addr4' in row.keys():
        address.SetAddr4(row['addr4'])
    if 'phone' in row.keys():
        address.SetPhone(row['phone'])
    if 'fax' in row.keys():
        address.SetFax(row['fax'])
    if 'email' in row.keys():
        address.SetEmail(row['email'])
    if 'notes' in row.keys():
        vend_acct.SetNotes(str(row['notes']))

    if 'tax item' in row.keys():
        tablename = row['tax item']
        try:
            vend_taxtable = book.TaxTableLookupByName(tablename)
            assert (isinstance(vend_taxtable, TaxTable))
            if 'sales tax code' in row.keys():
                sales_tax_code = row['sales tax code']
                if sales_tax_code == 'Tax':
                    vend_acct.SetTaxTable(vend_taxtable)
                    vend_acct.SetTaxTableOverride(True)
                elif sales_tax_code == 'Non':
                    vend_acct.SetTaxTable(vend_taxtable)
                    vend_acct.SetTaxTableOverride(False)
                else:
                    print "%s sales tax code %s not recognized assume Tax \
                        and use TaxTable %s" \
                          % (company, sales_tax_code, tablename)
                    vend_acct.SetTaxTable(vend_taxtable)
                    vend_acct.SetTaxTableOverride(True)
        except:
            print "%s TaxTable %s does not exist. Vendor Tax not updated" \
                  % (company, tablename)
            raise
    return 0