[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
This commit is contained in:
Thibault Delavallée
2017-06-19 17:37:38 +02:00
committed by Yannick Tivisse
parent 71e5c8b0b5
commit 7efa2b63a6
2 changed files with 21 additions and 5 deletions
@@ -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)
@@ -37,16 +37,16 @@
<div id="sale_security_lead" position="replace">
<div class="col-xs-12 col-md-6 o_setting_box" title="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.">
<div class="o_setting_left_pane">
<field name="default_new_security_lead"/>
<field name="use_security_lead"/>
</div>
<div class="o_setting_right_pane">
<label for="default_new_security_lead"/>
<label for="use_security_lead"/>
<span class="fa fa-lg fa-building-o" title="Values set here are company-specific." groups="base.group_multi_company"/>
<div class="text-muted">
Schedule deliveries earlier to avoid delays
</div>
<div class="content-group">
<div class="mt16" attrs="{'invisible': [('default_new_security_lead','=',False)]}">
<div class="mt16" attrs="{'invisible': [('use_security_lead','=',False)]}">
<span>Move forward expected delivery dates by <field name="security_lead" class="oe_inline"/> days</span>
</div>
</div>