~pexego/openobject-addons/6.1-pexego-sale_commission

« back to all changes in this revision

Viewing changes to product_expiry_notification/stock_move.py

  • Committer: Omar (pexego)
  • Date: 2012-07-27 08:40:22 UTC
  • Revision ID: omar@pexego.es-20120727084022-qp3ludpr3vsuyuf6
[ADD] Traceability modules ported to 6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2011 Pexego (<www.pexego.es>). All Rights Reserved
 
6
#    $Omar Castiñeira Saavedra$
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
##############################################################################
 
22
"""inherits fromk stock_move for checks expired prodlots"""
 
23
 
 
24
from osv import osv
 
25
from tools.translate import _
 
26
 
 
27
class stock_move(osv.osv):
 
28
    """inherits fromk stock_move for checks expired prodlots"""
 
29
    _inherit = "stock.move"
 
30
 
 
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']:
 
36
                    return False
 
37
        return True
 
38
 
 
39
    _constraints = [
 
40
    (_check_prodlot_expiration, _('Cannot move an expired production lot to internal or customer location'), ['expired']),
 
41
    ]
 
42
 
 
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):
 
47
            return res
 
48
        elif prodlot:
 
49
            obj_prodlot_id = self.pool.get('stock.production.lot').browse(cr, uid, prodlot)
 
50
            if obj_prodlot_id.expired:
 
51
                res['warning'] = {
 
52
                    'title': _('Production Lot Expired!'),
 
53
                    'message': _('This production lot is expired'),
 
54
                        }
 
55
                return {'warning': res['warning'], 'value': res.get('value') and res['value'].update({'prodlot_id': None}) or {'prodlot_id': None}}
 
56
        return res
 
57
 
 
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:
 
62
            return {}
 
63
 
 
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)
 
66
 
 
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)
 
70
 
 
71
        return self.eval_onchange_lot_date(cr, uid, res)
 
72
 
 
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)
 
76
 
 
77
        return self.eval_onchange_lot_date(cr, uid, res)
 
78
 
 
79
stock_move()