~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to mrp_advance/mrp_bom_cost/mrp.py

  • Committer: Nhomar Hernandez
  • Date: 2013-04-19 20:33:12 UTC
  • mfrom: (542.1.314 addons-vauxoo)
  • Revision ID: nhomar@gmail.com-20130419203312-o35v7dn79l6vur0t
[MERGE - PEP8 AND V7-MIG] All migrated to V7 Just
improved osv.osv => osv.Model, osv.osv_memory => osv.TransientModel
import inside openerp.* enviroment
Erased class instansiation no necesarry anymore in V7
AUTOPEP8 run, Left PEP8 long lines manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#    Module Writen to OpenERP, Open Source Management Solution
4
4
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
5
5
#    All Rights Reserved
6
 
###############Credits######################################################
 
6
# Credits######################################################
7
7
#    Coded by: nhomar@openerp.com.ve,
8
8
#    Coded by: rodo@vauxoo.com,
9
9
#    Planified by: Nhomar Hernandez
23
23
#    You should have received a copy of the GNU General Public License
24
24
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
25
##############################################################################
26
 
from osv import osv
27
 
from osv import fields
28
 
from tools.translate import _
 
26
from openerp.osv import fields, osv
 
27
from openerp.tools.translate import _
 
28
 
29
29
import decimal_precision as dp
30
30
 
31
 
class mrp_bom(osv.osv):
 
31
 
 
32
class mrp_bom(osv.Model):
32
33
    _inherit = 'mrp.bom'
33
34
 
34
35
    def _calc_cost(self, cr, uid, ids, field_name, arg, context):
35
 
        res={}
36
 
        for i in self.browse(cr,uid,ids):
 
36
        res = {}
 
37
        for i in self.browse(cr, uid, ids):
37
38
            res[i.id] = self.compute_bom_cost(cr, uid, [i.id])
38
39
        return res
39
40
 
43
44
        @cost = se almacena el costo unitario final.
44
45
        @res = diccionario usado para retornar el id y el costo unitario.
45
46
        '''
46
 
        res={}
47
 
        for i in self.browse(cr,uid,ids):
 
47
        res = {}
 
48
        for i in self.browse(cr, uid, ids):
48
49
            cost = 0.00
49
50
            cost = i.cost_t/i.product_qty
50
51
            for l in i.bom_lines:
51
52
                if not l.bom_lines:
52
 
                    cost =  l.product_id.standard_price*l.product_qty
53
 
                    res[i.id]= cost
 
53
                    cost = l.product_id.standard_price*l.product_qty
 
54
                    res[i.id] = cost
54
55
                else:
55
 
                    cost = cost + self._calc_cost_u(cr,uid,[l.id],field_name,arg,context)[l.id]*l.product_qty
56
 
                    res[i.id]=cost/l.product_qty
 
56
                    cost = cost + self._calc_cost_u(cr, uid, [
 
57
                                                    l.id], field_name, arg, context)[l.id]*l.product_qty
 
58
                    res[i.id] = cost/l.product_qty
57
59
            res[i.id] = i.cost_t/i.product_qty
58
 
            if i._columns.has_key('sub_products') and i.sub_products:
59
 
                sum_amount_subproducts=0.0
 
60
            if 'sub_products' in i._columns and i.sub_products:
 
61
                sum_amount_subproducts = 0.0
60
62
                product_uom_obj = self.pool.get('product.uom')
61
63
                for sub_prod in i.sub_products:
62
 
                    sum_amount_subproducts += (product_uom_obj._compute_price(cr, uid,sub_prod.product_id.uom_id.id , sub_prod.product_id.standard_price, sub_prod.product_uom.id) * sub_prod.product_qty) 
63
 
                res[i.id] =  (i.cost_t - sum_amount_subproducts)/ i.product_qty #mrp.bom valida cantidades mayores a 0
 
64
                    sum_amount_subproducts += (product_uom_obj._compute_price(
 
65
                        cr, uid, sub_prod.product_id.uom_id.id, sub_prod.product_id.standard_price, sub_prod.product_uom.id) * sub_prod.product_qty)
 
66
                res[i.id] =  (i.cost_t - sum_amount_subproducts) / \
 
67
                    i.product_qty  # mrp.bom valida cantidades mayores a 0
64
68
        return res
65
69
 
66
70
    def _get_category(self, cr, uid, ids, field_name, arg, context):
68
72
        funcion para obtener la categoria del producto y luego aplicarla para la filtracion
69
73
        de las categorias de los campos product_uom  y product_uos
70
74
        '''
