~cristian-rocha/openerp-l10n-ar-localization/8.0

« back to all changes in this revision

Viewing changes to l10n_ar_bank/wizard/wiz_l10n_ar_bank.py

  • Committer: López, Ignacio Martín
  • Date: 2012-09-20 22:30:02 UTC
  • mto: This revision was merged to the branch mainline in revision 61.
  • Revision ID: lopezignacio@gmail.com-20120920223002-x7lt8y822hp5x712
[REF] Se crea modulo para actualizar bancos a partir de los scripts y se agrega CABA a provincias

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (C) 2011-2014 OpenERP - Team de Localización Argentina.
 
5
# https://launchpad.net/~openerp-l10n-ar-localization
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
#############################################################################
 
21
 
 
22
from osv import fields,osv
 
23
from tools.translate import _
 
24
import time
 
25
 
 
26
from banks_def import *
 
27
 
 
28
class l10n_ar_banks_wizard(osv.osv_memory):
 
29
    _name = 'l10nar.banks.wizard'
 
30
 
 
31
    def on_cancel(self, cr, uid, ids, context):
 
32
            return {}
 
33
   
 
34
    def on_process (self, cr, uid, ids, context): 
 
35
        """
 
36
            Tomo los datos de los banco de BCRA. 
 
37
        """
 
38
        Resultados={}
 
39
        bancos_procesados = 0
 
40
        bancos_actualizados = 0
 
41
        bancos_nuevos = 0
 
42
        bancos_desahabilitados = 0
 
43
        
 
44
        update_date = time.strftime('%Y-%m-%d')
 
45
        idargentina = self.pool.get('res.country').search(cr, uid, [('name', '=', 'Argentina')])[0]
 
46
        idbuenosaires = self.pool.get('res.country.state').search(cr, uid, [('name', '=', 'Buenos Aires')])[0]
 
47
        idciudadbuenosaires = self.pool.get('res.country.state').search(cr, uid, [('name', '=', 'Ciudad Autónoma de Buenos Aires')])[0]
 
48
        Bancos_obj = self.pool.get('res.bank')
 
49
 
 
50
        TodosLosBancosArgentinos = Bancos_obj.search(cr, uid, [('country', '=', idargentina)])  
 
51
        self.pool.get('res.bank').write(cr, uid, TodosLosBancosArgentinos, {'active': False}, context=context)
 
52
        bancos_desahabilitados = len(TodosLosBancosArgentinos)
 
53
        
 
54
        for bank in ar_banks_iterator():                    
 
55
            bancos_procesados += 1
 
56
            vals={}         
 
57
            for key in bankfields:
 
58
                if key in bank:
 
59
                    valor=bank[key]
 
60
                    if key == 'country' : 
 
61
                        valor=idargentina
 
62
                    if key == 'state' : 
 
63
                        if bank[key] == 'Buenos Aires':
 
64
                            valor = idbuenosaires
 
65
                        elif bank[key] == 'Autonomous City of Buenos Aires':
 
66
                            valor = idciudadbuenosaires
 
67
                        else: 
 
68
                            valor = self.pool.get('res.country.state').search(cr, uid, [('name', '=', bank[key])])[0]
 
69
                    vals.update({key:valor})
 
70
            
 
71
            vals.update({'update' : time.strftime('%Y-%m-%d')})
 
72
               
 
73
            Bancos_ids = Bancos_obj.search(cr, uid, [('name', '=', bank.get('name')),('country', '=', idargentina),('active', '=', False)])
 
74
            if not(Bancos_ids):
 
75
                Bancos_ids = Bancos_obj.search(cr, uid, [('vat', '=', bank.get('vat')), ('country', '=', idargentina),('active', '=', False)])
 
76
                if not(Bancos_ids):
 
77
                    Bancos_ids = Bancos_obj.search(cr, uid, [('street', '=', bank.get('street')), ('city', '=', bank.get('city')), ('country', '=', idargentina),('active', '=', False)])               
 
78
                    
 
79
            if Bancos_ids:
 
80
                bancos_desahabilitados -= 1
 
81
                bancos_actualizados += 1
 
82
                self.pool.get('res.bank').write(cr, uid, [Bancos_ids[0]], vals, context=context)
 
83
            else:
 
84
                bancos_nuevos += 1
 
85
                self.pool.get('res.bank').create(cr, uid, vals, context=context)
 
86
 
 
87
        Resultados.update({'bancos_procesados' : bancos_procesados})
 
88
        Resultados.update({'bancos_actualizados' : bancos_actualizados})
 
89
        Resultados.update({'bancos_nuevos' : bancos_nuevos})
 
90
        Resultados.update({'bancos_desahabilitados' : bancos_desahabilitados})
 
91
        
 
92
        return {
 
93
                'view_type': 'form',
 
94
                'view_mode': 'form',
 
95
                'context': Resultados,
 
96
                'res_model': 'l10nar.banks.wizard.result',
 
97
                'type': 'ir.actions.act_window',
 
98
                'target': 'new'
 
99
            }    
 
100
 
 
101
l10n_ar_banks_wizard()
 
102
 
 
103
 
 
104
class l10n_ar_banks_wizard_result(osv.osv_memory):
 
105
    _name = 'l10nar.banks.wizard.result'
 
106
 
 
107
    def _get_bancos_actualizados(self, cr, uid, context=None):
 
108
        if context is None:
 
109
            context = {}
 
110
        valor = context.get('bancos_actualizados')
 
111
        return valor
 
112
        
 
113
    def _get_bancos_nuevos(self, cr, uid, context=None):
 
114
        if context is None:
 
115
            context = {}
 
116
        valor = context.get('bancos_nuevos')
 
117
        return valor
 
118
 
 
119
    def _get_bancos_desahabilitados(self, cr, uid, context=None):
 
120
        if context is None:
 
121
            context = {}
 
122
        valor = context.get('bancos_desahabilitados')
 
123
        return valor
 
124
 
 
125
    def _get_bancos_procesados(self, cr, uid, context=None):
 
126
        if context is None:
 
127
            context = {}
 
128
        valor = context.get('bancos_procesados')
 
129
        return valor
 
130
 
 
131
    _columns = {
 
132
                  'bancos_actualizados' : fields.char(_('Banks Upgraded'), size=3),
 
133
                  'bancos_nuevos' : fields.char(_('New Banks'), size=3),
 
134
                  'bancos_desahabilitados' : fields.char(_('Desactivated Banks'), size=3),
 
135
                  'bancos_procesados' : fields.char(_('Banks total processed'), size=3),
 
136
                }
 
137
    _defaults = {
 
138
                  'bancos_actualizados' : _get_bancos_actualizados,
 
139
                  'bancos_nuevos' : _get_bancos_nuevos,
 
140
                  'bancos_desahabilitados' : _get_bancos_desahabilitados,
 
141
                  'bancos_procesados' : _get_bancos_procesados,
 
142
                }
 
143
   
 
144
    def on_close(self, cr, uid, ids, context):
 
145
            return {}
 
146
      
 
147
l10n_ar_banks_wizard_result()
 
 
b'\\ No newline at end of file'