Skip to content

Commit a1b72f7

Browse files
filoquinjjscarafia
authored andcommittedSep 1, 2021
[fix] - Actualizo vistas de wizard y partner para mejorar la UX
- Agrego el campo last_update_census para guardar la fecha de actualizacion - creo la funcion parce_census_vals para permitir extender datos del padron de otros modulos - Elimino campos que aun no estan el la localizacion (por ejempo los del los padrones) - ahora es la interseccion de dos arrys evitando problemas con posible campos inexistentes en el modelo partner fields_names = list(set(partner_vals) & set(fields_names))
1 parent 1f6f4c1 commit a1b72f7

File tree

3 files changed

+120
-156
lines changed

3 files changed

+120
-156
lines changed
 

‎l10n_ar_afipws/models/res_partner.py

+64-67
Original file line numberDiff line numberDiff line change
@@ -16,108 +16,64 @@
1616
class ResPartner(models.Model):
1717
_inherit = 'res.partner'
1818

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+
)
2522

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):
6426

6527
# porque imp_iva activo puede ser S o AC
66-
imp_iva = padron.imp_iva
28+
imp_iva = census.imp_iva
6729
if imp_iva == 'S':
6830
imp_iva = 'AC'
6931
elif imp_iva == 'N':
7032
# por ej. monotributista devuelve N
7133
imp_iva = 'NI'
7234

7335
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,
8340
'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(),
8942
}
43+
44+
# padron.idProvincia
45+
9046
ganancias_inscripto = [10, 11]
9147
ganancias_exento = [12]
92-
if set(ganancias_inscripto) & set(padron.impuestos):
48+
if set(ganancias_inscripto) & set(census.impuestos):
9349
vals['imp_ganancias_padron'] = 'AC'
94-
elif set(ganancias_exento) & set(padron.impuestos):
50+
elif set(ganancias_exento) & set(census.impuestos):
9551
vals['imp_ganancias_padron'] = 'EX'
96-
elif padron.monotributo == 'S':
52+
elif census.monotributo == 'S':
9753
vals['imp_ganancias_padron'] = 'NC'
9854
else:
9955
_logger.info(
10056
"We couldn't get impuesto a las ganancias from padron, you"
10157
"must set it manually")
10258

103-
if padron.provincia:
59+
if census.provincia:
10460
# depending on the database, caba can have one of this codes
10561
caba_codes = ['C', 'CABA', 'ABA']
10662
# if not localidad then it should be CABA.
107-
if not padron.localidad:
63+
if not census.localidad:
10864
state = self.env['res.country.state'].search([
10965
('code', 'in', caba_codes),
11066
('country_id.code', '=', 'AR')], limit=1)
11167
# If localidad cant be caba
11268
else:
11369
state = self.env['res.country.state'].search([
114-
('name', 'ilike', padron.provincia),
70+
('name', 'ilike', census.provincia),
11571
('code', 'not in', caba_codes),
11672
('country_id.code', '=', 'AR')], limit=1)
11773
if state:
11874
vals['state_id'] = state.id
11975

120-
if imp_iva == 'NI' and padron.monotributo == 'S':
76+
if imp_iva == 'NI' and census.monotributo == 'S':
12177
vals['l10n_ar_afip_responsibility_type_id'] = self.env.ref(
12278
'l10n_ar.res_RM').id
12379
elif imp_iva == 'AC':
@@ -131,4 +87,45 @@ def get_data_from_padron_afip(self):
13187
"We couldn't infer the AFIP responsability from padron, you"
13288
"must set it manually.")
13389

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

‎l10n_ar_afipws/wizard/res_partner_update_from_padron_wizard.py

+10-22
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ class ResPartnerUpdateFromPadronField(models.TransientModel):
1414
'Wizard',
1515
)
1616
field = fields.Char(
17+
'name'
1718
)
1819
old_value = fields.Char(
20+
'old Value'
1921
)
2022
new_value = fields.Char(
23+
'new Value'
2124
)
2225

2326

@@ -59,21 +62,11 @@ def default_get(self, fields):
5962
def _get_domain(self):
6063
fields_names = [
6164
'name',
62-
'estado_padron',
6365
'street',
6466
'city',
6567
'zip',
66-
'actividades_padron',
67-
'impuestos_padron',
68-
'imp_iva_padron',
69-
'state_id',
70-
'imp_ganancias_padron',
71-
'monotributo_padron',
72-
'actividad_monotributo_padron',
73-
'empleador_padron',
74-
'integrante_soc_padron',
75-
'last_update_padron',
76-
'afip_responsability_type_id',
68+
'l10n_ar_afip_responsibility_type_id',
69+
'last_update_census'
7770
]
7871
return [
7972
('model', '=', 'res.partner'),
@@ -137,7 +130,6 @@ def get_fields(self):
137130
required=True,
138131
)
139132

140-
141133
@api.onchange('partner_id')
142134
def change_partner(self):
143135
self.ensure_one()
@@ -147,15 +139,17 @@ def change_partner(self):
147139
if partner:
148140
partner_vals = partner.get_data_from_padron_afip()
149141
lines = []
150-
for key, new_value in partner_vals.items():
142+
fields_names = list(set(partner_vals) & set(fields_names))
143+
for key in fields_names:
151144
old_value = partner[key]
145+
new_value = partner_vals[key]
152146
if new_value == '':
153147
new_value = False
154148
if self.title_case and key in ('name', 'city', 'street'):
155149
new_value = new_value and new_value.title()
156150
if key in ('impuestos_padron', 'actividades_padron'):
157151
old_value = old_value.ids
158-
elif key in ('state_id', 'afip_responsability_type_id'):
152+
elif key in ('state_id', 'l10n_ar_afip_responsibility_type_id'):
159153
old_value = old_value.id
160154
if new_value and key in fields_names and \
161155
old_value != new_value:
@@ -168,7 +162,6 @@ def change_partner(self):
168162
lines.append((0, False, line_vals))
169163
self.field_ids = lines
170164

171-
172165
def _update(self):
173166
self.ensure_one()
174167
vals = {}
@@ -179,7 +172,6 @@ def _update(self):
179172
vals[field.field] = field.new_value
180173
self.partner_id.write(vals)
181174

182-
183175
def automatic_process_cb(self):
184176
for partner in self.partner_ids:
185177
self.partner_id = partner.id
@@ -195,7 +187,6 @@ def automatic_process_cb(self):
195187
'target': 'new',
196188
}
197189

198-
199190
def update_selection(self):
200191
self.ensure_one()
201192
if not self.field_ids:
@@ -210,7 +201,6 @@ def update_selection(self):
210201
self._update()
211202
return self.next_cb()
212203

213-
214204
def next_cb(self):
215205
"""
216206
"""
@@ -219,7 +209,6 @@ def next_cb(self):
219209
self.write({'partner_ids': [(3, self.partner_id.id, False)]})
220210
return self._next_screen()
221211

222-
223212
def _next_screen(self):
224213
self.ensure_one()
225214
self.refresh()
@@ -248,10 +237,9 @@ def _next_screen(self):
248237
'target': 'new',
249238
}
250239

251-
252240
def start_process_cb(self):
253241
"""
254242
Start the process.
255243
"""
256244
self.ensure_one()
257-
return self._next_screen()
245+
return self._next_screen()

0 commit comments

Comments
 (0)