1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2011 Pexego (<www.pexego.es>). All Rights Reserved
6
# $Omar Castiñeira Saavedra$
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
##############################################################################
23
"""Creates functions to search prodlots to block"""
27
class plpgsql_block_prodlots(osv.osv):
28
"""Creates functions to search prodlots to block"""
29
_name = "plpgsql.block.prodlots"
30
_description = "Creates functions to search prodlots to block"
34
"""creates functions when install"""
35
#check if exists the language plpgsql in bbdd, if not, is created for can create functions in this language
36
cr.execute("select * from pg_language where lanname = 'plpgsql'")
38
cr.execute("create language 'plpgsql'")
40
#creates a function. From int parameter (prodlot_id) returns all prodlots child of specific
41
cr.execute("""CREATE OR REPLACE FUNCTION block_prodlots_up(integer)
42
RETURNS SETOF stock_production_lot AS
44
declare parent_move record;
48
FOR parent_move IN select distinct stock_move.* from stock_move
49
inner join stock_move_history_ids on stock_move.id = parent_id
50
where prodlot_id = $1 and state != 'cancel'
52
FOR child_prodlot IN select distinct stock_production_lot.* from stock_move
53
inner join stock_move_history_ids on child_id = stock_move.id
54
inner join stock_production_lot on stock_production_lot.id = stock_move.prodlot_id
55
where parent_id = parent_move.id and stock_move.state != 'cancel' and stock_production_lot.id != $1
57
FOR result in select distinct * from block_prodlots_up(child_prodlot.id)
61
return next child_prodlot;
65
LANGUAGE 'plpgsql';""")
67
#creates a function. From int parameter return the stock_move last childs for this paramenter
68
cr.execute("""CREATE OR REPLACE FUNCTION block_prodlots_down(integer)
69
RETURNS SETOF stock_production_lot AS
71
declare child_move record;
72
parent_prodlot record;
75
FOR child_move IN select distinct stock_move.* from stock_move
76
inner join stock_move_history_ids on stock_move.id = child_id
77
where prodlot_id = $1 and state != 'cancel'
79
FOR parent_prodlot IN select distinct stock_production_lot.* from stock_move
80
inner join stock_move_history_ids on parent_id = stock_move.id
81
inner join stock_production_lot on stock_production_lot.id = stock_move.prodlot_id
82
where child_id = child_move.id and stock_move.state != 'cancel' and stock_production_lot.id != $1
84
FOR result in select distinct * from block_prodlots_down(parent_prodlot.id)
88
return next parent_prodlot;
92
LANGUAGE 'plpgsql';""")
94
plpgsql_block_prodlots()
b'\\ No newline at end of file'