From a0d44f99528a06008749e725ee514fe31e2e2e21 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Thu, 30 Jul 2015 17:34:42 +0200 Subject: [PATCH] [IMP] update the expiry dates when changing the product Written in the new API even though the rest is in the old API, because otherwise we'd have to add an onchange in the views which may be a problem for existing custom modules. We want this behavior because previously, in some cases the default values were only added at create() time, ie. possibily when the users close the pop-up, so they may never have an opportunity to see and adjust the default. --- addons/product_expiry/product_expiry.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addons/product_expiry/product_expiry.py b/addons/product_expiry/product_expiry.py index 392e574a0bb..4b52d9bf3b6 100644 --- a/addons/product_expiry/product_expiry.py +++ b/addons/product_expiry/product_expiry.py @@ -21,6 +21,7 @@ import datetime import openerp +from openerp import api, models from openerp.osv import fields, osv class stock_production_lot(osv.osv): @@ -75,6 +76,19 @@ class stock_production_lot(osv.osv): } +# Onchange added in new api to avoid having to change views +class StockProductionLot(models.Model): + _inherit = 'stock.production.lot' + + @api.onchange('product_id') + def _onchange_product(self): + defaults = self.with_context( + product_id=self.product_id.id).default_get( + ['life_date', 'use_date', 'removal_date', 'alert_date']) + for field, value in defaults.items(): + setattr(self, field, value) + + class stock_quant(osv.osv): _inherit = 'stock.quant'