1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2014 SF Soluciones.
5
# (http://www.sfsoluciones.com)
6
# contacto@sfsoluciones.com
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
25
class product_product(osv.osv):
26
_inherit = 'product.product'
28
def set_qty_available_function(self, cr, uid, context=None):
29
cr.execute("""drop function if exists get_qty_onhand(product_id integer);
30
CREATE OR REPLACE FUNCTION get_qty_onhand
31
(x_product_id integer)
32
RETURNS TABLE(qty float) AS
36
select round(coalesce(sum(x.product_qty)::float, 0.00))
38
coalesce(sum(-m.product_qty * pu.factor / pu2.factor)::float, 0.0) as product_qty
41
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
42
LEFT JOIN product_product pp ON (m.product_id=pp.id)
43
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
44
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
45
LEFT JOIN product_uom pu2 ON (m.product_uom=pu2.id)
46
LEFT JOIN product_uom u ON (m.product_uom=u.id)
47
LEFT JOIN stock_location l ON (m.location_id=l.id)
48
where m.product_id = x_product_id and l.usage = 'internal' and m.state = 'done'
50
m.id, m.product_id, m.product_uom, pt.categ_id, m.location_id, m.location_dest_id,
51
m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id)
54
coalesce(sum(m.product_qty * pu.factor / pu2.factor)::decimal, 0.0) as product_qty
57
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
58
LEFT JOIN product_product pp ON (m.product_id=pp.id)
59
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
60
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
61
LEFT JOIN product_uom pu2 ON (m.product_uom=pu2.id)
62
LEFT JOIN product_uom u ON (m.product_uom=u.id)
63
LEFT JOIN stock_location l ON (m.location_dest_id=l.id)
64
where m.product_id = x_product_id and l.usage='internal' and m.state = 'done'
66
m.id, m.product_id, m.product_uom, pt.categ_id, m.location_id, m.location_dest_id,
67
m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id
71
LANGUAGE 'plpgsql';""")
76
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: