diff --git a/.gitignore b/.gitignore index 378a19a..1041dd9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,35 @@ -# Byte-compiled / optimized / DLL files +# Created by https://www.toptal.com/developers/gitignore/api/python,jupyternotebooks,pycharm,flask,django,visualstudiocode,venv,dotenv,linux,windows,emacs,database,powershell +# Edit at https://www.toptal.com/developers/gitignore?templates=python,jupyternotebooks,pycharm,flask,django,visualstudiocode,venv,dotenv,linux,windows,emacs,database,powershell + +### Database ### +*.accdb +*.db +*.dbf +*.mdb +*.pdb +*.sqlite3 +*.db-shm +*.db-wal + +### Django ### +*.log +*.pot +*.pyc __pycache__/ +local_settings.py +db.sqlite3 +db.sqlite3-journal +media +__idea__ +__cache__ +__pycache__ +.idea +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files *.py[cod] *$py.class @@ -20,7 +50,6 @@ parts/ sdist/ var/ wheels/ -pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg @@ -50,16 +79,12 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo -*.pot # Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal # Flask stuff: instance/ @@ -72,6 +97,7 @@ instance/ docs/_build/ # PyBuilder +.pybuilder/ target/ # Jupyter Notebook @@ -82,6 +108,8 @@ profile_default/ ipython_config.py # pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: .python-version # pipenv @@ -89,9 +117,24 @@ ipython_config.py # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. -#Pipfile.lock +Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +poetry.lock -# PEP 582; used by e.g. github.com/David-OConnor/pyflow +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ # Celery stuff @@ -104,8 +147,8 @@ celerybeat.pid # Environments .env .venv -venv/ env/ +venv/ ENV/ env.bak/ venv.bak/ @@ -127,3 +170,450 @@ dmypy.json # Pyre type checker .pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### dotenv ### + +### Emacs ### +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + + +### Flask ### +instance/* +!instance/.gitignore + +### Flask.Python Stack ### +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm + +# Celery stuff + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# pytype static type analyzer + +# Cython debug symbols + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. + +### JupyterNotebooks ### +# gitignore template for Jupyter Notebooks +# website: http://jupyter.org/ + +*/.ipynb_checkpoints/* + +# IPython + +# Remove previous ipynb_checkpoints +# git rm -r .ipynb_checkpoints/ + +### Linux ### + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### PowerShell ### +# Exclude packaged modules +*.zip + +# Exclude .NET assemblies from source +*.dll + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Python ### +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm + +# Celery stuff + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# pytype static type analyzer + +# Cython debug symbols + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +### venv ### +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +pip-selfcheck.json + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/python,jupyternotebooks,pycharm,flask,django,visualstudiocode,venv,dotenv,linux,windows,emacs,database,powershell \ No newline at end of file diff --git a/omie.py b/omie.py index 1e70e5b..601d2f8 100644 --- a/omie.py +++ b/omie.py @@ -3,9 +3,9 @@ from datetime import date from dotenv import load_dotenv + class Omie: def __init__(self, empresa): - self.AlterarPrecoItem = OmieAlterarPrecoItem(empresa) self.AlterarProduto = OmieAlterarProduto(empresa) self.ConsultarCliente = OmieConsultarCliente(empresa) @@ -25,6 +25,137 @@ def __init__(self, empresa): self.ListarTabelasPreco = OmieListarTabelasPreco(empresa) self.ListarVendedores = OmieListarVendedores(empresa) self.ObterAnexo = OmieObterAnexo(empresa) + self.ListarProjetos = OmieListarProjetos(empresa) + self.ListarRecebimentos = OmieListarRecebimentos(empresa) + self.ListarProdutoFornecedor = OmieListarProdutoFornecedor(empresa) + self.ListarNotaEnt = OmieListarNotaEnt(empresa) + self.OmieListarNF = OmieListarNF(empresa) + + +class OmieListarNF: + def __init__(self, empresa): + self.empresa = empresa + self.caminho = "produtos/nfconsultar/" + self.call = 'ListarNF' + self.Pagina = 1 + self.registros_por_pagina = 50 + + def executar(self): + return OmieApi().executar(self, self.empresa) + + def todos(self): + nome_lista_omie = "nfCadastro" + self.registros_por_pagina = 500 + consulta = self.executar() + total_de_paginas = consulta['total_de_paginas'] + lista = consulta[nome_lista_omie] + while self.pagina < total_de_paginas: + self.pagina += 1 + registros = self.executar()[nome_lista_omie] + for registro in registros: + lista.append(registro) + return lista + + +class OmieListarNotaEnt: + def __init__(self, empresa): + self.empresa = empresa + self.caminho = "produtos/notaentrada/" + self.call = 'ListarNotaEnt' + self.nPagina = 1 + self.nRegistrosPorPagina = 50 + + def executar(self): + return OmieApi().executar(self, self.empresa) + + def todos(self): + nome_lista_omie = "notas" + self.registros_por_pagina = 500 + consulta = self.executar() + total_de_paginas = consulta['nTotalPaginas'] + lista = consulta[nome_lista_omie] + while self.pagina < total_de_paginas: + self.pagina += 1 + registros = self.executar()[nome_lista_omie] + for registro in registros: + lista.append(registro) + return lista + + +class OmieListarProdutoFornecedor: + def __init__(self, empresa): + self.empresa = empresa + self.caminho = "estoque/produtofornecedor/" + self.call = 'ListarProdutoFornecedor' + self.pagina = 1 + self.registros_por_pagina = 50 + + def executar(self): + return OmieApi().executar(self, self.empresa) + + def todos(self): + nome_lista_omie = "cadastros" + self.registros_por_pagina = 500 + consulta = self.executar() + total_de_paginas = consulta['total_de_paginas'] + lista = consulta[nome_lista_omie] + while self.pagina < total_de_paginas: + self.pagina += 1 + registros = self.executar()[nome_lista_omie] + for registro in registros: + lista.append(registro) + return lista + + +class OmieListarRecebimentos: + def __init__(self, empresa): + self.empresa = empresa + self.caminho = "produtos/recebimentonfe/" + self.call = 'ListarRecebimentos' + self.nPagina = 1 + self.nRegistrosPorPagina = 50 + + def executar(self): + return OmieApi().executar(self, self.empresa) + + def todos(self): + nome_lista_omie = "recebimentos" + self.registros_por_pagina = 500 + consulta = self.executar() + total_de_paginas = consulta['nTotalPaginas'] + lista = consulta[nome_lista_omie] + while self.pagina < total_de_paginas: + self.pagina += 1 + registros = self.executar()[nome_lista_omie] + for registro in registros: + lista.append(registro) + return lista + + +class OmieListarProjetos: + def __init__(self, empresa): + self.empresa = empresa + self.caminho = "geral/projetos/" + self.call = 'ListarProjetos' + self.pagina = 1 + self.registros_por_pagina = 50 + + def executar(self): + return OmieApi().executar(self, self.empresa) + + def todos(self): + nome_lista_omie = "" + self.registros_por_pagina = 500 + consulta = self.executar() + total_de_paginas = consulta['total_de_paginas'] + lista = consulta[nome_lista_omie] + while self.pagina < total_de_paginas: + self.pagina += 1 + registros = self.executar()[nome_lista_omie] + for registro in registros: + lista.append(registro) + return lista + class OmieAlterarPrecoItem: def __init__(self, empresa): @@ -35,8 +166,9 @@ def __init__(self, empresa): self.nCodProd = 0 self.nValorTabela = 0 - def executar(self, console = True): - return OmieApi().executar(self, self.empresa, console = console) + def executar(self, console=True): + return OmieApi().executar(self, self.empresa, console=console) + class OmieAlterarProduto: def __init__(self, empresa): @@ -45,8 +177,9 @@ def __init__(self, empresa): self.call = "AlterarProduto" self.codigo_produto = 0 - def executar(self, console = True): - return OmieApi().executar(self, self.empresa, console = console) + def executar(self, console=True): + return OmieApi().executar(self, self.empresa, console=console) + class OmieConsultarCliente: def __init__(self, empresa): @@ -57,7 +190,8 @@ def __init__(self, empresa): self.codigo_cliente_integracao = "" def executar(self): - return OmieApi().executar(self, self.empresa) + return OmieApi().executar(self, self.empresa) + class OmieConsultarPedido: def __init__(self, empresa): @@ -69,6 +203,7 @@ def __init__(self, empresa): def executar(self): return OmieApi().executar(self, self.empresa) + class OmieConsultarVendedor: def __init__(self, empresa): self.empresa = empresa @@ -78,8 +213,9 @@ def __init__(self, empresa): self.codInt = "" def executar(self): - return OmieApi().executar(self, self.empresa) - + return OmieApi().executar(self, self.empresa) + + class OmieListarAnexo: def __init__(self, empresa): self.empresa = empresa @@ -90,8 +226,9 @@ def __init__(self, empresa): self.nId = 0 self.cTabela = "" - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) + class OmieListarCenarios: def __init__(self, empresa): @@ -102,7 +239,8 @@ def __init__(self, empresa): self.nRegPorPagina = 20 def executar(self): - return OmieApi().executar(self, self.empresa) + return OmieApi().executar(self, self.empresa) + class OmieListarClientes: def __init__(self, empresa): @@ -113,7 +251,7 @@ def __init__(self, empresa): self.registros_por_pagina = 50 def executar(self): - return OmieApi().executar(self, self.empresa) + return OmieApi().executar(self, self.empresa) def todos(self): nome_lista_omie = "clientes_cadastro" @@ -127,7 +265,8 @@ def todos(self): for registro in registros: lista.append(registro) return lista - + + class OmieListarContasPagar: def __init__(self, empresa): self.empresa = empresa @@ -137,8 +276,8 @@ def __init__(self, empresa): self.registros_por_pagina = 20 def executar(self): - return OmieApi().executar(self, self.empresa) - + return OmieApi().executar(self, self.empresa) + def todos(self): nome_lista_omie = "conta_pagar_cadastro" self.registros_por_pagina = 500 @@ -151,7 +290,8 @@ def todos(self): for registro in registros: lista.append(registro) return lista - + + class OmieListarContasReceber: def __init__(self, empresa): self.empresa = empresa @@ -162,8 +302,8 @@ def __init__(self, empresa): self.apenas_importado_api = "N" def executar(self): - return OmieApi().executar(self, self.empresa) - + return OmieApi().executar(self, self.empresa) + def todos(self): nome_lista_omie = "conta_receber_cadastro" self.registros_por_pagina = 500 @@ -177,19 +317,21 @@ def todos(self): lista.append(registro) return lista + class OmieListarImpostosCenario: def __init__(self, empresa): self.empresa = empresa self.caminho = "geral/cenarios/" self.call = 'ListarImpostosCenario' self.consumo_final = "N" - self.codigo_produto = 0 + self.codigo_produto = 0 def executar(self): self.codigo_cliente_omie = OmieApi(self.empresa).cliente_imposto() self.codigo_cenario = OmieApi(self.empresa).cenario_imposto() return OmieApi().executar(self, self.empresa) + class OmieListarLocaisEstoque: def __init__(self, empresa): self.empresa = empresa @@ -199,8 +341,9 @@ def __init__(self, empresa): self.nRegPorPagina = 20 def executar(self): - return OmieApi().executar(self, self.empresa) - + return OmieApi().executar(self, self.empresa) + + class OmieListarPedidos: def __init__(self, empresa): self.empresa = empresa @@ -210,22 +353,23 @@ def __init__(self, empresa): self.registros_por_pagina = 100 self.apenas_importado_api = "N" - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) - - def todos(self, console = False): + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) + + def todos(self, console=False): nome_lista_omie = "pedido_venda_produto" self.registros_por_pagina = 500 - consulta = self.executar(console = console) + consulta = self.executar(console=console) total_de_paginas = consulta['total_de_paginas'] lista = consulta[nome_lista_omie] while self.pagina < total_de_paginas: self.pagina += 1 - lista_pagina = self.executar(console = console)[nome_lista_omie] + lista_pagina = self.executar(console=console)[nome_lista_omie] for ind in lista_pagina: lista.append(ind) return lista + class OmieListarPosEstoque: def __init__(self, empresa): self.empresa = empresa @@ -237,13 +381,13 @@ def __init__(self, empresa): self.cExibeTodos = "N" self.codigo_local_estoque = OmieApi(empresa).local_de_estoque() - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) - def todos(self, console = False): + def todos(self, console=False): nome_lista_omie = "produtos" self.nRegPorPagina = 500 - consulta = self.executar(console = console) + consulta = self.executar(console=console) total_de_paginas = consulta['nTotPaginas'] lista = consulta[nome_lista_omie] while self.nPagina < total_de_paginas: @@ -253,6 +397,7 @@ def todos(self, console = False): lista.append(produto) return lista + class OmieListarProdutos: def __init__(self, empresa): self.empresa = empresa @@ -263,22 +408,23 @@ def __init__(self, empresa): self.apenas_importado_api = 'N' self.filtrar_apenas_omiepdv = 'N' - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) - def todos(self, console = False): + def todos(self, console=False): nome_lista_omie = "produto_servico_cadastro" self.registros_por_pagina = 500 - consulta = self.executar(console = console) + consulta = self.executar(console=console) total_de_paginas = consulta['total_de_paginas'] lista = consulta[nome_lista_omie] while self.pagina < total_de_paginas: self.pagina += 1 - produtos = self.executar(console = console)[nome_lista_omie] + produtos = self.executar(console=console)[nome_lista_omie] for produto in produtos: lista.append(produto) return lista + class OmieListarTabelaItens: def __init__(self, empresa): self.empresa = empresa @@ -288,10 +434,10 @@ def __init__(self, empresa): self.nRegPorPagina = 20 self.nCodTabPreco = 0 - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) - def todos(self, console = False): + def todos(self, console=False): nome_lista_omie = "listaTabelaPreco" self.nRegPorPagina = 500 consulta = self.executar() @@ -299,12 +445,13 @@ def todos(self, console = False): lista = consulta[nome_lista_omie]['itensTabela'] while self.nPagina < total_de_paginas: self.nPagina += 1 - busca = self.executar(console = console) + busca = self.executar(console=console) produtos = busca[nome_lista_omie]['itensTabela'] for produto in produtos: lista.append(produto) return lista + class OmieListarTabelasPreco: def __init__(self, empresa): self.empresa = empresa @@ -313,9 +460,10 @@ def __init__(self, empresa): self.nPagina = 1 self.nRegPorPagina = 20 - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) - + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) + + class OmieListarVendedores: def __init__(self, empresa): self.empresa = empresa @@ -325,9 +473,10 @@ def __init__(self, empresa): self.registros_por_pagina = 100 self.apenas_importado_api = "N" - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) - + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) + + class OmieObterAnexo: def __init__(self, empresa): self.empresa = empresa @@ -339,17 +488,18 @@ def __init__(self, empresa): self.nIdAnexo = 0, self.cNomeArquivo = "" - def executar(self, console = False): - return OmieApi().executar(self, self.empresa, console = console) + def executar(self, console=False): + return OmieApi().executar(self, self.empresa, console=console) + class OmieApi: - def __init__(self, empresa = ""): + def __init__(self, empresa=""): self.caminho = "" self.call = "" load_dotenv() self.empresa = empresa - def executar(self, metodo, empresa, console = False): + def executar(self, metodo, empresa, console=False): self.empresa = empresa @@ -379,13 +529,22 @@ def __converter_json(self, metodo): valor = antigo[atributo] atributo = atributo.replace("_" + classe + "__", "") atributo = atributo.replace("_" + classe + "_", "") - atributo = atributo.replace("_" + classe, "") - novo[atributo] = valor + atributo = atributo.replace("_" + classe, "") + novo[atributo] = valor return novo - def key(self): return os.getenv(self.empresa + '_KEY') - def secret(self): return os.getenv(self.empresa + '_SECRET') - def cliente_imposto(self): return os.getenv(self.empresa + '_CLIENTE_IMPOSTO') - def cenario_imposto(self): return os.getenv(self.empresa + '_CENARIO_IMPOSTO') - def local_de_estoque(self): return os.getenv(self.empresa + '_LOCAL_DE_ESTOQUE') \ No newline at end of file + def key(self): + return os.getenv(self.empresa + '_KEY') + + def secret(self): + return os.getenv(self.empresa + '_SECRET') + + def cliente_imposto(self): + return os.getenv(self.empresa + '_CLIENTE_IMPOSTO') + + def cenario_imposto(self): + return os.getenv(self.empresa + '_CENARIO_IMPOSTO') + + def local_de_estoque(self): + return os.getenv(self.empresa + '_LOCAL_DE_ESTOQUE') diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_funcoes.py b/test/test_funcoes.py new file mode 100644 index 0000000..6efd27d --- /dev/null +++ b/test/test_funcoes.py @@ -0,0 +1,20 @@ +import omie +import requests +from unittest.mock import patch +import os +from datetime import date +from dotenv import load_dotenv +import httpx + +# Mock da função requests.post para simular a chamada à API sem realmente fazer a requisição + +def test_a_resposta_do_metodo_OmieListarNF(): + consulta = omie.OmieListarNF('EmpresaTeste') + + # Chama o método executar() da instância + resposta = consulta.executar() + # Verifica se a resposta é 200 + assert isinstance(resposta,dict) + + +