1
# -*- encoding: utf-8 -*-
2
###########################################################################
3
# Module Writen to OpenERP, Open Source Management Solution
4
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
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.
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.
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 _
29
import decimal_precision as dp
32
class mrp_bom(osv.Model):
35
def _calc_cost(self, cr, uid, ids, field_name, arg, context):
37
for i in self.browse(cr, uid, ids):
38
res[i.id] = self.compute_bom_cost(cr, uid, [i.id])
41
def _calc_cost_u(self, cr, uid, ids, field_name, arg, context):
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.
49
for i in self.browse(cr, uid, ids):
51
cost = i.cost_t/i.product_qty
54
cost = l.product_id.standard_price*l.product_qty
57
cost = cost + self._calc_cost_u(cr, uid, [l.id],
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
74
def _get_category(self, cr, uid, ids, field_name, arg, context):
76
funcion para obtener la categoria del producto y luego aplicarla
78
de las categorias de los campos product_uom y product_uos
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)
86
def _get_category_prod(self, cr, uid, ids, field_name, arg, context):
88
funcion para obtener la categoria del producto
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)
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."),
113
def compute_bom_cost(self, cr, uid, ids, *args):
114
for i in self.browse(cr, uid, ids):
117
for l in i.bom_lines:
118
cost += self.compute_bom_cost(cr, uid, [l.id])
120
cost = i.product_id.standard_price*i.product_qty * \
121
i.product_uom.factor_inv * i.product_id.uom_id.factor
124
for j in i.routing_id.workcenter_lines:
125
cost += j.costo_total