From 7efa2b63a63a8a3b44c47055696b1de8419c99ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 5 Apr 2017 14:59:06 +0200 Subject: [PATCH] [REF] sale_stock: use config parameter instead of ir values in settings Fields like `default_foo` still used ir.values although those are system-wide parameters and should therefore be stored in ir.config_parameter table. When no default_model is set on a field, don't prefix it by `default_`. Also, reset security_lead when use_security_lead is unchecked to avoid it to be used in further computations --- .../models/stock_config_settings.py | 20 +++++++++++++++++-- .../views/stock_config_settings_views.xml | 6 +++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/sale_stock/models/stock_config_settings.py b/addons/sale_stock/models/stock_config_settings.py index d4590166076..9695caf0636 100644 --- a/addons/sale_stock/models/stock_config_settings.py +++ b/addons/sale_stock/models/stock_config_settings.py @@ -1,15 +1,31 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import api, fields, models class StockConfigSettings(models.TransientModel): _inherit = 'stock.config.settings' security_lead = fields.Float(related='company_id.security_lead') - default_new_security_lead = fields.Boolean(string="Security Lead Time for Sales", default_model="stock.config.settings", help="Margin of error for dates promised to customers. Products will be scheduled for procurement and delivery that many days earlier than the actual promised date, to cope with unexpected delays in the supply chain.") + 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 procurement and 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_default_fields(self, fields): + return dict( + use_security_lead=self.env['ir.config_parameter'].sudo().get_param('sale_stock.use_security_lead') + ) + + def set_fields(self): + self.env['ir.config_parameter'].sudo().set_param('sale_stock.use_security_lead', self.use_security_lead) diff --git a/addons/sale_stock/views/stock_config_settings_views.xml b/addons/sale_stock/views/stock_config_settings_views.xml index bc019ab07a4..96d8c9ef1da 100644 --- a/addons/sale_stock/views/stock_config_settings_views.xml +++ b/addons/sale_stock/views/stock_config_settings_views.xml @@ -37,16 +37,16 @@
- +
-