~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to mrp_bom_constraint/mrp_bom.py

[MERGE] from local .bzrignore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
###########################################################################
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#    Copyright (C) Vauxoo (<http://vauxoo.com>).
 
6
#    All Rights Reserved
 
7
# Credits######################################################
 
8
#    Coded by: Juan Carlos Funes(juan@vauxoo.com)
 
9
#############################################################################
 
10
#    This program is free software: you can redistribute it and/or modify
 
11
#    it under the terms of the GNU Affero General Public License as published by
 
12
#    the Free Software Foundation, either version 3 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    This program is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU Affero General Public License for more details.
 
19
#
 
20
#    You should have received a copy of the GNU Affero General Public License
 
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
##########################################################################
 
23
import time
 
24
from openerp.tools.translate import _
 
25
 
 
26
from openerp.osv import osv, fields
 
27
 
 
28
 
 
29
class mrp_bom(osv.Model):
 
30
    _inherit = 'mrp.bom'
 
31
 
 
32
    def check_uom(self, cr, uid, ids, context=None):
 
33
        for mrp_bom in self.browse(cr, uid, ids, context=context):
 
34
            if mrp_bom.product_uom and\
 
35
                mrp_bom.product_id.uom_id.category_id.id !=\
 
36
                    mrp_bom.product_uom.category_id.id:
 
37
                return False
 
38
        return True
 
39
 
 
40
    _constraints = [(check_uom, _(
 
41
        'No puedes agregar un UdM que pertenezca a otra categoría que la que\
 
42
        tiene la unidad de medida default del producto'), ["product_uom"])]