Odoo Help

0

0
5 Answers
1
Avatar

HIREN DANGAR India

--HIREN DANGAR--
1200
| 5 2 5
Gandhinagar, India
--HIREN DANGAR--

Odoo (OpenERP) backed developer. A very strong grip on a Qweb & Xlsx reports and customise any base module and develop new module.

HIREN DANGAR India
8/23/18, 5:48 AM

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

Zbik Poland

--Zbik--
13382
| 7 6 9
Łódź, Poland
--Zbik--


Zbik Poland
8/22/18, 12:43 PM

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)




Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now