71
 
        res={}
72
 
        for i in self.browse(cr,uid,ids):
73
 
            res[i.id] = (i.product_id.uom_id.category_id.id,i.product_id.uom_id.category_id.name)
 
75
        res = {}
 
76
        for i in self.browse(cr, uid, ids):
 
77
            res[i.id] = (i.product_id.uom_id.category_id.id,
 
78
                         i.product_id.uom_id.category_id.name)
74
79
        return res
75
 
        
76
 
        
 
80
 
77
81
    def _get_category_prod(self, cr, uid, ids, field_name, arg, context):
78
82
        '''
79
83
        funcion para obtener la categoria del producto
80
84
        '''
81
 
        res={}
82
 
        for i in self.browse(cr,uid,ids):
83
 
            res[i.id] = (i.product_id.product_tmpl_id.categ_id.id,i.product_id.product_tmpl_id.categ_id.name)
 
85
        res = {}
 
86
        for i in self.browse(cr, uid, ids):
 
87
            res[i.id] = (i.product_id.product_tmpl_id.categ_id.id,
 
88
                         i.product_id.product_tmpl_id.categ_id.name)
84
89
        return res
85
90
 
86
91
    _columns = {
87
 
        'cost_t': fields.function(_calc_cost, method=True, type='float', digits_compute= dp.get_precision('Cost_Bom'), string='Cost', store=False),
88
 
        'cost_u': fields.function(_calc_cost_u, method=True, type='float',digits_compute= dp.get_precision('Cost_Bom'), string='Unit Cost', store=False),
89
 
        'category_id': fields.function(_get_category, method=True, type='many2one',relation='product.uom.categ',string='Category Uom'),
90
 
        'category_prod_id': fields.function(_get_category_prod, method=True, type='many2one',relation='product.category',string='Category'),
 
92
        'cost_t': fields.function(_calc_cost, method=True, type='float', digits_compute=dp.get_precision('Cost_Bom'), string='Cost', store=False),
 
93
        'cost_u': fields.function(_calc_cost_u, method=True, type='float', digits_compute=dp.get_precision('Cost_Bom'), string='Unit Cost', store=False),
 
94
        'category_id': fields.function(_get_category, method=True, type='many2one', relation='product.uom.categ', string='Category Uom'),
 
95
        'category_prod_id': fields.function(_get_category_prod, method=True, type='many2one', relation='product.category', string='Category'),
91
96
        'product_uom_default_id': fields.related('product_id', 'uom_id', string="Uom Default", type='many2one', relation='product.uom'),
92
97
        #~ 'bom_assets':fields.boolean('Assets', help="Determine if the bom is of type assets."),
93
98
    }
94
 
    
95
99
 
96
100
    def compute_bom_cost(self, cr, uid, ids, *args):
97
 
        for i in self.browse(cr,uid,ids):
 
101
        for i in self.browse(cr, uid, ids):
98
102
            cost = 0.00
99
103
            if i.bom_lines:
100
104
                for l in i.bom_lines:
101
105
                    cost += self.compute_bom_cost(cr, uid, [l.id])
102
106
            else:
103
 
                cost = i.product_id.standard_price*i.product_qty* i.product_uom.factor_inv * i.product_id.uom_id.factor
104
 
                
 
107
                cost = i.product_id.standard_price*i.product_qty * \
 
108
                    i.product_uom.factor_inv * i.product_id.uom_id.factor
 
109
 
105
110
            if i.routing_id:
106
111
                for j in i.routing_id.workcenter_lines:
107
112
                    cost += j.costo_total
108
 
                
 
113
 
109
114
        return cost
110
 
    
111
 
mrp_bom()
112
115