[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.
This commit is contained in:
Lionel Sausin 2015-07-30 17:34:42 +02:00 committed by Josse Colpaert
parent 3c0fe940aa
commit a0d44f9952
1 changed files with 14 additions and 0 deletions

View File

@ -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'