Import clients
This commit is contained in:
parent
aa68225571
commit
892906c46f
|
@ -775,7 +775,6 @@ def to_slug(string):
|
|||
def read_csv(path, args={'delimiter': '|'}):
|
||||
with open(path) as f:
|
||||
reader = csv.DictReader(f, **args)
|
||||
# ~ rows = tuple(csv.reader(f, **args))
|
||||
rows = [r for r in reader]
|
||||
return rows
|
||||
|
||||
|
|
|
@ -10524,25 +10524,28 @@ def _import_clients(rfc, path):
|
|||
log.info('Importando clientes...')
|
||||
|
||||
data = utils.read_csv(path)
|
||||
t = len(data)
|
||||
for i, row in enumerate(data):
|
||||
if i == 0:
|
||||
msg = f'\tImportando cliente {i+1} de {t}'
|
||||
log.info(msg)
|
||||
row['rfc'] = row['rfc'].upper()
|
||||
row['nombre'] = utils.spaces(row['nombre'])
|
||||
row['slug'] = utils.to_slug(row['nombre'])
|
||||
|
||||
w = ((Socios.rfc==row['rfc']) & (Socios.slug==row['slug']))
|
||||
if Socios.select().where(w).exists():
|
||||
msg = 'Ya existe el RFC y Razón Social'
|
||||
log.info(msg)
|
||||
continue
|
||||
print(row)
|
||||
|
||||
# ~ w = ((Socios.rfc==fields['rfc']) & (Socios.slug==fields['slug']))
|
||||
# ~ if Socios.select().where(w).exists():
|
||||
# ~ msg = 'Ya existe el RFC y Razón Social'
|
||||
# ~ data = {'ok': False, 'row': {}, 'new': True, 'msg': msg}
|
||||
# ~ return data
|
||||
row['es_cliente'] = True
|
||||
row['forma_pago'] = SATFormaPago.get(SATFormaPago.id==row['forma_pago'])
|
||||
|
||||
# ~ try:
|
||||
# ~ obj = Socios.create(**fields)
|
||||
# ~ except IntegrityError as e:
|
||||
# ~ msg = 'Ocurrio un error, al dar de alta el emisor'
|
||||
# ~ data = {'ok': False, 'row': {}, 'new': True, 'msg': msg}
|
||||
# ~ return data
|
||||
|
||||
break
|
||||
try:
|
||||
obj = Socios.create(**row)
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
break
|
||||
|
||||
desconectar()
|
||||
log.info('Proceso terminado correctamente...')
|
||||
|
|
Loading…
Reference in New Issue