Exemplo n.º 1
0
def CopyCustomers(session, session_new):
    attributes = ['Active', 'Discount', 'TaxIncluded', 'Credit', 'Notes']
    # 'TaxTableOverride', 'Terms', 'TaxTable'
    # These attributes are not copied, and are lost.
    # you can include them to coppy and manually copy XML from the old XML
    # file to the new one !
    # Tables to copy are: <gnc:GncBillTerm version="2.0.0">
    # and <gnc:GncTaxTable version="2.0.0">
    # The TaxTable needs to be edited afterwards, since the account reference changed.

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

        customer_new = Customer(session_new.book, customer.GetID(), commod,
                                customer.GetName())
        for attrib in attributes:
            getattr(customer_new,
                    'Set' + attrib)(getattr(customer, 'Get' + attrib)())

        for job in customer.GetJoblist(True):
            job_old = Job(instance=job)
            if job_old.GetActive() == True:
                job_new = Job(book=session_new.book,
                              id=job_old.GetID(),
                              owner=customer_new,
                              name=job_old.GetName())

        _CopyAddress(customer.GetAddr(), customer_new.GetAddr())
        _CopyAddress(customer.GetShipAddr(), customer_new.GetShipAddr())
Exemplo n.º 2
0
Arquivo: tax.py Projeto: jfishe/qb2gnc
    def iscustomer(company):
        book = GncFile.book
        query = Query()
        query.search_for('gncCustomer')
        query.set_book(book)

        for result in query.run():
            customer = Customer(instance=result)
            if customer.GetName() == company:
                query.destroy()
                return customer
        query.destroy()
        return None
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    def GetCustomerByEmail(self, email):
        q = Query()
        q.search_for('gncCustomer')
        q.set_book(self._book)

        c = None

        for result in q.run():
            tmp = Customer(instance=result)
            if tmp.GetAddr().GetEmail().lower() == email.lower():
                c = tmp
                break

        q.destroy()

        return c
Exemplo n.º 5
0
    def GetCustomerByName(self, name):
        q = Query()
        q.search_for('gncCustomer')
        q.set_book(self._book)

        c = None

        for result in q.run():
            tmp = Customer(instance=result)
            if tmp.GetName().lower() in name.lower():
                c = tmp
                break

        q.destroy()

        return c
Exemplo n.º 6
0
def get_customers(book):
    customers = []
    query = Query()
    query.set_book(book)
    query.search_for("gncCustomer")
    for result in query.run():
        customers.append(Customer(instance=result))
    query.destroy()
    return customers
Exemplo n.º 7
0
def get_all_customers(book):
    """Returns all customers in book.

    Posts a query to search for all customers.

    arguments:
        book                the gnucash book to work with
    """

    query = gnucash.Query()
    query.search_for('gncCustomer')
    query.set_book(book)

    customer_list = []

    for result in query.run():
        customer_list.append(Customer(instance=result))

    query.destroy()

    return customer_list
Exemplo n.º 8
0
    a4.SetCommodity(CAD)

    a5 = Account(book)
    a4.append_child(a5)
    a5.SetName('Tax payable')
    a5.SetType(ACCT_TYPE_LIABILITY)
    a5.SetCommodity(CAD)

    a6 = Account(book)
    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)))
Exemplo n.º 9
0
Arquivo: tax.py Projeto: jfishe/qb2gnc
def new_customer(book, row, USD):
    # Assume customer exists. Check id and company for new customer.
    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 Customers
    try:
        testcompany = GetCustomers.iscustomer(company)
        cid = testcompany.GetID()
    except AttributeError:
        pass

    if 'id' in row.keys():
        if row['id'] != cid:
            cid = row['id']
            testid = book.CustomerLookupByID(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.CustomerNextID()
        # Customer not found, create.
        cust_acct = Customer(book, cid, USD, company)
    elif testid == testcompany:
        # ID and Company match, use.
        cust_acct = testid
    elif testid is not None and testcompany is None:
        # Customer found by ID, update Company
        cust_acct = testid
        cust_acct.SetCompany(company)
#    elif testid is None and testcompany is not None:
    else:
        if not cid:
            # Customer found by Company, ID missing, use.
            cust_acct = testcompany
        else:
            # Customer found by Company, update ID
            cust_acct = testcompany
            cust_acct.SetID(cid)

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

    # Update the rest if they're in the row
    address = cust_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():
        cust_acct.SetNotes(str(row['notes']))

    address = cust_acct.GetShipAddr()
    if 'shipname' in row.keys():
        address.SetName(row['shipname'])
    if 'shipaddr1' in row.keys():
        address.SetAddr1(row['shipaddr1'])
    if 'shipaddr2' in row.keys():
        address.SetAddr2(row['shipaddr2'])
    if 'shipaddr3' in row.keys():
        address.SetAddr3(row['shipaddr3'])
    if 'shipaddr4' in row.keys():
        address.SetAddr4(row['shipaddr4'])
    if 'shipphone' in row.keys():
        address.SetPhone(row['shipphone'])

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