~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to mrp_advance/mrp_bom_cost/mrp.py

  • Committer: Sabrina Romero
  • Date: 2013-08-20 21:10:39 UTC
  • mto: (543.7.272 vaddddddd)
  • mto: This revision was merged to the branch mainline in revision 840.
  • Revision ID: sabrina@vauxoo.com-20130820211039-9jqrffvg2nz8q3vx

[ADD] Module product_do_merge added

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: nhomar@openerp.com.ve,
 
8
#    Coded by: rodo@vauxoo.com,
 
9
#    Planified by: Nhomar Hernandez
 
10
#    Finance by: Helados Gilda, C.A. http://heladosgilda.com.ve
 
11
#    Audited by: Humberto Arocha humberto@openerp.com.ve
 
12
#############################################################################
 
13
#    This program is free software: you can redistribute it and/or modify
 
14
#    it under the terms of the GNU General Public License as published by
 
15
#    the Free Software Foundation, either version 3 of the License, or
 
16
#    (at your option) any later version.
 
17
#
 
18
#    This program is distributed in the hope that it will be useful,
 
19
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
#    GNU General Public License for more details.
 
22
#
 
23
#    You should have received a copy of the GNU General Public License
 
24
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
25
##############################################################################
 
26
from openerp.osv import fields, osv
 
27
from openerp.tools.translate import _
 
28
 
 
29
import decimal_precision as dp
 
30
 
 
31
 
 
32
class mrp_bom(osv.Model):
 
33
    _inherit = 'mrp.bom'
 
34
 
 
35
    def _calc_cost(self, cr, uid, ids, field_name, arg, context):
 
36
        res = {}
 
37
        for i in self.browse(cr, uid, ids):
 
38
            res[i.id] = self.compute_bom_cost(cr, uid, [i.id])
 
39
        return res
 
40
 
 
41
    def _calc_cost_u(self, cr, uid, ids, field_name, arg, context):
 
42
        '''
 
43
        funcion para el calculo del costo unitario, el cual es:
 
44
        product cost/ product qty
 
45
        @cost = se almacena el costo unitario final.
 
46
        @res = diccionario usado para retornar el id y el costo unitario.
 
47
        '''
 
48
        res = {}
 
49
        for i in self.browse(cr, uid, ids):
 
50
            cost = 0.00
 
51
            cost = i.cost_t/i.product_qty
 
52
            for l in i.bom_lines:
 
53
                if not l.bom_lines:
 
54
                    cost = l.product_id.standard_price*l.product_qty
 
55
                    res[i.id] = cost
 
56
                else:
 
57
                    cost = cost + self._calc_cost_u(cr, uid, [l.id],
 
58
                                                field_name, arg,
 
59
                                                context)[l.id]*l.product_qty
 
60
                    res[i.id] = cost/l.product_qty
 
61
            res[i.id] = i.cost_t/i.product_qty
 
62
            if 'sub_products' in i._columns and i.sub_products:
 
63
                sum_amount_subproducts = 0.0
 
64
                product_uom_obj = self.pool.get('product.uom')
 
65
                for sub_prod in i.sub_products:
 
66
                    sum_amount_subproducts += (product_uom_obj._compute_price(
 
67
                        cr, uid, sub_prod.product_id.uom_id.id,
 
68
                        sub_prod.product_id.standard_price,
 
69
                        sub_prod.product_uom.id) * sub_prod.product_qty)
 
70
                res[i.id] =  (i.cost_t - sum_amount_subproducts) / \
 
71
                    i.product_qty  # mrp.bom valida cantidades mayores a 0
 
72
        return res
 
73
 
 
74
    def _get_category(self, cr, uid, ids, field_name, arg, context):
 
75
        '''
 
76
        funcion para obtener la categoria del producto y luego aplicarla
 
77
        para la filtracion
 
78
        de las categorias de los campos product_uom  y product_uos
 
79
        '''
 
80
        res = {}
 
81
        for i in self.browse(cr, uid, ids):
 
82
            res[i.id] = (i.product_id.uom_id.category_id.id,
 
83
                         i.product_id.uom_id.category_id.name)
 
84
        return res
 
85
 
 
86
    def _get_category_prod(self, cr, uid, ids, field_name, arg, context):
 
87
        '''
 
88
        funcion para obtener la categoria del producto
 
89
        '''
 
90
        res = {}
 
91
        for i in self.browse(cr, uid, ids):
 
92
            res[i.id] = (i.product_id.product_tmpl_id.categ_id.id,
 
93
                         i.product_id.product_tmpl_id.categ_id.name)
 
94
        return res
 
95
 
 
96
    _columns = {
 
97
        'cost_t': fields.function(_calc_cost, method=True, type='float',
 
98
            digits_compute=dp.get_precision('Cost_Bom'),
 
99
            string='Cost', store=False),
 
100
        'cost_u': fields.function(_calc_cost_u, method=True, type='float',
 
101
            digits_compute=dp.get_precision('Cost_Bom'),
 
102
            string='Unit Cost', store=False),
 
103
        'category_id': fields.function(_get_category, method=True,
 
104
            type='many2one', relation='product.uom.categ',
 
105
            string='Category Uom'),
 
106
        'category_prod_id': fields.function(_get_category_prod, method=True,
 
107
            type='many2one', relation='product.category', string='Category'),
 
108
        'product_uom_default_id': fields.related('product_id', 'uom_id',
 
109
            string="Uom Default", type='many2one', relation='product.uom'),
 
110
        #~ 'bom_assets':fields.boolean('Assets', help="Determine if the bom is of type assets."),
 
111
    }
 
112
 
 
113
    def compute_bom_cost(self, cr, uid, ids, *args):
 
114
        for i in self.browse(cr, uid, ids):
 
115
            cost = 0.00
 
116
            if i.bom_lines:
 
117
                for l in i.bom_lines:
 
118
                    cost += self.compute_bom_cost(cr, uid, [l.id])
 
119
            else:
 
120
                cost = i.product_id.standard_price*i.product_qty * \
 
121
                    i.product_uom.factor_inv * i.product_id.uom_id.factor
 
122
 
 
123
            if i.routing_id:
 
124
                for j in i.routing_id.workcenter_lines:
 
125
                    cost += j.costo_total
 
126
 
 
127
        return cost