hnt-sap-nf-caixas 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: hnt_sap_nf_caixas
3
+ Version: 0.0.1
4
+ Summary: Lib to access sap gui to run transactions
5
+ Author: Pepe
6
+ License: MIT License
7
+ Keywords: nota_fiscal
8
+ Requires-Dist: python-dotenv
9
+ Requires-Dist: robotframework-sapguilibrary
10
+ Dynamic: author
11
+ Dynamic: keywords
12
+ Dynamic: license
13
+ Dynamic: requires-dist
14
+ Dynamic: summary
@@ -0,0 +1,67 @@
1
+ # hnt_sap_nf_caixas
2
+ ## Via transação J1BNFE (Monitor NF-e)
3
+ J1BNFE
4
+ ## Tipo de imposto - SAP
5
+ (ICMS linha zero NF)
6
+ (COFINS IVA SupNãoDedutImpNorm.)
7
+ (PIS IVA SupNãoDedutImpNormal)
8
+ (IPI NotaFisc Linha 0)
9
+
10
+ ## NF função parceiro
11
+ AG = Emissor de ordem
12
+ BR = Filial
13
+ LF = Fornecedor
14
+ RG = Pagador
15
+ RE = Recebedor da fatura
16
+ WE = Recebedor mercadoria
17
+ SP = Transportadora
18
+
19
+ # Requirements
20
+ Pip 24.0
21
+ Python 3.11.5
22
+ VirtualEnv
23
+
24
+ # Setup the development env unix
25
+ ```sh
26
+ virtualenv venv
27
+ . ./venv/bin/activate
28
+ ```
29
+
30
+ # Setup the development env win10
31
+ ```sh
32
+ python -m venv venv
33
+ . .\venv\Scripts\activate
34
+ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
35
+ python.exe -m pip install --upgrade pip
36
+ pip install pytest
37
+ pip install python-dotenv
38
+ pip install robotframework-sapguilibrary
39
+ copy .\.env.template .\.env
40
+ ```
41
+
42
+ # Before publish the packages
43
+ ```sh
44
+ pip install --upgrade pip
45
+ pip install --upgrade setuptools wheel
46
+ pip install twine
47
+ ```
48
+ python.exe -m pip install --upgrade pip
49
+
50
+ # How to cleanup generated files to publish
51
+ ```powershell
52
+ Remove-Item .\build\ -Force -Recurse
53
+ Remove-Item .\dist\ -Force -Recurse
54
+ Remove-Item .\hnt_sap_nf_caixas.egg-info\ -Force -Recurse
55
+ ```
56
+
57
+ # How to publish the package to test.pypi.org
58
+ ```sh
59
+ python setup.py sdist bdist_wheel
60
+ python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
61
+ ```
62
+
63
+ # How to publish the package to pypi.org (username/password see lastpass Pypi)
64
+ ```sh
65
+ python setup.py sdist bdist_wheel
66
+ python -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
67
+ ```
@@ -0,0 +1 @@
1
+ from .hnt_sap_gui import *
@@ -0,0 +1,13 @@
1
+ import logging
2
+ import re
3
+
4
+ logger = logging.getLogger(__name__)
5
+
6
+ def sbar_extracted_text(patter, full_text):
7
+ regex = re.compile(patter , re.IGNORECASE)
8
+ text_list = regex.search(full_text)
9
+ if text_list is None:
10
+ return None
11
+ text = text_list[1]
12
+ logger.info(f"Extracted text: '{text}', from full_text: '{full_text}'")
13
+ return text
@@ -0,0 +1,60 @@
1
+ from functools import wraps
2
+ import os
3
+ import logging
4
+
5
+ from hnt_sap_nf.hnt_sap_exception import HntSapException
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ def sessionable(original_function):
10
+ @wraps(original_function)
11
+ def wrapped(*args, **kwargs):
12
+ this = args[0]
13
+ try:
14
+ _open(this)
15
+ response = original_function(*args, **kwargs)
16
+ _close(this)
17
+ return response
18
+ except HntSapException as hntEx:
19
+ _close(this)
20
+ raise hntEx
21
+ except Exception as ex:
22
+ logger.error(msg=str(ex))
23
+ if this.session.findById("wnd[0]/sbar", False) != None:
24
+ msg = this.session.findById("wnd[0]/sbar").Text
25
+ logger.error(f"SAP Status bar: '{msg}'")
26
+ raise HntSapException(msg, ex.args)
27
+
28
+ if isinstance(ex.args[0], str) and ex.args[0].endswith("object has no attribute 'sapapp'"):
29
+ raise ex
30
+ _close(this)
31
+ return wrapped
32
+
33
+ def _open(sap_gui):
34
+ logger.info("enter _open")
35
+ sap_gui.connect_to_session()
36
+
37
+ sap_gui.open_connection(os.getenv("SAP_FIN_OPEN_CONNECTION"))
38
+
39
+ sap_gui.session.findById("wnd[0]/usr/txtRSYST-MANDT").text = os.getenv("SAP_FIN_MANDANTE")
40
+ sap_gui.session.findById("wnd[0]/usr/txtRSYST-BNAME").text = os.getenv("SAP_FIN_USERNAME")
41
+ sap_gui.session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = os.getenv("SAP_FIN_PASSWORD")
42
+ sap_gui.session.findById("wnd[0]/usr/txtRSYST-LANGU").text = os.getenv("SAP_FIN_LANGUAGE")
43
+ sap_gui.send_vkey(0)
44
+ if sap_gui.session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2", False) != None:
45
+ sap_gui.session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").select()
46
+ sap_gui.session.findById("wnd[1]/tbar[0]/btn[0]").press()
47
+ if sap_gui.session.findById("wnd[1]/tbar[0]/btn[0]", False) != None:
48
+ sap_gui.session.findById("wnd[1]/tbar[0]/btn[0]").press()
49
+ elif sap_gui.session.findById("wnd[1]/tbar[0]/btn[0]", False) != None:
50
+ sap_gui.session.findById("wnd[1]/tbar[0]/btn[0]").press()
51
+ logger.info("leave _open")
52
+
53
+ def _close(sap_gui):
54
+ logger.info("enter _close")
55
+ sap_gui.session.findById("wnd[0]").close()
56
+ if sap_gui.session.findById("wnd[1]/usr/btnSPOP-OPTION1", False) != None:
57
+ sap_gui.session.findById("wnd[1]/usr/btnSPOP-OPTION1").press()
58
+ elif sap_gui.session.findById("wnd[2]/usr/btnSPOP-OPTION1", False) != None:
59
+ sap_gui.session.findById("wnd[2]/usr/btnSPOP-OPTION1").press()
60
+ logger.info("leave _close")
@@ -0,0 +1,18 @@
1
+ from datetime import datetime
2
+
3
+
4
+ class TxResult:
5
+ def __init__(self, sap_docnum, sbar=None) -> None:
6
+ self.sap_docnum = sap_docnum
7
+ self.sbar = sbar
8
+ self.created_at = datetime.now().strftime("%Y%m%d%H%M%S")
9
+
10
+ def to_dict(self):
11
+ return {
12
+ 'sap_docnum': self.sap_docnum,
13
+ 'sbar': self.sbar,
14
+ 'created_at': self.created_at,
15
+ }
16
+
17
+ def __str__(self):
18
+ return f"TxResult instance with sap_docnum: '{self.sap_docnum}', sbar: '{self.sbar}', created_at:'{self.created_at}'"
@@ -0,0 +1,13 @@
1
+ class HntSapException(Exception):
2
+ def __init__(self, message, cause=None):
3
+ self.message = message
4
+ self.cause = cause
5
+
6
+ def __str__(self):
7
+ if self.cause:
8
+ return f'HFNTException: {self.message} caused by {self.cause}'
9
+ else:
10
+ return f'HFNTException: {self.message}'
11
+
12
+ def __cause__(self):
13
+ return self.cause
@@ -0,0 +1,43 @@
1
+ import logging
2
+ import locale
3
+ import time
4
+ from SapGuiLibrary import SapGuiLibrary
5
+
6
+ from hnt_sap_nf.common.tx_result import TxResult
7
+ from hnt_sap_nf.j1b1n_transaction import J1b1nTransaction
8
+ from .common.session import sessionable
9
+ from dotenv import load_dotenv
10
+ logger = logging.getLogger(__name__)
11
+
12
+ class SapGui(SapGuiLibrary):
13
+ def __init__(self) -> None:
14
+ SapGuiLibrary.__init__(self, screenshots_on_error=True)
15
+ locale.setlocale(locale.LC_ALL, ('pt_BR.UTF-8'))
16
+ load_dotenv()
17
+ pass
18
+ def format_float(self, value):
19
+ return locale.format_string("%.2f", value)
20
+
21
+ @sessionable
22
+ def run_j1b1n(self, nf):
23
+ logger.info(f"Enter execute run_j1b1n nf:{nf}")
24
+ result = {
25
+ "j1b1n": None,
26
+ "error": None
27
+ }
28
+ try:
29
+ j1b1n = J1b1nTransaction().execute(self, nf)
30
+ result['j1b1n'] = j1b1n.to_dict()
31
+ except Exception as ex:
32
+ logger.error(str(ex))
33
+ result["error"] = str(ex)
34
+ logger.info(f"Leave execute run_j1b1n result:{', '.join([str(result[obj]) for obj in result])}")
35
+ return result
36
+
37
+ @sessionable
38
+ def run_j1b1n_mock(self, nf):
39
+ logger.info(f"Enter execute run_j1b1n_mock nf:{nf}")
40
+ epoch_now = int(time.time())
41
+ result = TxResult(str(epoch_now), 'chamada run_j1b1n_mock')
42
+ logger.info(f"Leave run_j1b1n_mock:{result}")
43
+ return result
@@ -0,0 +1,82 @@
1
+ import logging
2
+ from hnt_sap_nf.common.tx_result import TxResult
3
+ logger = logging.getLogger(__name__)
4
+ from hnt_sap_nf.common.sap_status_bar import sbar_extracted_text
5
+ MSG_SAP_NOTA_FISCAL_CRIADA = "^Nota fiscal ([0-9]+) criada$"
6
+ IMPOSTOS = [
7
+ 'ICM0',
8
+ 'ICON',
9
+ 'IPSN',
10
+ 'IPI0'
11
+ ]
12
+ class J1b1nTransaction:
13
+ def __init__(self) -> None:
14
+ pass
15
+
16
+ def execute(self, sapGuiLib, nf):
17
+ logger.info(f"Enter lançar nf:{nf}")
18
+ sapGuiLib.run_transaction('/nJ1B1N')
19
+
20
+ sapGuiLib.session.findById("wnd[0]/usr/ctxtJ_1BDYDOC-NFTYPE").Text = nf['categoria_nf'] #Planilha: Cat NF | SAP: Ctg.nota fiscal
21
+ sapGuiLib.session.findById("wnd[0]/usr/ctxtJ_1BDYDOC-BUKRS").Text = nf['empresa'] #Planilha: Empresa | SAP: Empresa
22
+ sapGuiLib.session.findById("wnd[0]/usr/ctxtJ_1BDYDOC-BRANCH").Text = nf['local_negocio'] #Planilha: Unidade | SAP: Local de negócios
23
+ sapGuiLib.session.findById("wnd[0]/usr/cmbJ_1BDYDOC-PARVW").Key = nf['funcao_parceiro'] #SAP: NF função parceiro*
24
+ sapGuiLib.session.findById("wnd[0]/usr/ctxtJ_1BDYDOC-PARID").Text = nf['sap_cod_fornecedor'] #Planilha: Código Fornecedor | SAP: ID parceiro
25
+
26
+ sapGuiLib.send_vkey(0)
27
+ if nf['categoria_nf'] == 'YS':
28
+ sapGuiLib.session.findById("wnd[0]/usr/subNF_NUMBER:SAPLJ1BB2:2002/txtJ_1BDYDOC-NFENUM").Text = nf['nro_nf'] #Planilha: Nº NF | SAP: Nº da NF-e
29
+ sapGuiLib.session.findById("wnd[0]/usr/txtJ_1BDYDOC-SERIES").Text = nf['serie_nf'] # Série NF Planilha: Nº Série | SAP: Nº da NF-e (campo 2)
30
+ sapGuiLib.session.findById("wnd[0]/usr/ctxtJ_1BDYDOC-DOCDAT").Text = nf['data_emissao'] #Planilha: Data emissão | SAP: Data documento
31
+ elif nf['categoria_nf'] == 'YZ':
32
+ sapGuiLib.session.findById("wnd[0]/usr/ctxtJ_1BDYDOC-DOCDAT").Text = nf['data_corrente'] #Data corrente, ex. 10.12.2025
33
+
34
+ #------------------------------------------------------------------------------------------------
35
+ #INCLUSÃO DE MATERIAIS
36
+ for i, item in enumerate(nf['itens']):
37
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/ctxtJ_1BDYLIN-ITMTYP[1,{i}]").Text = item['tipo'] #Planilha: Tipo item NF | SAP: Tipo de item NF
38
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/ctxtJ_1BDYLIN-MATNR[3,{i}]").Text = item['cod_material_sap'] #Planilha: Código Material | SAP: Material
39
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/ctxtJ_1BDYLIN-WERKS[2,{i}]").Text = item['centro'] #Planilha: CD | SAP: Centro
40
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/txtJ_1BDYLIN-MENGE[4,{i}]").Text = item['quantidade'] #Planilha: Quantidade | SAP: Quantidade
41
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/ctxtJ_1BDYLIN-MEINS[5,{i}]").Text = item['unidade_medida'] #Planilha: Un Med | SAP: Unidade de medida
42
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/txtJ_1BDYLIN-NETPR[6,{i}]").Text = sapGuiLib.format_float(item['preco']) #Planilha: Valor UN | SAP: Preço
43
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/ctxtJ_1BDYLIN-CFOP[9,{i}]").Text = item['cfop'] #Planilha: CFOP Entrada | SAP: CFOP
44
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/tblSAPLJ1BB2ITEM_CONTROL/ctxtJ_1BDYLIN-TAXLW1[10,{i}]").Text = item['dir_fiscal'] #Planilha: Dir Fiscal | SAP: Dir.fisc.: ICMS
45
+ sapGuiLib.send_vkey(0)
46
+ sapGuiLib.send_vkey(0)
47
+
48
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/btn%#AUTOTEXT004").press() #Botão "Selecionar tudo"
49
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB1/ssubHEADER_TAB:SAPLJ1BB2:2100/btn%#AUTOTEXT001").press() #Botão "DetalhItem"
50
+ sapGuiLib.session.findById("wnd[0]/usr/tabsITEM_TAB/tabpTAX").Select() #Seleciona aba Impsotos
51
+ for i, item in enumerate(nf['itens']):
52
+ for i, imposto in enumerate(IMPOSTOS):
53
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsITEM_TAB/tabpTAX/ssubITEM_TABS:SAPLJ1BB2:3200/tblSAPLJ1BB2TAX_CONTROL/ctxtJ_1BDYSTX-TAXTYP[0,{i}]").Text = imposto
54
+ sapGuiLib.session.findById(f"wnd[0]/usr/tabsITEM_TAB/tabpTAX/ssubITEM_TABS:SAPLJ1BB2:3200/tblSAPLJ1BB2TAX_CONTROL/txtJ_1BDYSTX-OTHBAS[7,{i}]").Text = sapGuiLib.format_float(item['valor_produto'])
55
+
56
+ sapGuiLib.session.findById("wnd[0]/usr/tabsITEM_TAB/tabpTAX/ssubITEM_TABS:SAPLJ1BB2:3200/btnPB_NEXT").press()
57
+
58
+ sapGuiLib.send_vkey(0)
59
+ sapGuiLib.session.findById("wnd[0]/tbar[0]/btn[3]").press()
60
+
61
+ if nf['categoria_nf'] == 'YS':
62
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8").Select() #Seleciona aba DadosNF-e
63
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubHEADER_TAB:SAPLJ1BB2:2800/subRANDOM_NUMBER:SAPLJ1BB2:2801/ctxtJ_1BNFE_DOCNUM9_DIVIDED-TPEMIS").Text = nf['dados_nfe']['tipo_emissao'] #Planilha: Tipo de emissão | SAP: Tp.emissão
64
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubHEADER_TAB:SAPLJ1BB2:2800/subRANDOM_NUMBER:SAPLJ1BB2:2801/txtJ_1BNFE_DOCNUM9_DIVIDED-DOCNUM8").Text = nf['dados_nfe']['nro_aleatorio'] #Planilha: Nº aleatorio | SAP: Nº aleatório
65
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubHEADER_TAB:SAPLJ1BB2:2800/subRANDOM_NUMBER:SAPLJ1BB2:2801/txtJ_1BNFE_ACTIVE-CDV").Text = nf['dados_nfe']['digito_verificador'] #Planilha: Dig verificador | SAP: Díg.verif.
66
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubHEADER_TAB:SAPLJ1BB2:2800/subTIMESTAMP:SAPLJ1BB2:2803/subAUTHCODE_AREA:SAPLJ1BB2:2805/txtJ_1BDYDOC-AUTHCOD").Text = nf['dados_nfe']['nro_log'] #Planilha: Numero Doc | SAP: Nº do log
67
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubHEADER_TAB:SAPLJ1BB2:2800/subTIMESTAMP:SAPLJ1BB2:2803/ctxtJ_1BDYDOC-AUTHDATE").Text = nf['dados_nfe']['data_emissao'] #Planilha: Data emissão | SAP: Hora procmto.
68
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubHEADER_TAB:SAPLJ1BB2:2800/subTIMESTAMP:SAPLJ1BB2:2803/ctxtJ_1BDYDOC-AUTHTIME").Text = nf['dados_nfe']['hora_emissao'] # Planilha: Hora de emissão | SAP: Hora procmto.
69
+ elif nf['categoria_nf'] == 'YZ':
70
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB4").Select() #Seleciona aba Mensagens
71
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB4/ssubHEADER_TAB:SAPLJ1BB2:2400/tblSAPLJ1BB2MESSAGE_CONTROL/txtJ_1BDYFTX-MESSAGE[0,2]").Text = f"NOTA DE PRODUTOR {nf['nro_nf']}-{nf['serie_nf']}"
72
+ sapGuiLib.send_vkey(0)
73
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB5").Select() #Seleciona aba Transporte
74
+ sapGuiLib.session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB5/ssubHEADER_TAB:SAPLJ1BB2:2500/ctxtJ_1BDYDOC-MODFRETE").Text = nf['dados_nfe']['modalid_fret'] #SAP: Modalid.fret
75
+
76
+ sapGuiLib.send_vkey(0)
77
+ sapGuiLib.session.findById("wnd[0]/tbar[0]/btn[11]").press() #Salvar
78
+ sbar = sapGuiLib.session.findById("wnd[0]/sbar").Text
79
+ sap_docnum = sbar_extracted_text(MSG_SAP_NOTA_FISCAL_CRIADA, sbar)
80
+ result = TxResult(sap_docnum, sbar)
81
+ logger.info(f"Leave lançar nf:{result}")
82
+ return result
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: hnt_sap_nf_caixas
3
+ Version: 0.0.1
4
+ Summary: Lib to access sap gui to run transactions
5
+ Author: Pepe
6
+ License: MIT License
7
+ Keywords: nota_fiscal
8
+ Requires-Dist: python-dotenv
9
+ Requires-Dist: robotframework-sapguilibrary
10
+ Dynamic: author
11
+ Dynamic: keywords
12
+ Dynamic: license
13
+ Dynamic: requires-dist
14
+ Dynamic: summary
@@ -0,0 +1,16 @@
1
+ README.md
2
+ setup.py
3
+ hnt_sap_nf/__init__.py
4
+ hnt_sap_nf/hnt_sap_exception.py
5
+ hnt_sap_nf/hnt_sap_gui.py
6
+ hnt_sap_nf/j1b1n_transaction.py
7
+ hnt_sap_nf/common/sap_status_bar.py
8
+ hnt_sap_nf/common/session.py
9
+ hnt_sap_nf/common/tx_result.py
10
+ hnt_sap_nf_caixas.egg-info/PKG-INFO
11
+ hnt_sap_nf_caixas.egg-info/SOURCES.txt
12
+ hnt_sap_nf_caixas.egg-info/dependency_links.txt
13
+ hnt_sap_nf_caixas.egg-info/requires.txt
14
+ hnt_sap_nf_caixas.egg-info/top_level.txt
15
+ tests/test_j1b1n.py
16
+ tests/test_j1b1n_transaction.py
@@ -0,0 +1,2 @@
1
+ python-dotenv
2
+ robotframework-sapguilibrary
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,14 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(name='hnt_sap_nf_caixas',
4
+ version='0.0.1',
5
+ license='MIT License',
6
+ author='Pepe',
7
+ keywords='nota_fiscal',
8
+ description=u'Lib to access sap gui to run transactions',
9
+ packages=find_packages(),
10
+ package_data={'hnt_sap_nf': ['common/*']},
11
+ install_requires=[
12
+ 'python-dotenv',
13
+ 'robotframework-sapguilibrary',
14
+ ])
@@ -0,0 +1,33 @@
1
+ import json
2
+ from hnt_sap_nf.hnt_sap_gui import SapGui
3
+
4
+
5
+ def test_create():
6
+ with open("./devdata/json/nf_caixas_GHN-68955.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
7
+ nf = payload['payloads'][0]['nf_caixas']
8
+ result = SapGui().run_j1b1n(nf)
9
+
10
+ assert result['error'] is None
11
+
12
+ def test_create_chave_acesso():
13
+ with open("./devdata/json/sap_nf_35251296669288000160550010006831461561796697.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
14
+ result = SapGui().run_j1b1n(payload)
15
+
16
+ with open("./devdata/json/sap_nf_31251200015861804877559220001443241320827677.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
17
+ with open("./devdata/json/sap_nf_35251200988809000335550010001651121840350907.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
18
+ with open("./devdata/json/sap_nf_35251205258070000168550010004132661080163793.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
19
+ with open("./devdata/json/sap_nf_35251205602272000185550020001438521235812151.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
20
+ with open("./devdata/json/sap_nf_35251208066591001698550010000171511340852410.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
21
+ with open("./devdata/json/sap_nf_35251208365506000106550010001262411065725349.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
22
+ with open("./devdata/json/sap_nf_35251208373288000151550010000136701122387540.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
23
+ with open("./devdata/json/sap_nf_35251210971350000159550010005726011000773077.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
24
+ with open("./devdata/json/sap_nf_35251211981319000161550010000153121072594075.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
25
+ with open("./devdata/json/sap_nf_35251221938705000124550140000199981001391927.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
26
+ with open("./devdata/json/sap_nf_35251226240336000115550010002870451299328855.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
27
+ with open("./devdata/json/sap_nf_35251235639330000106550010000529851001623777.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
28
+ with open("./devdata/json/sap_nf_35251237969285000183550020000029381094569980.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
29
+ with open("./devdata/json/sap_nf_35251250983733000161550010006907971246388892.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
30
+ with open("./devdata/json/sap_nf_35251254549340000103550010001953431072177460.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
31
+ with open("./devdata/json/sap_nf_35251255746019000173550010000136521051806942.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
32
+ with open("./devdata/json/sap_nf_35251255825811000113550010000188791883017856.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
33
+ with open("./devdata/json/sap_nf_35251267109710000206550010002775761413632824.json", "r", encoding="utf-8") as payload_json: payload = json.load(payload_json)
@@ -0,0 +1,34 @@
1
+ import json
2
+ from hnt_sap_nf.hnt_sap_gui import SapGui
3
+
4
+ class TestJ1b1nTransaction:
5
+ def setup_method(self, method):
6
+ with open(f"./devdata/json/{method.__name__}.json", "r", encoding="utf-8") as arquivo_json: nf = json.load(arquivo_json)
7
+ self.nf = nf
8
+ self.saved_record = None
9
+ self.error_record = None
10
+
11
+ def test_sap_nf_31251200015861804877559220001443241320827677(self):
12
+ if self.nf is not None:
13
+ result = SapGui().run_j1b1n(self.nf)
14
+ self.saved_record = result.get('j1b1n')
15
+ self.error_record = result.get('error')
16
+ assert self.saved_record is not None
17
+ def test_sap_nf_35251200988809000335550010001651121840350907(self):
18
+ if self.nf is not None:
19
+ result = SapGui().run_j1b1n(self.nf)
20
+ self.saved_record = result.get('j1b1n')
21
+ self.error_record = result.get('error')
22
+ assert self.saved_record is not None
23
+ def test_j1b1n_mock(self):
24
+ if self.nf is not None:
25
+ result = SapGui().run_j1b1n_mock(self.nf)
26
+ assert result.sbar == 'chamada run_j1b1n_mock'
27
+ def teardown_method(self, method):
28
+ if self.saved_record is not None:
29
+ with open(f"./output/json/saved_{method.__name__}.json", "w", encoding="utf-8") as json_file:
30
+ json.dump( self.saved_record, json_file, ensure_ascii=False, indent=4)
31
+ if self.error_record is not None:
32
+ with open(f"./output/json/error_{method.__name__}.json", "w", encoding="utf-8") as json_file:
33
+ json.dump( self.error_record, json_file, ensure_ascii=False, indent=4)
34
+