1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2011 Pexego (<www.pexego.es>). All Rights Reserved
6
# $Omar Castiñeira Saavedra$
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
22
"""inherits fromk stock_move for checks expired prodlots"""
25
from tools.translate import _
27
class stock_move(osv.osv):
28
"""inherits fromk stock_move for checks expired prodlots"""
29
_inherit = "stock.move"
31
def _check_prodlot_expiration(self, cr, uid, ids):
32
"""checks if prodlot is expired and is trying move it to internal or customer location"""
33
for move in self.browse(cr, uid, ids):
34
if move.prodlot_id and move.location_dest_id:
35
if move.prodlot_id.expired and move.location_dest_id.usage in ['internal', 'customer']:
40
(_check_prodlot_expiration, _('Cannot move an expired production lot to internal or customer location'), ['expired']),
43
def eval_onchange_lot_date(self, cr, uid, res, prodlot_id = False):
44
"""overwrites this event for shows a warning if the production lot selected is expired"""
45
prodlot = prodlot_id or ((res.get('value') and res['value'].get('prodlot_id')) and res['value']['prodlot_id'] or False)
46
if res.get('warning', False):
49
obj_prodlot_id = self.pool.get('stock.production.lot').browse(cr, uid, prodlot)
50
if obj_prodlot_id.expired:
52
'title': _('Production Lot Expired!'),
53
'message': _('This production lot is expired'),
55
return {'warning': res['warning'], 'value': res.get('value') and res['value'].update({'prodlot_id': None}) or {'prodlot_id': None}}
58
def onchange_lot_id(self, cr, uid, ids, prodlot_id=False, product_qty=False, loc_id=False, product_id=False, uom_id=False, context=None):
59
"""overwrites this event for shows a warning if the production lot selected is on alert"""
60
if context is None: context = {}
61
if not prodlot_id or not loc_id:
64
res = super(stock_move, self).onchange_lot_id(cr, uid, ids, prodlot_id = prodlot_id, product_qty = product_qty, loc_id = loc_id, product_id=product_id, uom_id=uom_id, context = context)
65
return self.eval_onchange_lot_date(cr, uid, res, prodlot_id)
67
def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False, loc_dest_id=False, address_id=False, prod_qty=0.0, prodlot_id=False):
68
"""Extends this event checking prodlot obtained"""
69
res = super(stock_move, self).onchange_product_id(cr, uid, ids, prod_id, loc_id, loc_dest_id, address_id)
71
return self.eval_onchange_lot_date(cr, uid, res)
73
def onchange_location_id(self, cr, uid, ids, product_id = False, location_id = False, dummy = False, product_qty=False, product_uom_id=False):
74
"""event fires when changes the location, checks the location and return a default production lot for this location"""
75
res = super(stock_move, self).onchange_location_id(cr, uid, ids,product_id,location_id,dummy,product_qty,product_uom_id)
77
return self.eval_onchange_lot_date(cr, uid, res)