~tecvemar/openerp-tecvemar/trunk

« back to all changes in this revision

Viewing changes to openerp-modules/tcv_extra_uom/extra_UOM.py

  • Committer: Miguel Delgado
  • Date: 2012-01-16 16:01:47 UTC
  • Revision ID: miguel.delgado07@gmail.com-20120116160147-xh7svuwouf56xjjj

[ADD] Se añadieron todos los modulos desarrollados por Tecvemar para arrancar dicha compañia con la version  
6.0 de OpenErp.
[ADD] Se creo una estructura de 2 carpetas donde openerp-modules contendra los modulos que añaden 
funcionalidad a OpenErp segun el modelo de negocios de la compañia y init-data contendra modulos necesarios 
para cargar la data de la compañia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#    
 
4
#    OpenERP, Open Source Management Solution
 
5
#
 
6
#    This program is free software: you can redistribute it and/or modify
 
7
#    it under the terms of the GNU Affero General Public License as
 
8
#    published by the Free Software Foundation, either version 3 of the
 
9
#    License, or (at your option) any later version.
 
10
#
 
11
#    This program is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU Affero General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU Affero General Public License
 
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 
18
#
 
19
##############################################################################
 
20
 
 
21
#import datetime
 
22
from osv import fields,osv
 
23
import pooler
 
24
import decimal_precision as dp
 
25
 
 
26
 
 
27
#this code must be in  stock.py
 
28
class stock_production_lot(osv.osv):
 
29
 
 
30
    _inherit = 'stock.production.lot'
 
31
   
 
32
    
 
33
    def _calc_lot_area(self, l, h, w):
 
34
        obj_uom = self.pool.get('product.uom')
 
35
        r = obj_uom._calc_area(l,h)
 
36
        if w:
 
37
           r = obj_uom._calc_area(r,w)           
 
38
        return r
 
39
    
 
40
 
 
41
    def _calc_lot_factor(self, cr, uid, ids, name, arg, context=None):
 
42
        if context is None:
 
43
            context = {}
 
44
        if not len(ids):
 
45
            return []            
 
46
        res = {}
 
47
        for id in ids:
 
48
            # creates a UOM model to calculate lot factor
 
49
            r = self.read(cr, uid, id, ['length', 'heigth', 'width'], context)    
 
50
            res[id] = self._calc_lot_area(r['length'], r['heigth'], r['width'])
 
51
#            obj_uom = self.pool.get('product.uom')
 
52
#            r = self.read(cr, uid, id, ['length','heigth','width'], context)    
 
53
#            res[id] = obj_uom._calc_area(r['length'],r['heigth'])
 
54
#            if r['width']:
 
55
#                res[id] = obj_uom._calc_area(res[id],r['width'])           
 
56
        return res
 
57
        
 
58
        
 
59
    def on_change_size(self, cr, uid, ids, length, heigth, width):
 
60
        res = {'value':{'lot_factor':self._calc_lot_area(length, heigth, width)}}
 
61
        return res
 
62
        
 
63
        
 
64
    _columns = {
 
65
        'length': fields.float('Length (m)', digits_compute=dp.get_precision('Extra UOM data')),
 
66
        'width': fields.float('Width (m)', digits_compute=dp.get_precision('Extra UOM data')),
 
67
        'heigth': fields.float('Heigth (m)', digits_compute=dp.get_precision('Extra UOM data')),
 
68
#        'lot_location': fields.char('Location', size=10, translate=True), # don't use this field use wharehouse
 
69
        'lot_factor': fields.function(_calc_lot_factor, method=True, type="float", string='Lot Factor', digits_compute=dp.get_precision('Product UoM')),
 
70
    }
 
71
    
 
72
    
 
73
    _defaults = {
 
74
        'length':0.0,
 
75
        'width' :0.0,
 
76
        'heigth':0.0,
 
77
    }
 
78
        
 
79
        
 
80
    _sql_constraints = [
 
81
        ('length_gt_zero', 'CHECK (length>=0)', 'The length must be >= 0!'),
 
82
        ('width_gt_zero', 'CHECK (width>=0)', 'The width must be >= 0!'),
 
83
        ('heigth_gt_zero', 'CHECK (heigth>=0)', 'The heigth must be >= 0!'),
 
84
    ]
 
85
 
 
86
 
 
87
    def name_get(self,cr, uid, ids, context):
 
88
        if not len(ids):
 
89
            return []
 
90
#        reads = self.read(cr, uid, ids, ['id','name', 'prefix', 'ref','length','heigth','width','lot_factor','move_ids'], context)
 
91
        reads = self.read(cr, uid, ids, [], context)
 
92
#        l = self.pool.get('stock.production.lot').browse(cr,uid,ids)
 
93
        res = []
 
94
        for r in reads:
 
95
            #TODO optimize with only one read for all ids, or maybe use "self" data
 
96
            l = self.pool.get('stock.production.lot').browse(cr,uid,r['id'])
 
97
            drv = l.product_id.stock_driver
 
98
            if drv == 'tile':
 
99
                name = '%s (%sx%s)' % (r['name'].strip(),r['length'],r['heigth'])
 
100
            elif drv == 'slab':
 
101
                name = '%s (%sx%s)' % (r['name'].strip(),r['length'],r['heigth'])
 
102
            elif drv == 'block':
 
103
                name = '%s (%sx%sx%s)' % (r['name'].strip(),r['length'],r['heigth'],r['width'])
 
104
            else: # call inherited name_get()
 
105
                this_id = [r['id']]
 
106
                super_name = super(stock_production_lot,self).name_get(cr, uid, this_id, context)
 
107
                name = super_name[0][-1]
 
108
            res.append((r['id'], name))
 
109
        return res
 
110
stock_production_lot()
 
111
 
 
112
# IMPORTANTE:
 
113
# En sale_order se debe incorporar una validacion que impida vender un lote parcial si el stock_driver es slab o block
 
114
 
 
115
#class sale_order(osv.osv):
 
116
#    _inherit = 'sale.order.line'
 
117
#    _columns = {
 
118
#        'prodlot_id' : fields.many2one('stock.production.lot', 'Production lot', help="Production lot is used to put a serial number on the production"),
 
119
#    }
 
120
#sale_order()
 
121
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
122