Skip to content

Conversation

Isaacvf-dev
Copy link
Collaborator

  • Adicionado valores padrões dos dados já presentes no script env.txt
    Foi necessário adicionar as seguintes funções
def default_year():
    with open("env.txt", "r") as configFile:
        content = configFile.readlines()
        yearInFile = [i for i in content if "year =" in i]
        return yearInFile[0][7:-1]


def default_month():
    with open("env.txt", "r") as configfile:
        lines = configfile.readlines()
        monthInFile = [i for i in lines if "month =" in i][0]
        month_num = int(monthInFile.split('=')[1].strip())
        months = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro',
                  'Novembro', 'Dezembro']
        return months[month_num - 1]
  • Adicionados default values para sg.combo de mês e ano e default text para cnpj
    Obs: Ao clicar em configurações, só é possível desabilitar Salvar caso apagado um número e escrito novamente (caso número do cnpj venha automaticamente de env)

Obs: Generate Das está apresentando erro na função getYear()

line 69, in getYear
return int(yearInFile[0][7:-1])
^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''

@Isaacvf-dev Isaacvf-dev self-assigned this Apr 27, 2023
@lostcode-dev
Copy link
Owner

lostcode-dev commented Apr 27, 2023

  • [sg.Button ( "Salvar", key="-SAVE-", disabled=True )]

É possível verificar com o getCnpj() se já tem os 14 caracteres, e deixar o botão habilitado ou desabilitado.

Se getCnpg() == 14 caracteres
      btn_disabled = False
Se não
      btn_disabled = True
[sg.Button ( "Salvar", key="-SAVE-", disabled=btn_disabled )]

pages/config.py Outdated
from helpers.utils import getCnpj

def default_year():
with open("env.txt", "r") as configFile:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em helpers.utils já existe uma função que lê o arquivo e retorna o ano.
Então o adequado seria utilizar essa função que já supri a necessidade.

Razões:

  • Eficiência e economia de tempo
  • Manutenção simplificada
  • Legibilidade e organização do código

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentei essa opção, mas não consegui fazer funcionar. Da forma como a função está lá em utils, não dá certo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foi corrigido conforme solicitado



def default_month():
with open("env.txt", "r") as configfile:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m helpers.utils já existe uma função que lê o arquivo e retorna o mês que está no arquivo.
Então o adequado seria utilizar essa função que já supri a necessidade.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A função retorna um int mas precisamos de um string com o nome do mês
def getMonth():
with open("env.txt", "r") as configFile:
content = configFile.readlines()
monthInFile = [i for i in content if "month =" in i][0]
containsData = monthInFile[8:-1] != ''

    if containsData and int(monthInFile[8:-1]) > 0:
        return int(monthInFile[8:-1])
    else:
        return 0

Por isso o uso da nova função
def default_month():
with open("env.txt", "r") as configfile:
lines = configfile.readlines()
monthInFile = [i for i in lines if "month =" in i][0]
month_num = int(monthInFile.split('=')[1].strip())
months = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro',
'Novembro', 'Dezembro']
return months[month_num - 1]

Verificar uma forma de a função inicial servir para os dois propósitos?

@lostcode-dev
Copy link
Owner

Referente a este erro:

line 69, in getYear
return int(yearInFile[0][7:-1])
^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''

Altera para mim e deixa "return int(yearInFile[7:-1])", acredito que isto já vai resolver.

@Isaacvf-dev
Copy link
Collaborator Author

Isaacvf-dev commented Apr 29, 2023

O botão save estava ficando desabilitado apenas 1 vez. O programa não estava reconhecendo caso o usuário digitasse novamente um comprimento do CNPJ de 14 caracteres.
Antes:

if len(getCnpj()) == 14:
      btn_disabled = False
  if len(getCnpj()) < 14:
      btn_disabled = True
     [sg.Button ( "Salvar", key="-SAVE-", disabled= btn_disabled)],

Depois:

if event == "-CNPJ-":
            if len(values["-CNPJ-"]) == 14:
                window['-SAVE-'].update(disabled=False)
            if len(values["-CNPJ-"]) < 14:
                window['-SAVE-'].update(disabled=True)

A variável, repetida em default_month() e returnMonth(month=None) foi colocada no inicio do script config, sendo agora repetida apenas 1 vez.

@lostcode-dev lostcode-dev merged commit 6afc6d0 into development May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants