dataset/seed/odoo/templates/config_odoo.py

75 lines
4.1 KiB
Python

#!/usr/bin/env python3
from os import environ
environ['ODOO_RC'] = '/etc/odoo/odoo.conf'
from odoo import registry, SUPERUSER_ID
from odoo.api import Environment
with registry('{{ general.postgresql.pg_client_database }}').cursor() as cr:
ctx = Environment(cr, SUPERUSER_ID, {})["res.users"].context_get()
env = Environment(cr, SUPERUSER_ID, ctx)
# Company
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
doc = env['base.document.layout'].create({'company_id': env.company.id})
doc._onchange_company_id()
# Admin
admin = env['res.users'].search([('name', '=', 'Administrator')])
admin.email = "{{ general.odoo.odoo_admin_email }}"
admin.password = '{{ general.odoo.odoo_admin_password }}'
# URL
env['ir.config_parameter'].set_param('web.base.url', 'https://{{ general.revprox.revprox_client.revprox_client_external_domainnames[0] }}')
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]
ldap.ldap_server = '{{ general.ldap.server.ldap_server_address }}'
ldap.ldap_server_port = '636'
ldap.ldap_binddn = '{{ general.ldap.client.ldapclient_user }}'
ldap.ldap_password = '{{ general.ldap.client.ldapclient_user_password }}'
ldap.ldap_filter = 'cn=%s'
ldap.ldap_base = '{{ general.ldap.client.ldapclient_user_dn }}'
else:
ldap = env['res.company.ldap'].create({'company': env.company.id,
'ldap_server': '{{ general.ldap.server.ldap_server_address }}',
'ldap_server_port': '636',
'ldap_binddn': '{{ general.ldap.client.ldapclient_user }}',
'ldap_password': '{{ general.ldap.client.ldapclient_user_password }}',
'ldap_filter': 'cn=%s',
'ldap_base': '{{ general.ldap.client.ldapclient_user_dn }}',
})
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',
'smtp_host': '{{ general.smtp.smtp_relay_address }}',
'smtp_port': '25',
'smtp_authentication': 'login',
'smtp_user': '{{ general.smtp.smtp_relay_user }}@{{ general.smtp.smtp_client_ip }}',
'smtp_pass': '{{ general.smtp.smtp_relay_password }}',
'smtp_encryption': 'starttls',
})
else:
mail.smtp_host = '{{ general.smtp.smtp_relay_address }}'
mail.smtp_port = '25'
mail.smtp_authentication = 'login'
mail.smtp_user = '{{ general.smtp.smtp_relay_user }}@{{ general.smtp.smtp_client_ip }}'
mail.smtp_pass = '{{ general.smtp.smtp_relay_password }}'
mail.smtp_encryption = 'starttls'
env['ir.config_parameter'].set_param('base_setup.default_external_email_server', True)