Adicão da rota de despesas, agora atualizando
This commit is contained in:
parent
9aad6ff8f4
commit
e9a98424bd
2 changed files with 34 additions and 9 deletions
|
|
@ -20,18 +20,13 @@ def inserir_nota_despesas(
|
||||||
repo = NotasDespesas(conexao)
|
repo = NotasDespesas(conexao)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inseriu = repo.inserir_nota_despesas(dados_nota_holmes)
|
acao = repo.inserir_nota_despesas(dados_nota_holmes)
|
||||||
except ValueError as erro:
|
except ValueError as erro:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code= status.HTTP_422_UNPROCESSABLE_ENTITY,
|
status_code= status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||||
detail= str(erro)
|
detail= str(erro)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not inseriu:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code= status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail= "Não foi possível inserir a nota"
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
'mensagem': 'Nota inserida'
|
'mensagem': f'Nota {acao}'
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ class NotasDespesas:
|
||||||
})
|
})
|
||||||
return parcelas
|
return parcelas
|
||||||
|
|
||||||
def inserir_nota_despesas(self, nota: NotasHolmesInput) -> bool:
|
def inserir_nota_despesas(self, nota: NotasHolmesInput) -> str:
|
||||||
props = nota.properties
|
props = nota.properties
|
||||||
|
|
||||||
datas = sorted(
|
datas = sorted(
|
||||||
|
|
@ -45,6 +45,36 @@ class NotasDespesas:
|
||||||
vencimentos_json = json.dumps(self.montar_vencimentos(valor, datas))
|
vencimentos_json = json.dumps(self.montar_vencimentos(valor, datas))
|
||||||
|
|
||||||
cursor = self.conexao.cursor()
|
cursor = self.conexao.cursor()
|
||||||
|
|
||||||
|
# A mesma nota pode chegar mais de uma vez: se já existe, atualiza
|
||||||
|
cursor.execute("""
|
||||||
|
UPDATE PD_HOLMES_APOLLO
|
||||||
|
SET
|
||||||
|
EMPRESA_NOME = ?,
|
||||||
|
TIPO_DOCUMENTO = ?,
|
||||||
|
SITUACAO = ?,
|
||||||
|
NUM_NOTA = ?,
|
||||||
|
DTA_EMISSAO = ?,
|
||||||
|
VAL_NOTA = ?,
|
||||||
|
VENCIMENTOS_JSON = ?,
|
||||||
|
ORIGEM = ?
|
||||||
|
WHERE ID_HOLMES = ?
|
||||||
|
""", (
|
||||||
|
props.empresa,
|
||||||
|
props.tipo_de_documento,
|
||||||
|
props.aprovacao,
|
||||||
|
props.num_nota,
|
||||||
|
props.data_emissao,
|
||||||
|
valor,
|
||||||
|
vencimentos_json,
|
||||||
|
props.origem,
|
||||||
|
nota.id,
|
||||||
|
))
|
||||||
|
|
||||||
|
if cursor.rowcount > 0:
|
||||||
|
self.conexao.commit()
|
||||||
|
return 'atualizada'
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
INSERT INTO PD_HOLMES_APOLLO (
|
INSERT INTO PD_HOLMES_APOLLO (
|
||||||
ID_HOLMES,
|
ID_HOLMES,
|
||||||
|
|
@ -72,4 +102,4 @@ class NotasDespesas:
|
||||||
))
|
))
|
||||||
|
|
||||||
self.conexao.commit()
|
self.conexao.commit()
|
||||||
return cursor.rowcount > 0
|
return 'inserida'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue