Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
7551 Переглядів

Prior to configuring a production database, I am performing several manual configuration steps in development and staging branches.

It seems like I have to repeat all of these manual steps .

It is possible to export settings between databases?

Is it possible to programmatically configure a database?


Аватар
Відмінити
Найкраща відповідь

Yes, you can script the configuration of a database and reuse the script.


Note: You need to (a) understand this is an advanced technique and (b) be familiar / fluent in using Python to set values for different types of data structures. Configuration options can be represented in different ways - check boxes, radio buttons, fields to enter text, fields to enter numbers, fields to select dates, fields to select related records, etc. - which translate to model fields of different types: boolean, selection, char, integer, date, many2one, etc. - and each needs a different method to set and/or change the value.


We do this in our test scripts, so you can also do it in your own scripts.  (Please test and verify what you think is happening is actually happening!).


In the code at https://github.com/odoo/odoo/blob/17.0/addons/base_setup/tests/test_res_config.py#L40 you can see these lines configure a database to support multiple currencies (res.config.settings is a transient model):

# get access to the configuration model
ResConfig = self.env['res.config.settings']

# get a copy of the default values
default_values = ResConfig.default_get(list(ResConfig.fields_get()))

# update the default values
default_values.update({'group_multi_currency': True})

# persist the updated defaults
ResConfig.create(default_values).execute()


Example:

Let's say we want to change the default currency of a database to $USD and also configure the database to support multi-currency, and the current configuration looks like this:



First, hover over each of the fields to see their technical name, since these are the fields you will need to update:

                   


Next, you can script.  This example uses a Scheduled Action configured as inactive so the only time it runs is when the RUN MANUALLY button is clicked.  You may prefer to write an XML-RPC based script. 




default_values = model.default_get(list(model.fields_get()))

default_values.update({
'currency_id': env.ref('base.USD').id,
'group_multi_currency': True
})

model.create(default_values).execute()


After the script is run:



You can also install modules:

for app in ['stock','account_consolidation','contacts','helpdesk','sale_purchase','sale_management','crm','web_studio']:
    env['ir.module.module'].search([('name','=',app)],limit=1).button_immediate_install()


Populate company data:

coname = 'ACME'
 
# ↓↓↓ add details to the main Company, "ACME USA Inc."
us_company = env.ref('base.main_company')
us_company.update({'name': coname + ' USA Inc.', 'street': '100 Main Street', 'city': 'Springfield', 'state_id': env.ref('base.state_us_5').id, 'zip': '90123'})


Activate currencies:

# ↓↓↓ Activate Currencies and rename prefixes
env.ref('base.AUD').update({'active': True,'symbol': '$AUD'})
env.ref('base.EUR')['active'] = True
env.ref('base.GBP')['active'] = True
env.ref('base.JPY')['active'] = True


Create fake historic data:

# ↓↓↓ Create CRM Teams
env.ref('sales_team.team_sales_department').update({'name': 'Farmers', 'company_id': 1})
farmers = env.ref('sales_team.team_sales_department').id
hunters = env['crm.team'].create({'name': 'Hunters'}).id

# ↓↓↓ Sort Sales Teams alphabetically
sorted_teams = env['crm.team'].search([]).sorted(key=lambda r: r.name)
for i in range(len(sorted_teams)):
  sorted_teams[i].update({'sequence': i})

# ↓↓↓  mediums for historic data
web = env.ref('utm.utm_medium_website').id
phone = env.ref('utm.utm_medium_phone').id

# ↓↓↓  historic data
for i in range(1,142):
  env.cr.execute("insert into crm_lead (create_date,active,name,medium_id,team_id,type) values ('%s','f','l',%d,%d,'lead')" % \
(datetime.datetime.today() - datetime.timedelta(weeks=52),phone,farmers))


If you are writing a module for this, you can also use the function tag to call model methods in your XML files.  See https://www.odoo.com/documentation/master/developer/reference/backend/data.html#function

Аватар
Відмінити

install module xml install app xml configure app xml configure module xml

Найкраща відповідь

You can use this module https://apps.odoo.com/apps/modules/16.0/export_import_settings

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
бер. 24
2011
0
лист. 23
1320
0
трав. 21
2697
6
лип. 24
82030
3
серп. 24
5736