forked from OCA/l10n-france
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_install.py
49 lines (44 loc) · 1.61 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright 2017-2020 Akretion France
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo import SUPERUSER_ID, api
logger = logging.getLogger(__name__)
def set_fr_company_intrastat(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
imdo = env["ir.model.data"]
afpo = env["account.fiscal.position"]
fr_id = env.ref("base.fr").id
companies = env["res.company"].search([("partner_id.country_id", "=", fr_id)])
fpdict = {
"intraeub2b": "b2b",
"intraeub2c": "b2c",
}
for company in companies:
company.write(
{
"intrastat_accessory_costs": True,
}
)
fps = afpo.search([("company_id", "=", company.id)])
for fp in fps:
xmlid_rec = imdo.search(
[
("model", "=", "account.fiscal.position"),
("module", "=like", "l10n_fr%"),
("res_id", "=", fp.id),
],
limit=1,
)
if xmlid_rec:
for fp_type, intrastat in fpdict.items():
if xmlid_rec.name.endswith(fp_type):
logger.debug(
"set_fr_company_intrastat writing intrastat=%s "
"on fiscal position ID %d",
intrastat,
fp.id,
)
vals = {"intrastat": intrastat}
fp.write(vals)
break