-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathpost_install.py
25 lines (22 loc) · 1.04 KB
/
post_install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright 2014-2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api
def set_department_on_partner(cr, registry):
"""This post_install script is required because, when the module
is installed, Odoo creates the column in the DB and compute the field
and THEN it loads the file data/res_country_department.xml...
So, when it computes the field on module installation, the
departments are not available in the DB, so the country_department_id field
on res.partner stays null. This post_install script fixes this."""
env = api.Environment(cr, SUPERUSER_ID, {})
fr_countries = env["res.country"].search(
[("code", "in", ("FR", "GP", "MQ", "GF", "RE", "YT"))]
)
partners = (
env["res.partner"]
.with_context(active_test=False)
.search([("country_id", "in", fr_countries.ids)])
)
partners._compute_country_department()
return