~openbias/bias-trunk/addons_minerales

« back to all changes in this revision

Viewing changes to bias_cost_report_minerales/wizard/wizard_report_produccion_plant.py

  • Committer: Jose Patricio
  • Date: 2011-12-01 16:01:00 UTC
  • mfrom: (546.1.7 addons_mx)
  • Revision ID: josepato@bias.com.mx-20111201160100-k10fh8uok4pnnwdq
elĀ mergeĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
}
48
48
 
49
49
def _get_details(self, cr, uid, data, context={}):
50
 
    self._get_library_query(cr, uid, data, context={})
51
50
    pool = pooler.get_pool(cr.dbname)
52
51
    fiscalyear_obj = pool.get('account.fiscalyear')
53
52
    user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
73
72
        ids = reports.search(cr, uid, [('name','=','Produccion planta'),('report_name', '=', 'report.production.plant.graphics'),('report_rml','ilike','.jrxml')], context=context)
74
73
        dat = reports.write(cr, uid, ids[0], {'jasper_output':'pdf'})
75
74
        return {}
76
 
 
77
 
    def _get_library_query(self, cr, uid, data, context={}):        
78
 
        cr.execute("""
79
 
            CREATE OR REPLACE FUNCTION get_production_plant(location_id integer, fiscalyear character varying)
80
 
            RETURNS SETOF "record" AS
81
 
            $BODY$
82
 
            DECLARE
83
 
                r RECORD;
84
 
                r1 RECORD;
85
 
                r2 RECORD;
86
 
                r3 RECORD;
87
 
                query varchar;
88
 
                i integer;
89
 
                fiscal_year integer[];
90
 
                indx integer := 1;
91
 
                array_dim integer := 0;
92
 
                fiscalyear_id integer := 0;
93
 
                fiscalyear_name varchar := '';
94
 
                month_name varchar[];
95
 
            BEGIN
96
 
                fiscal_year := fiscalyear;
97
 
                array_dim := array_upper(fiscal_year, 1);
98
 
                month_name := ARRAY['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'];
99
 
                WHILE array_dim >= indx
100
 
                LOOP
101
 
                    fiscalyear_id := fiscal_year[indx];
102
 
                    FOR r3 IN EXECUTE 'SELECT name FROM account_fiscalyear WHERE id = '||fiscalyear_id||' '
103
 
                    LOOP
104
 
                        fiscalyear_name := r3.name;
105
 
                    END LOOP;
106
 
                    FOR r IN EXECUTE 'SELECT pp.id, pp.default_code, ppp.sequence 
107
 
                        FROM production_plant_product ppp
108
 
                        LEFT JOIN product_product pp ON (ppp.product_id = pp.id) 
109
 
                        WHERE ppp.type = ''fp'' AND ppp.plant_id = '|| location_id ||'
110
 
                        ORDER BY ppp.sequence;'
111
 
                    LOOP
112
 
                        i := 1;
113
 
                        FOR r1 IN EXECUTE 'SELECT ap.id AS period_id, ap.name AS period_name, COALESCE(pp.id, 0) AS production_id
114
 
                            FROM account_period ap
115
 
                            LEFT JOIN production_plant pp ON (ap.id = pp.period_id AND pp.location_id = '|| location_id ||')
116
 
                            WHERE ap.fiscalyear_id = '|| fiscalyear_id ||' ORDER BY ap.id;'
117
 
                        LOOP
118
 
                            FOR r2 IN EXECUTE 'SELECT COALESCE(SUM(ppp.pqty_'||r.sequence||'), 0) AS producto
119
 
                                FROM production_plant_production ppp WHERE ppp.production_id = '||quote_literal(r1.production_id)||';'
120
 
                            LOOP
121
 
                                r2 = (r.sequence, r.id, r.default_code, fiscalyear_id, fiscalyear_name, r1.period_id, i, month_name[i], r1.production_id, (r2.producto/1000));
122
 
                                RETURN NEXT r2;
123
 
                            END LOOP;
124
 
                            i := i + 1;
125
 
                        END LOOP;
126
 
                    END LOOP;
127
 
                    indx := indx + 1;
128
 
                END LOOP;                
129
 
            RETURN;
130
 
            END;
131
 
            $BODY$
132
 
            LANGUAGE 'plpgsql' VOLATILE;
133
 
        """)
134
 
        return {
135
 
        }
136
75
        
137
76
    states = {
138
77
        'init': {