16
16
class ResPartner (models .Model ):
17
17
_inherit = 'res.partner'
18
18
19
- def cuit_required (self ):
20
- self .ensure_one ()
21
- if not self .vat :
22
- raise UserError (_ ('No CUIT configured for partner [%i] %s' ) % (
23
- self .id , self .name ))
24
- return self .vat
19
+ last_update_census = fields .Date (
20
+ string = 'Last update census'
21
+ )
25
22
26
- def get_data_from_padron_afip (self ):
27
- self .ensure_one ()
28
- cuit = self .cuit_required ()
29
-
30
- # GET COMPANY
31
- # if there is certificate for user company, use that one, if not
32
- # use the company for the first certificate found
33
- company = self .env .user .company_id
34
- env_type = company ._get_environment_type ()
35
- try :
36
- certificate = company .get_key_and_certificate (
37
- company ._get_environment_type ())
38
- except Exception :
39
- certificate = self .env ['afipws.certificate' ].search ([
40
- ('alias_id.type' , '=' , env_type ),
41
- ('state' , '=' , 'confirmed' ),
42
- ], limit = 1 )
43
- if not certificate :
44
- raise UserError (_ (
45
- 'Not confirmed certificate found on database' ))
46
- company = certificate .alias_id .company_id
47
-
48
- # consultamos a5 ya que extiende a4 y tiene validez de constancia
49
- padron = company .get_connection ('ws_sr_padron_a5' ).connect ()
50
- error_msg = _ (
51
- 'No pudimos actualizar desde padron afip al partner %s (%s).\n '
52
- 'Recomendamos verificar manualmente en la página de AFIP.\n '
53
- 'Obtuvimos este error: %s' )
54
- try :
55
- padron .Consultar (cuit )
56
- except SoapFault as e :
57
- raise UserError (error_msg % (self .name , cuit , e .faultstring ))
58
- except Exception as e :
59
- raise UserError (error_msg % (self .name , cuit , e ))
60
-
61
- if not padron .denominacion or padron .denominacion == ', ' :
62
- raise UserError (error_msg % (
63
- self .name , cuit , 'La afip no devolvió nombre' ))
23
+ # Separo esto para poder heredar de otros
24
+ # modulos y extender los datos
25
+ def parce_census_vals (self , census ):
64
26
65
27
# porque imp_iva activo puede ser S o AC
66
- imp_iva = padron .imp_iva
28
+ imp_iva = census .imp_iva
67
29
if imp_iva == 'S' :
68
30
imp_iva = 'AC'
69
31
elif imp_iva == 'N' :
70
32
# por ej. monotributista devuelve N
71
33
imp_iva = 'NI'
72
34
73
35
vals = {
74
- 'name' : padron .denominacion ,
75
- 'estado_padron' : padron .estado ,
76
- 'street' : padron .direccion ,
77
- 'city' : padron .localidad ,
78
- 'zip' : padron .cod_postal ,
79
- 'actividades_padron' : self .actividades_padron .search (
80
- [('code' , 'in' , padron .actividades )]).ids ,
81
- 'impuestos_padron' : self .impuestos_padron .search (
82
- [('code' , 'in' , padron .impuestos )]).ids ,
36
+ 'name' : census .denominacion ,
37
+ 'street' : census .direccion ,
38
+ 'city' : census .localidad ,
39
+ 'zip' : census .cod_postal ,
83
40
'imp_iva_padron' : imp_iva ,
84
- 'monotributo_padron' : padron .monotributo ,
85
- 'actividad_monotributo_padron' : padron .actividad_monotributo ,
86
- 'empleador_padron' : padron .empleador == 'S' and True ,
87
- 'integrante_soc_padron' : padron .integrante_soc ,
88
- 'last_update_padron' : fields .Date .today (),
41
+ 'last_update_census' : fields .Date .today (),
89
42
}
43
+
44
+ # padron.idProvincia
45
+
90
46
ganancias_inscripto = [10 , 11 ]
91
47
ganancias_exento = [12 ]
92
- if set (ganancias_inscripto ) & set (padron .impuestos ):
48
+ if set (ganancias_inscripto ) & set (census .impuestos ):
93
49
vals ['imp_ganancias_padron' ] = 'AC'
94
- elif set (ganancias_exento ) & set (padron .impuestos ):
50
+ elif set (ganancias_exento ) & set (census .impuestos ):
95
51
vals ['imp_ganancias_padron' ] = 'EX'
96
- elif padron .monotributo == 'S' :
52
+ elif census .monotributo == 'S' :
97
53
vals ['imp_ganancias_padron' ] = 'NC'
98
54
else :
99
55
_logger .info (
100
56
"We couldn't get impuesto a las ganancias from padron, you"
101
57
"must set it manually" )
102
58
103
- if padron .provincia :
59
+ if census .provincia :
104
60
# depending on the database, caba can have one of this codes
105
61
caba_codes = ['C' , 'CABA' , 'ABA' ]
106
62
# if not localidad then it should be CABA.
107
- if not padron .localidad :
63
+ if not census .localidad :
108
64
state = self .env ['res.country.state' ].search ([
109
65
('code' , 'in' , caba_codes ),
110
66
('country_id.code' , '=' , 'AR' )], limit = 1 )
111
67
# If localidad cant be caba
112
68
else :
113
69
state = self .env ['res.country.state' ].search ([
114
- ('name' , 'ilike' , padron .provincia ),
70
+ ('name' , 'ilike' , census .provincia ),
115
71
('code' , 'not in' , caba_codes ),
116
72
('country_id.code' , '=' , 'AR' )], limit = 1 )
117
73
if state :
118
74
vals ['state_id' ] = state .id
119
75
120
- if imp_iva == 'NI' and padron .monotributo == 'S' :
76
+ if imp_iva == 'NI' and census .monotributo == 'S' :
121
77
vals ['l10n_ar_afip_responsibility_type_id' ] = self .env .ref (
122
78
'l10n_ar.res_RM' ).id
123
79
elif imp_iva == 'AC' :
@@ -131,4 +87,45 @@ def get_data_from_padron_afip(self):
131
87
"We couldn't infer the AFIP responsability from padron, you"
132
88
"must set it manually." )
133
89
134
- return vals
90
+ return vals
91
+
92
+ def get_data_from_padron_afip (self ):
93
+ self .ensure_one ()
94
+ cuit = self .ensure_vat ()
95
+
96
+ # GET COMPANY
97
+ # if there is certificate for user company, use that one, if not
98
+ # use the company for the first certificate found
99
+ company = self .env .user .company_id
100
+ env_type = company ._get_environment_type ()
101
+ try :
102
+ certificate = company .get_key_and_certificate (
103
+ company ._get_environment_type ())
104
+ except Exception :
105
+ certificate = self .env ['afipws.certificate' ].search ([
106
+ ('alias_id.type' , '=' , env_type ),
107
+ ('state' , '=' , 'confirmed' ),
108
+ ], limit = 1 )
109
+ if not certificate :
110
+ raise UserError (_ (
111
+ 'Not confirmed certificate found on database' ))
112
+ company = certificate .alias_id .company_id
113
+
114
+ # consultamos a5 ya que extiende a4 y tiene validez de constancia
115
+ padron = company .get_connection ('ws_sr_padron_a5' ).connect ()
116
+ error_msg = _ (
117
+ 'No pudimos actualizar desde padron afip al partner %s (%s).\n '
118
+ 'Recomendamos verificar manualmente en la página de AFIP.\n '
119
+ 'Obtuvimos este error: %s' )
120
+ try :
121
+ padron .Consultar (cuit )
122
+ except SoapFault as e :
123
+ raise UserError (error_msg % (self .name , cuit , e .faultstring ))
124
+ except Exception as e :
125
+ raise UserError (error_msg % (self .name , cuit , e ))
126
+
127
+ if not padron .denominacion or padron .denominacion == ', ' :
128
+ raise UserError (error_msg % (
129
+ self .name , cuit , 'La afip no devolvió nombre' ))
130
+ vals = self .parce_census_vals (padron )
131
+ return vals
0 commit comments