Skip to content

Commit e52ae27

Browse files
committed
[ADD] l10n_us_county: Add US county to partners and leads.
1 parent 71da022 commit e52ae27

File tree

17 files changed

+3804
-0
lines changed

17 files changed

+3804
-0
lines changed

l10n_us_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_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_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_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_county>`_ project on GitHub.
76+
77+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

l10n_us_county/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

l10n_us_county/__manifest__.py

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+
"crm",
12+
"l10n_us",
13+
],
14+
"data": [
15+
"data/res.country.state.county.csv",
16+
"security/ir.model.access.csv",
17+
"views/crm_lead_views.xml",
18+
"views/partner_views.xml",
19+
],
20+
}

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

Lines changed: 3142 additions & 0 deletions
Large diffs are not rendered by default.

l10n_us_county/models/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import crm_lead
2+
from . import res_country_state_county
3+
from . import res_partner

l10n_us_county/models/crm_lead.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from odoo import api, fields, models
2+
3+
from odoo.addons.crm.models.crm_lead import PARTNER_ADDRESS_FIELDS_TO_SYNC
4+
5+
PARTNER_ADDRESS_FIELDS_TO_SYNC.extend(["county_id"])
6+
7+
8+
class Lead(models.Model):
9+
_inherit = "crm.lead"
10+
11+
county_id = fields.Many2one(
12+
"res.country.state.county",
13+
ondelete="restrict",
14+
domain="[('state_id', '=', state_id)]",
15+
)
16+
17+
@api.onchange("partner_id")
18+
def _onchange_partner_id(self):
19+
if self.partner_id.county_id.id:
20+
self.county_id = self.partner_id.county_id.id
21+
22+
# Override
23+
def _prepare_customer_values(self, partner_name, is_company, parent_id=False):
24+
values = super()._prepare_customer_values(partner_name, is_company, parent_id)
25+
values["county_id"] = self.county_id.id
26+
return values
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from odoo import fields, models
2+
3+
4+
class County(models.Model):
5+
_name = "res.country.state.county"
6+
_description = "United States County"
7+
_sql_constraints = [
8+
(
9+
"name_uniq",
10+
"unique(name, state_id)",
11+
"County name must be unique per state!",
12+
),
13+
]
14+
15+
name = fields.Char()
16+
country_id = fields.Many2one(
17+
"res.country", related="state_id.country_id", readonly=True
18+
)
19+
state_id = fields.Many2one("res.country.state")
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import logging
2+
import re
3+
4+
from odoo import fields, models
5+
from odoo.tools import ormcache
6+
7+
_logger = logging.getLogger(__name__)
8+
9+
10+
class Partner(models.Model):
11+
_inherit = "res.partner"
12+
13+
county_id = fields.Many2one(
14+
"res.country.state.county",
15+
ondelete="restrict",
16+
domain="[('state_id', '=', state_id)]",
17+
)
18+
19+
def _get_county_id(self, name, code):
20+
code = code[:2].upper()
21+
name = re.sub(r" County$", "", name)
22+
return self.__get_county_id(name, code)
23+
24+
@ormcache("self.country_id.id", "name", "state_id")
25+
def __get_county_id(self, name, code):
26+
county = self.env["res.country.state.county"].search(
27+
[
28+
("country_id", "=", self.country_id.id),
29+
("name", "=", name),
30+
("state_id.code", "=", code),
31+
],
32+
limit=1,
33+
)
34+
if not county.id:
35+
_logger.warning(f"missing county {name}, {code}")
36+
return county.id
37+
38+
@ormcache("self.country_id.id", "code")
39+
def _get_state_id(self, code):
40+
state = self.env["res.country.state"].search(
41+
[("country_id", "=", self.country_id.id), ("code", "=", code)], limit=1
42+
)
43+
if not state.id:
44+
_logger.warning(f"missing state {code}")
45+
return state.id

l10n_us_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>\>

0 commit comments

Comments
 (0)