~isaac.delabarrera/+junk/editorial-addons-5.0

« back to all changes in this revision

Viewing changes to crm_agendas_escolares/wizard/wizard_show_production_lines.py

  • Committer: isaac.delabarrera at gmail
  • Date: 2012-07-03 16:25:45 UTC
  • Revision ID: isaac.delabarrera@gmail.com-20120703162545-0k2d10hn3m47yvik
New Reports

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from mx.DateTime import now
 
24
 
 
25
import wizard
 
26
import netsvc
 
27
import ir
 
28
import pooler
 
29
from tools.translate import _
 
30
 
 
31
init_form = '''<?xml version="1.0"?>
 
32
<form string="Ver Líneas de Producción" col="6">  
 
33
    <field name="campaign_id"/>  
 
34
</form>'''
 
35
init_fields = {
 
36
    'campaign_id': {'type':'many2one', 'relation':'campaign.campaign', 'string':'Campaña', 'required':True},
 
37
}
 
38
 
 
39
class show_production(wizard.interface):
 
40
 
 
41
    def _show_production_dos_lineas(self, cr, uid, data, context):
 
42
        pool = pooler.get_pool(cr.dbname)
 
43
        campaign_id = data['form']['campaign_id']
 
44
        production_lines_obj = pool.get('crm.agendas.production.order.lines')
 
45
        production_obj = pool.get('crm.agendas.production.order')
 
46
        
 
47
        production_ids = production_obj.search(cr, uid, [('campaign','=',campaign_id)])
 
48
        order_ids = production_lines_obj.search(cr, uid, [('production_id','in',production_ids)])
 
49
        orders = production_lines_obj.read(cr, uid, order_ids, ['production_id'])
 
50
        orders_ids = [x['production_id'][0] for x in orders]
 
51
        orders_ids.sort()
 
52
        set_lista = set(orders_ids)
 
53
        set_lista = list(set_lista)
 
54
        set_lista.sort()      
 
55
        lista_final = []  
 
56
        for numero in set_lista:
 
57
            if orders_ids.count(numero) >= 2:
 
58
                lista_final.append(numero)
 
59
 
 
60
        value = {
 
61
            'domain': "[('id','in',(" + str(lista_final) +"))]",
 
62
            'view_type': 'form',
 
63
            'view_mode': 'tree,form',
 
64
            'res_model': 'crm.agendas.production.order',
 
65
            'type': 'ir.actions.act_window',
 
66
        }
 
67
        return value                
 
68
 
 
69
    def _suma_de_cantidades_error(self, cr, uid, data, context):
 
70
        pool = pooler.get_pool(cr.dbname)
 
71
        campaign_id = data['form']['campaign_id']
 
72
        production_lines_obj = pool.get('crm.agendas.production.order.lines')
 
73
        production_obj = pool.get('crm.agendas.production.order')
 
74
        
 
75
        production_ids = production_obj.search(cr, uid, [('campaign','=',campaign_id)])
 
76
        lista_final = []
 
77
        
 
78
        for production_id in production_obj.browse(cr, uid, production_ids):
 
79
            sum_lines = 0
 
80
            if production_id.lines_ids:
 
81
                for line_id in production_id.lines_ids:
 
82
                    sum_lines = sum_lines + line_id.cantidad
 
83
                sum_cantidad = production_id.primaria + production_id.secundaria + \
 
84
                    production_id.bachillerato + production_id.bilingue + \
 
85
                    production_id.inf_0a3 + production_id.inf_3a6 + production_id.cantidad   
 
86
                if sum_cantidad != sum_lines:
 
87
                    lista_final.append(production_id.id)
 
88
                
 
89
        value = {
 
90
            'domain': "[('id','in',(" + str(lista_final) +"))]",
 
91
            'view_type': 'form',
 
92
            'view_mode': 'tree,form',
 
93
            'res_model': 'crm.agendas.production.order',
 
94
            'type': 'ir.actions.act_window',
 
95
        }
 
96
        return value
 
97
 
 
98
    states = {
 
99
        'init': {
 
100
            'actions': [], 
 
101
            'result': {'type':'form', 'arch':init_form, 'fields':init_fields,
 
102
                       'state':[('end','Cancel','gtk-cancel')
 
103
                                ,('dos_lineas_pers','Dos Líneas Personalizadas','gtk-go-forward')
 
104
                                ,('error_cantidades','Error Cantidades','gtk-go-forward')]}
 
105
        },
 
106
        'dos_lineas_pers':{
 
107
            'actions':[],
 
108
            'result':{'type':'action', 'action':_show_production_dos_lineas, 'state':'end'}
 
109
        },
 
110
        'error_cantidades':{
 
111
            'actions':[],
 
112
            'result':{'type':'action', 'action':_suma_de_cantidades_error, 'state':'end'}
 
113
        },
 
114
              
 
115
}
 
116
 
 
117
show_production('crm_agendas_escolares.show_production')
 
118
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
119