Ejemplo 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())
Ejemplo n.º 2
0
Archivo: tax.py Proyecto: 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