Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Odoo 11 - Using custom settings (module defaults)

Subscribe

Get notified when there's activity on this post

This question has been flagged
configurationsettingsdefaultsodoo11
5 Replies
18886 Views
Avatar
Alf Olsen

I managed to set up my custom module settings as described by the first answer here

https://www.odoo.com/forum/help-1/question/create-a-custom-configuration-page-for-custom-module-51842

class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
    ...

I read that in this model one are supposed to be able to use these custom settings as default values in other models, but how? I read all the source code on other models from the core, but cant seem to find the answer.

This article (old) states that this is possible

http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html

“Default” settings
The value of a field named default_foo will be set as a default value for a field named foo on a model given as a default_model argument.

..but I can't make it work, so in the mean time I havea default method to set the value from the settings

@api.model
def _get_default_foobar(self):
res = self.env['res.config.settings'].get_values()
return res['foobar'] or 1

which works, but seems like the wrong solution.

Any ideas? Code example would be great.

UPDATE    

default_foo = fields.Integer(default_model='some_model')

I try to set the default value in the model "some_model", but that model's property "foo" does not get the default value.

0
Avatar
Discard
Alf Olsen
Author

@Zbik: Thanks for trying, but none of your answers really answers what I'm really asking. I'm looking for a way to set default values in other models from the ResConfigSettings

Zbik

All solutions are related + default_foo. My answer updated.

Alf Olsen
Author

Thanks again. Let me just say I _really_ looked into the source code, so I'm familiar with the code you pasted from the source. I added an update to my question, because I tried what you said. In my case I'm trying to set the default value (an integer)

Alf Olsen
Author

@Hiren Dangar: Thanks, but that will only set the value "foobar" in the ir.config_paramanter model. I already did that. Still doesnt "transfer" the foobar value as default to another model.

Zbik

In my system default_foo type Integer works without any problems. You must STORE config after set value, onchanage on default_foo is not implemented in this case. Sugestiona: a) you change name "foo" to "xyz" and repeat test. b) You verify, in global settings, values in ir.default (may be here are duplicates)

Alf Olsen
Author

Thanks again guys, so I got it working in the end when storing the default_foo in the table ir.config_parameter as well as the "foo" value. It didn't make sense to me to store this value more than once, I thought the code could handle it. I mean, lets say I have a value ResConfigSetting that I want to be default in two other models. Then I must basically store 3 values in ir.config_parameter. Anyway, it works so I'm not going to complain :)

Alf Olsen
Author

urk, so I notice now that I need to save twice in the settings for new defalut value to take affect. After saving once, I see the updated value in ir.config_parameter table, but the default value is still the previous value. Saving one more time will set the default value properly. This is extremely weird

Avatar
HIREN DANGAR
Best Answer

Try this below code.
In odoo version 8, 9 and 10 set default fields as are describe below.

@api.multi

    def set_default_penalty_base(self):

        self.env['ir.values'].set_default('account.config.settings', 'foobar', self.foobar)


In odoo 11 use below code to set default fields.

@api.multi

    def set_values(self):

        super(ResConfigSettingsExd, self).set_values()

        ICPSudo = self.env['ir.config_parameter'].sudo()

        ICPSudo.set_param('jt_penalty_on_due_invoices.foobar', self.foobar)


1
Avatar
Discard
Avatar
Zbik
Best Answer

1  solution - the use field related, example:

    currency_id = fields.Many2one('res.currency', related="company_id.currency_id", required=True,
        string='Currency', help="Main currency of the company.")

2 solution - the use @api.onchange to compute related field
3 solution - inherit method set_values() in class ResConfigSettings
4 solution - on click create wizard and set own values, or use button to call custom method in ResConfigSettings

For example, see addons/account/models/res_config_settings.py  
or the same file in other addons (if exist).

UPDATED ANSWER:

Examples from addons/sale_stock/models/res_config_settings.py (see default_picking_policy):

class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

security_lead = fields.Float(related='company_id.security_lead', string="Security Lead Time")
group_route_so_lines = fields.Boolean("Order-Specific Routes",
implied_group='sale_stock.group_route_so_lines')
module_sale_order_dates = fields.Boolean("Delivery Date")
group_display_incoterm = fields.Boolean("Incoterms", implied_group='sale_stock.group_display_incoterm')
use_security_lead = fields.Boolean(
string="Security Lead Time for Sales",
oldname='default_new_security_lead',
help="Margin of error for dates promised to customers. Products will be scheduled for delivery that many days earlier than the actual promised date, to cope with unexpected delays in the supply chain.")
default_picking_policy = fields.Selection([
('direct', 'Ship products as soon as available, with back orders'),
('one', 'Ship all products at once')
], "Shipping Management", default='direct', default_model="sale.order", required=True)

@api.onchange('use_security_lead')
def _onchange_use_security_lead(self):
if not self.use_security_lead:
self.security_lead = 0.0

def get_values(self):
res = super(ResConfigSettings, self).get_values()
res.update(
use_security_lead=self.env['ir.config_parameter'].sudo().get_param('sale_stock.use_security_lead')
)
return res

def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param('sale_stock.use_security_lead', self.use_security_lead)




1
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to configure module settings with erppeek on Odoo 11?
configuration settings erppeek odoo11
Avatar
1
Mar 20
9582
disable delete and edit options in conversations Odoo 15
configuration settings
Avatar
Avatar
Avatar
2
Apr 24
6342
What are the things to watch out for before my OpenERP goes live? Version 7.
configuration settings
Avatar
0
Mar 15
8827
Reserve Profit and Loss Account
configuration settings
Avatar
Avatar
1
Mar 15
8594
How to store Boolean value in res.config.settings? Solved
configuration settings v14
Avatar
Avatar
Avatar
2
Mar 24
12039
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now