Esempio n. 1
0
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())
Esempio n. 2
0
File: tax.py Progetto: 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