-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactored shared code into common file - introduced --from argument to limit the amount of taxes imported - allowed the account to be set, not hard-coded - Added state-specific tax accounts from accout_us
- Loading branch information
Showing
4 changed files
with
341 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<tryton> | ||
<data depends="account_us"> | ||
|
||
<record model="account.account.template" id="2230_AR"> | ||
<field name="name">Sales tax collected—Arkansas</field> | ||
<field name="code">2230-AR</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_GA"> | ||
<field name="name">Sales tax collected—Georgia</field> | ||
<field name="code">2230-GA</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_IA"> | ||
<field name="name">Sales tax collected—Iowa</field> | ||
<field name="code">2230-IA</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_IN"> | ||
<field name="name">Sales tax collected—Indiana</field> | ||
<field name="code">2230-IN</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_KS"> | ||
<field name="name">Sales tax collected—Kansas</field> | ||
<field name="code">2230-KS</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_KY"> | ||
<field name="name">Sales tax collected—Kentucky</field> | ||
<field name="code">2230-KY</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_MI"> | ||
<field name="name">Sales tax collected—Michigan</field> | ||
<field name="code">2230-MI</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_MN"> | ||
<field name="name">Sales tax collected—Minnesota</field> | ||
<field name="code">2230-MN</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_NC"> | ||
<field name="name">Sales tax collected—North Carolina</field> | ||
<field name="code">2230-NC</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_ND"> | ||
<field name="name">Sales tax collected—North Dakota</field> | ||
<field name="code">2230-ND</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_NE"> | ||
<field name="name">Sales tax collected—Nebraska</field> | ||
<field name="code">2230-NE</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_NJ"> | ||
<field name="name">Sales tax collected—New Jersey</field> | ||
<field name="code">2230-NJ</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_NV"> | ||
<field name="name">Sales tax collected—Nevada</field> | ||
<field name="code">2230-NV</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_OH"> | ||
<field name="name">Sales tax collected—Ohio</field> | ||
<field name="code">2230-OH</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_OK"> | ||
<field name="name">Sales tax collected—Oklahoma</field> | ||
<field name="code">2230-OK</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_RI"> | ||
<field name="name">Sales tax collected—Rhode Island</field> | ||
<field name="code">2230-RI</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_SD"> | ||
<field name="name">Sales tax collected—South Dakota</field> | ||
<field name="code">2230-SD</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_TN"> | ||
<field name="name">Sales tax collected—Tennessee</field> | ||
<field name="code">2230-TN</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_UT"> | ||
<field name="name">Sales tax collected—Utah</field> | ||
<field name="code">2230-UT</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_VT"> | ||
<field name="name">Sales tax collected—Vermont</field> | ||
<field name="code">2230-VT</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_WA"> | ||
<field name="name">Sales tax collected—Washington</field> | ||
<field name="code">2230-WA</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_WI"> | ||
<field name="name">Sales tax collected—Wisconsin</field> | ||
<field name="code">2230-WI</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_WV"> | ||
<field name="name">Sales tax collected—West Virginia</field> | ||
<field name="code">2230-WV</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
<record model="account.account.template" id="2230_WY"> | ||
<field name="name">Sales tax collected—Wyoming</field> | ||
<field name="code">2230-WY</field> | ||
<field name="type" ref="account_us.tax_liabilities"/> | ||
<field name="party_required" eval="True"/> | ||
<field name="parent" ref="account_us.2230"/> | ||
</record> | ||
|
||
</data> | ||
</tryton> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
import sys | ||
|
||
from html.parser import HTMLParser | ||
import zipfile | ||
from io import BytesIO, TextIOWrapper | ||
|
||
try: | ||
from urllib.error import HTTPError | ||
from urllib.request import urlopen | ||
from urllib.parse import urljoin | ||
except ImportError: | ||
from urllib2 import urlopen, HTTPError | ||
|
||
try: | ||
from progressbar import ETA, Bar, ProgressBar, SimpleProgress | ||
except ImportError: | ||
ProgressBar = None | ||
|
||
try: | ||
from proteus import Model, config | ||
except ImportError: | ||
prog = os.path.basename(sys.argv[0]) | ||
sys.exit("proteus must be installed to use %s" % prog) | ||
|
||
class LinksExtractor(HTMLParser): | ||
def __init__(self): | ||
super().__init__() | ||
self.links = [] | ||
|
||
def handle_starttag(self, tag, attrs): | ||
if tag == 'a': | ||
for attr in attrs: | ||
if attr[0] == 'href': | ||
self.links.append(attr[1]) | ||
|
||
def get_links(self): | ||
return self.links | ||
|
||
def _progress(iterable): | ||
if ProgressBar: | ||
pbar = ProgressBar( | ||
widgets=[SimpleProgress(), Bar(), ETA()]) | ||
else: | ||
pbar = iter | ||
return pbar(iterable) | ||
|
||
def _remove_forbidden_chars(name): | ||
from trytond.tools import remove_forbidden_chars | ||
return remove_forbidden_chars(name) | ||
|
||
def fetch(code, base): | ||
sys.stderr.write('Fetching') | ||
sys.stderr.flush() | ||
try: | ||
responce = urlopen(base) | ||
except HTTPError as e: | ||
sys.exit("\nError fetching directory listing: %s" % e.reason) | ||
parser = LinksExtractor() | ||
parser.feed(TextIOWrapper(responce, encoding='utf-8').read()) | ||
parser.close() | ||
|
||
files = {os.path.basename(a)[:2]: urljoin(base, a) for a in parser.get_links()} | ||
|
||
try: | ||
responce = urlopen(files[code]) | ||
except KeyError: | ||
sys.exit("\nFile not found for code: %s" % code) | ||
except HTTPError as e: | ||
sys.exit("\nError downloading %s: %s" % (code, e.reason)) | ||
data = responce.read() | ||
|
||
root, ext = os.path.splitext(responce.url) | ||
if ext == '.zip': | ||
with zipfile.ZipFile(BytesIO(data)) as zf: | ||
data = zf.read(os.path.basename(root) + '.csv') | ||
print('.', file=sys.stderr) | ||
return data | ||
|
||
def get_places(code): | ||
Place = Model.get('census.place') | ||
return {p.code_fips: p for p in Place.find([('subdivision.code', '=', code)])} | ||
|
Oops, something went wrong.