2
# -*- encoding: utf-8 -*-
3
###########################################################################
4
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
7
# Credits######################################################
8
# Coded by: Vauxoo C.A.
9
# Planified by: Nhomar Hernandez
10
# Audited by: Vauxoo C.A.
11
#############################################################################
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as published by
14
# the Free Software Foundation, either version 3 of the License, or
15
# (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU Affero General Public License for more details.
22
# You should have received a copy of the GNU Affero General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
##########################################################################
25
from openerp.osv import fields, osv
26
from openerp.tools.translate import _
29
import decimal_precision as dp
32
class stock_inventory_line(osv.Model):
33
_inherit = 'stock.inventory.line'
37
def _get_cost(self, cr, uid, ids, name, args, context={}):
40
res[id] = self.compute_cost(cr, uid, [id])
44
'cost': fields.function(_get_cost, method=True, digits_compute=dp.get_precision('Account'), string='Costo'),
47
def search_date_desc(self, cr, uid, ids, product_id, date):
48
cr.execute('SELECT price FROM product_historic_cost '
49
'WHERE product_id=%s AND name <= %s ORDER BY name desc LIMIT 1', (product_id, date))
50
res = [x[0] for x in cr.fetchall()]
57
def search_date_asc(self, cr, uid, ids, product_id, date):
58
cr.execute('SELECT price FROM product_historic_cost '
59
'WHERE product_id=%s AND name > %s ORDER BY name asc LIMIT 1', (product_id, date))
60
res = [x[0] for x in cr.fetchall()]
67
def compute_cost(self, cr, uid, ids, *args):
68
prod_obj = self.pool.get('product.product')
70
inv_brw = self.browse(cr, uid, ids, context=None)[0]
71
date = inv_brw.inventory_id.date
72
costo = self.search_date_desc(
73
cr, uid, ids, inv_brw.product_id.id, date)
75
costo = self.search_date_asc(
76
cr, uid, ids, inv_brw.product_id.id, date)
77
costo = costo * inv_brw.product_qty * \
78
inv_brw.product_uom.factor_inv * inv_brw.product_id.uom_id.factor
83
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: