~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to psm/model/stock.py

[MERGE] from local .bzrignore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
############################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution             #
 
4
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).            #
 
5
#    All Rights Reserved                                                   #
 
6
# Credits######################################################
 
7
#    Coded by: Miguel Delgado <miguel@openerp.com.ve>                      #
 
8
#    Planified by: Nhomar Hernandez                                        #
 
9
#    Finance by: Corporacion AMD                                           #
 
10
#    Audited by: Humberto Arocha humberto@openerp.com.ve                   #
 
11
############################################################################
 
12
#    This program is free software: you can redistribute it and/or modify  #
 
13
#    it under the terms of the GNU General Public License as published by  #
 
14
#    the Free Software Foundation, either version 3 of the License, or     #
 
15
#    (at your option) any later version.                                   #
 
16
#                                                                          #
 
17
#    This program is distributed in the hope that it will be useful,       #
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
 
20
#    GNU General Public License for more details.                          #
 
21
#                                                                          #
 
22
#    You should have received a copy of the GNU General Public License     #
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
 
24
############################################################################
 
25
from openerp.osv import osv, fields
 
26
from openerp.tools.translate import _
 
27
 
 
28
import decimal_precision as dp
 
29
 
 
30
 
 
31
class stock_production_lot(osv.Model):
 
32
 
 
33
    def _serial_identification(self, cr, uid, ids, context=None):
 
34
        if context is None:
 
35
            context = {}
 
36
        spl_brw = self.browse(cr, uid, ids, context=context)
 
37
 
 
38
        for spl in spl_brw:
 
39
            if spl.check_serial and spl.stock_available != 0:
 
40
                return False
 
41
        return True
 
42
 
 
43
    _inherit = 'stock.production.lot'
 
44
 
 
45
    _columns = {
 
46
        'check_serial': fields.boolean('Check Serial'),
 
47
        'ref': fields.char('Internal Reference', size=256,
 
48
                           help="""Internal reference number in case it
 
49
                                   differs from the manufacturer's
 
50
                                   serial number""")
 
51
    }
 
52
 
 
53
    _constraints = [
 
54
        (_serial_identification, _('Check this picking problem with serial'),
 
55
         ['Check Serial (check_serial)', 'Stock Available (stock_available)']),
 
56
    ]
 
57
 
 
58
    def name_get(self, cr, uid, ids, context=None):
 
59
        if context is None:
 
60
            context = {}
 
61
        ret = []
 
62
        res = super(stock_production_lot, self).name_get(
 
63
            cr, uid, ids, context=context)
 
64
        for i in res:
 
65
            ret.append((i[0], i[1].split(' ')[0]))
 
66
        return ret
 
67
 
 
68
 
 
69
class stock_picking(osv.Model):
 
70
    _inherit = "stock.picking"
 
71
 
 
72
    def test_serial(self, cr, uid, ids):
 
73
        ok = True
 
74
        spl_obj = self.pool.get('stock.production.lot')
 
75
        for pick in self.browse(cr, uid, ids):
 
76
            for move in pick.move_lines:
 
77
                if move.product_id.track_serial_incoming and not \
 
78
                        move.prodlot_id and pick.type == 'in':
 
79
                    raise osv.except_osv(_('Error !'), _(
 
80
                        'This product %s should be serialized') %
 
81
                        move.product_id.name)
 
82
                if move.product_id.track_serial_outgoing and not \
 
83
                        move.prodlot_id and pick.type == 'out':
 
84
                    raise osv.except_osv(_('Error !'), _(
 
85
                        'This product %s should be serialized') %
 
86
                        move.product_id.name)
 
87
 
 
88
                if move.product_id.track_serial_incoming and \
 
89
                    move.product_id.track_serial_outgoing and\
 
90
                        pick.type == 'out':
 
91
                    spl_ids = spl_obj.search(cr, uid, [(
 
92
                        'product_id', '=', move.product_id.id),
 
93
                        ('name', '=', move.prodlot_id.name)])
 
94
                    if len(spl_ids) < 1:
 
95
                        raise osv.except_osv(_('Error !'), _(
 
96
                            'This serial %s is not exist') %
 
97
                            move.prodlot_id.name)
 
98
        return ok