[REF] purchase: 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 po_lead when use_po_lead is unchecked to avoid it to be used it further computations.
This commit is contained in:
Thibault Delavallée
2017-06-19 17:37:38 +02:00
committed by Yannick Tivisse
parent b9c45fbabc
commit 682a648be0
2 changed files with 20 additions and 4 deletions
@@ -8,4 +8,20 @@ class StockConfigSettings(models.TransientModel):
_inherit = 'stock.config.settings'
po_lead = fields.Float(related='company_id.po_lead', default=lambda self: self.env.user.company_id.po_lead)
default_new_po_lead = fields.Boolean(string="Security Lead Time for Purchase", default_model="stock.config.settings", help="Margin of error for vendor lead times. When the system generates Purchase Orders for reordering products,they will be scheduled that many days earlier to cope with unexpected vendor delays.")
use_po_lead = fields.Boolean(
string="Security Lead Time for Purchase",
oldname='default_new_po_lead',
help="Margin of error for vendor lead times. When the system generates Purchase Orders for reordering products,they will be scheduled that many days earlier to cope with unexpected vendor delays.")
@api.onchange('use_po_lead')
def _onchange_use_po_lead(self):
if not self.use_po_lead:
self.po_lead = 0.0
def get_default_fields(self, fields):
return dict(
use_po_lead=self.env['ir.config_parameter'].sudo().get_param('purchase.use_po_lead')
)
def set_fields(self):
self.env['ir.config_parameter'].sudo().set_param('purchase.use_po_lead', self.use_po_lead)
@@ -9,16 +9,16 @@
<div id="purchase_po_lead" position="replace">
<div class="col-xs-12 col-md-6 o_setting_box" title="Margin of error for vendor lead times. When the system generates Purchase Orders for reordering products,they will be scheduled that many days earlier to cope with unexpected vendor delays.">
<div class="o_setting_left_pane">
<field name="default_new_po_lead"/>
<field name="use_po_lead"/>
</div>
<div class="o_setting_right_pane">
<label for="default_new_po_lead"/>
<label for="use_po_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 receivings earlier to avoid delays
</div>
<div class="content-group">
<div class="mt16" attrs="{'invisible': [('default_new_po_lead','=',False)]}">
<div class="mt16" attrs="{'invisible': [('use_po_lead','=',False)]}">
<span>Move forward expected delivery dates by <field name="po_lead" class="oe_inline"/> days</span>
</div>
</div>