forked from OCA/l10n-france
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_install.py
32 lines (25 loc) · 1006 Bytes
/
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
26
27
28
29
30
31
32
# Copyright 2021-2022 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from stdnum.fr.siret import is_valid
from odoo import SUPERUSER_ID, api
logger = logging.getLogger(__name__)
def set_siren_nic(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
partners = (
env["res.partner"]
.with_context(active_test=False)
.search([("siret", "!=", False), ("parent_id", "=", False)])
)
for partner in partners:
if is_valid(partner.siret):
logger.info("Setting SIREN and NIC on partner %s", partner.display_name)
partner.write({"siret": partner.siret})
else:
logger.warning(
"Remove SIRET %s on partner %s because checksum is wrong",
partner.siret,
partner.display_name,
)
partner.write({"siret": False})