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': '|'}):
|
def read_csv(path, args={'delimiter': '|'}):
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
reader = csv.DictReader(f, **args)
|
reader = csv.DictReader(f, **args)
|
||||||
# ~ rows = tuple(csv.reader(f, **args))
|
|
||||||
rows = [r for r in reader]
|
rows = [r for r in reader]
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
|
@ -10524,24 +10524,27 @@ def _import_clients(rfc, path):
|
||||||
log.info('Importando clientes...')
|
log.info('Importando clientes...')
|
||||||
|
|
||||||
data = utils.read_csv(path)
|
data = utils.read_csv(path)
|
||||||
|
t = len(data)
|
||||||
for i, row in enumerate(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
|
continue
|
||||||
print(row)
|
|
||||||
|
|
||||||
# ~ w = ((Socios.rfc==fields['rfc']) & (Socios.slug==fields['slug']))
|
row['es_cliente'] = True
|
||||||
# ~ if Socios.select().where(w).exists():
|
row['forma_pago'] = SATFormaPago.get(SATFormaPago.id==row['forma_pago'])
|
||||||
# ~ msg = 'Ya existe el RFC y Razón Social'
|
|
||||||
# ~ data = {'ok': False, 'row': {}, 'new': True, 'msg': msg}
|
|
||||||
# ~ return data
|
|
||||||
|
|
||||||
# ~ 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
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj = Socios.create(**row)
|
||||||
|
except Exception as e:
|
||||||
|
log.error(e)
|
||||||
break
|
break
|
||||||
|
|
||||||
desconectar()
|
desconectar()
|
||||||
|
|
Loading…
Reference in New Issue