Skip to content

Commit 3d0d61f

Browse files
committed
Merge PR #154 into 18.0
Signed-off-by jelenapoblet
2 parents 5e14584 + fbf77b4 commit 3d0d61f

29 files changed

+4516
-0
lines changed

l10n_us_base_county/README.rst

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
========================
2+
United States - Counties
3+
========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:2774e2288b2c4e5344ace576a97fe9755f506c9e53441849da544ec0451ccd1b
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--usa-lightgray.png?logo=github
20+
:target: https://github.com/OCA/l10n-usa/tree/18.0/l10n_us_base_county
21+
:alt: OCA/l10n-usa
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/l10n-usa-18-0/l10n-usa-18-0-l10n_us_base_county
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-usa&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
Imported from U.S. Census Bureau data.
32+
https://www.census.gov/library/publications/2011/compendia/usa-counties-2011.html
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Bug Tracker
40+
===========
41+
42+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-usa/issues>`_.
43+
In case of trouble, please check there if your issue has already been reported.
44+
If you spotted it first, help us to smash it by providing a detailed and welcomed
45+
`feedback <https://github.com/OCA/l10n-usa/issues/new?body=module:%20l10n_us_base_county%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
46+
47+
Do not contact contributors directly about support or help with technical issues.
48+
49+
Credits
50+
=======
51+
52+
Authors
53+
-------
54+
55+
* MetricWise
56+
57+
Contributors
58+
------------
59+
60+
- Adam Heinz <adam.heinz@metricwise.com>
61+
62+
Maintainers
63+
-----------
64+
65+
This module is maintained by the OCA.
66+
67+
.. image:: https://odoo-community.org/logo.png
68+
:alt: Odoo Community Association
69+
:target: https://odoo-community.org
70+
71+
OCA, or the Odoo Community Association, is a nonprofit organization whose
72+
mission is to support the collaborative development of Odoo features and
73+
promote its widespread use.
74+
75+
This module is part of the `OCA/l10n-usa <https://github.com/OCA/l10n-usa/tree/18.0/l10n_us_base_county>`_ project on GitHub.
76+
77+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

l10n_us_base_county/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "United States - Counties",
3+
"version": "18.0.0.0.0",
4+
"category": "Localization",
5+
"summary": "Add United States counties.",
6+
"author": "MetricWise, Odoo Community Association (OCA)",
7+
"license": "LGPL-3",
8+
"maintainer": "Adam Heinz <adam.heinz@metricwise.com>",
9+
"website": "https://github.com/OCA/l10n-usa",
10+
"depends": [
11+
"contacts",
12+
"l10n_us",
13+
],
14+
"data": [
15+
"data/res.country.state.county.csv",
16+
"security/ir.model.access.csv",
17+
"views/res_country_state_county_views.xml",
18+
"views/res_partner_views.xml",
19+
],
20+
}

l10n_us_base_county/data/res.country.state.county.csv

Lines changed: 3142 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import res_country_state_county
2+
from . import res_partner
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import logging
2+
3+
import xlrd
4+
5+
from odoo import fields, models
6+
7+
_logger = logging.getLogger(__name__)
8+
9+
10+
class County(models.Model):
11+
_name = "res.country.state.county"
12+
_description = "United States County"
13+
_sql_constraints = [
14+
(
15+
"name_uniq",
16+
"unique(name, state_id)",
17+
"County name must be unique per state!",
18+
),
19+
]
20+
21+
name = fields.Char()
22+
country_id = fields.Many2one(
23+
"res.country", related="state_id.country_id", readonly=True
24+
)
25+
state_id = fields.Many2one("res.country.state")
26+
27+
def _import_counties(self, file_contents):
28+
"""Import Excel spreadsheet from U.S. Census Bureau.
29+
See https://www.census.gov/library/publications/2011/compendia/usa-counties-2011.html"""
30+
self.check_access("create")
31+
32+
country_id = self.env.ref("base.us").id
33+
34+
def get_state_id(code):
35+
return (
36+
self.env["res.country.state"]
37+
.search(
38+
[
39+
("country_id", "=", country_id),
40+
("code", "=", code),
41+
],
42+
limit=1,
43+
)
44+
.id
45+
)
46+
47+
# https://www2.census.gov/library/publications/2011/compendia/usa-counties/excel/LND01.xls
48+
workbook = xlrd.open_workbook(filename="LND01.xls", file_contents=file_contents)
49+
sheet = workbook.sheet_by_index(0)
50+
for i, row in enumerate(sheet.get_rows()):
51+
if i == 0:
52+
assert row[0].value == "Areaname", row
53+
assert row[1].value == "STCOU"
54+
continue
55+
56+
areaname = row[0].value
57+
stcou = int(row[1].value)
58+
if (stcou % 1000) == 0:
59+
_logger.debug("reading %s", areaname)
60+
continue
61+
62+
if not areaname:
63+
continue
64+
if ", " not in areaname:
65+
if areaname == "District of Columbia":
66+
areaname += ", DC"
67+
else:
68+
_logger.warning("skipping %s", areaname)
69+
continue
70+
71+
county_name, state_code = areaname.split(", ")
72+
state_id = get_state_id(state_code)
73+
if self.search([("name", "=", county_name), ("state_id", "=", state_id)]):
74+
_logger.warning("skipping duplicate %s", areaname)
75+
continue
76+
77+
county = self.create(
78+
{
79+
"name": county_name,
80+
"state_id": get_state_id(state_code),
81+
}
82+
)
83+
self.env["ir.model.data"].create(
84+
{
85+
"module": "l10n_us_base_county",
86+
"model": self._name,
87+
"name": f"res_country_state_county_{stcou}",
88+
"res_id": county.id,
89+
}
90+
)
91+
_logger.info("created %s", areaname)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from odoo import fields, models
2+
3+
4+
class Partner(models.Model):
5+
_inherit = "res.partner"
6+
7+
county_id = fields.Many2one(
8+
"res.country.state.county",
9+
ondelete="restrict",
10+
domain="[('state_id', '=', state_id)]",
11+
)

l10n_us_base_county/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Adam Heinz \<<adam.heinz@metricwise.com>\>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Imported from U.S. Census Bureau data.
2+
https://www.census.gov/library/publications/2011/compendia/usa-counties-2011.html

0 commit comments

Comments
 (0)