dataset/seed/odoo/templates/config_odoo.py

76 lines
4.1 KiB
Python
Raw Permalink Normal View History

2023-06-23 08:12:05 +02:00
#!/usr/bin/env python3
2022-10-01 18:57:37 +02:00
from os import environ
environ['ODOO_RC'] = '/etc/odoo/odoo.conf'
from odoo import registry, SUPERUSER_ID
from odoo.api import Environment
2023-06-23 08:12:05 +02:00
with registry('{{ general.postgresql.pg_client_database }}').cursor() as cr:
2022-10-01 18:57:37 +02:00
ctx = Environment(cr, SUPERUSER_ID, {})["res.users"].context_get()
env = Environment(cr, SUPERUSER_ID, ctx)
# Company
2023-06-23 08:12:05 +02:00
env.company.name = '{{ general.odoo.odoo_company_name }}'
env.company.street = '{{ general.odoo.odoo_company_street }}'
env.company.city = '{{ general.odoo.odoo_company_city }}'
env.company.zip = '{{ general.odoo.odoo_company_zip }}'
env.company.vat = '{{ general.odoo.odoo_company_vat }}'
env.company.company_registry = '{{ general.odoo.odoo_company_registry }}'
env.company.phone = '{{ general.odoo.odoo_company_phone }}'
env.company.mobile = '{{ general.odoo.odoo_company_mobile }}'
env.company.email = '{{ general.odoo.odoo_company_email }}'
env.company.website = '{{ general.odoo.odoo_company_website }}'
env.company.logo = '{{ general.odoo.odoo_company_logo|get_logo }}'
env.company.report_footer = '{{ general.odoo.odoo_company_footer }}'
env.company.external_report_layout_id = env.ref('web.external_layout_{{ general.odoo.odoo_company_layout }}').id
2022-10-01 18:57:37 +02:00
doc = env['base.document.layout'].create({'company_id': env.company.id})
doc._onchange_company_id()
# Admin
admin = env['res.users'].search([('name', '=', 'Administrator')])
2023-06-23 08:12:05 +02:00
admin.email = "{{ general.odoo.odoo_admin_email }}"
admin.password = '{{ general.odoo.odoo_admin_password }}'
2022-10-01 18:57:37 +02:00
# URL
2023-06-23 08:12:05 +02:00
env['ir.config_parameter'].set_param('web.base.url', 'https://{{ general.revprox.revprox_client.revprox_client_external_domainnames[0] }}')
2022-10-01 18:57:37 +02:00
env['ir.config_parameter'].set_param('web.base.url.freeze', True)
# LDAP
env['res.config.settings'].create({'module_auth_ldap': True}).execute()
ldaps = env.company.ldaps
if ldaps:
ldap = ldaps[0]
2023-06-23 08:12:05 +02:00
ldap.ldap_server = '{{ general.ldap.server.ldap_server_address }}'
2022-10-01 18:57:37 +02:00
ldap.ldap_server_port = '636'
2023-06-23 08:12:05 +02:00
ldap.ldap_binddn = '{{ general.ldap.client.ldapclient_user }}'
ldap.ldap_password = '{{ general.ldap.client.ldapclient_user_password }}'
2022-10-01 18:57:37 +02:00
ldap.ldap_filter = 'cn=%s'
2023-06-23 08:12:05 +02:00
ldap.ldap_base = '{{ general.ldap.client.ldapclient_user_dn }}'
2022-10-01 18:57:37 +02:00
else:
ldap = env['res.company.ldap'].create({'company': env.company.id,
2023-06-23 08:12:05 +02:00
'ldap_server': '{{ general.ldap.server.ldap_server_address }}',
2022-10-01 18:57:37 +02:00
'ldap_server_port': '636',
2023-06-23 08:12:05 +02:00
'ldap_binddn': '{{ general.ldap.client.ldapclient_user }}',
'ldap_password': '{{ general.ldap.client.ldapclient_user_password }}',
2022-10-01 18:57:37 +02:00
'ldap_filter': 'cn=%s',
2023-06-23 08:12:05 +02:00
'ldap_base': '{{ general.ldap.client.ldapclient_user_dn }}',
2022-10-01 18:57:37 +02:00
})
env.company.ldaps = ldap
# SMTP
mail = env['ir.mail_server'].search([('name', '=', 'Silique')])
if mail.id is False:
env['ir.mail_server'].create({'name': 'Silique',
2023-06-23 08:12:05 +02:00
'smtp_host': '{{ general.smtp.smtp_relay_address }}',
2022-10-01 18:57:37 +02:00
'smtp_port': '25',
'smtp_authentication': 'login',
2023-06-23 08:12:05 +02:00
'smtp_user': '{{ general.smtp.smtp_relay_user }}@{{ general.smtp.smtp_client_ip }}',
'smtp_pass': '{{ general.smtp.smtp_relay_password }}',
2022-10-01 18:57:37 +02:00
'smtp_encryption': 'starttls',
})
else:
2023-06-23 08:12:05 +02:00
mail.smtp_host = '{{ general.smtp.smtp_relay_address }}'
2022-10-01 18:57:37 +02:00
mail.smtp_port = '25'
mail.smtp_authentication = 'login'
2023-06-23 08:12:05 +02:00
mail.smtp_user = '{{ general.smtp.smtp_relay_user }}@{{ general.smtp.smtp_client_ip }}'
mail.smtp_pass = '{{ general.smtp.smtp_relay_password }}'
2022-10-01 18:57:37 +02:00
mail.smtp_encryption = 'starttls'
env['ir.config_parameter'].set_param('base_setup.default_external_email_server', True)