Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1348 Vistas

Hi, im really new in this. I was trying to configurate the payroll app, and when i want to generate a pay, his appears.

I let you the code here:

def find_index(x, rates):

    measures = {

        'uma': payslip._rule_parameter('l10n_mx_uma'),

        'mdw': payslip._rule_parameter('l10n_mx_daily_min_wage'),

        'inf': float('inf'),

    }


    for ind, (low_num, low_measure, high_num, high_measure) in enumerate(rates):

        if low_num * measures[low_measure] <= x <= high_num * measures[high_measure]:

            return ind


    # Si no se encuentra un índice válido, devolver None

    return None


# Obtener los parámetros

ceav_table = payslip._rule_parameter('l10n_mx_ceav_lower_upper')

integrated_daily_wage = result_rules['INT_DAY_WAGE']['total']


# Encontrar el índice

index = find_index(integrated_daily_wage, ceav_table)


# Obtener el porcentaje y calcular el resultado

percentage_table = payslip._rule_parameter('l10n_mx_ceav_percentage')

percent = percentage_table[index]


# Calcular los días trabajados

days = days_in_period

if unpaid_days_in_period < 8:

    days -= unpaid_days_in_period


# Calcular el resultado final

result = integrated_daily_wage * days

result_rate = percent * 100

Avatar
Descartar
Mejor respuesta

AI was used to create this answer

The error "TypeError: list indices must be integers or slices, not NoneType" means that index is None, and you're trying to use it to access percentage_table[index], which is causing the issue.

Possible Causes:

  1. The function find_index() returns None when no valid index is found.
  2. This means that the integrated_daily_wage does not fit within any of the (low_num, low_measure, high_num, high_measure) conditions in the rates list (ceav_table).
  3. If ceav_table is empty or incorrectly formatted, the loop may never find a match, leading to None.

Solution:

  1. Check if ceav_table is empty or incorrect:
    • Add a debug print to check its contents before calling find_index().

    python

    CopyEdit

    print("CEAV Table:", ceav_table)

  2. Ensure find_index() does not return None unexpectedly:
    • Modify the part where index is used:

    python

    CopyEdit

    if index is None: raise ValueError("No valid index found in ceav_table for the given integrated_daily_wage.")

  3. Handle the case where index is None gracefully:

    python

    CopyEdit

    percent = percentage_table[index] if index is not None else 0

  4. Verify percentage_table is a valid list:
    • Ensure percentage_table is properly structured before accessing elements.

    python

    CopyEdit

    print("Percentage Table:", percentage_table)

Updated Code with Fix:

python

CopyEdit

index = find_index(integrated_daily_wage, ceav_table) if index is None: raise ValueError(f"No valid index found for wage {integrated_daily_wage} in table {ceav_table}") percentage_table = payslip._rule_parameter('l10n_mx_ceav_percentage') if not isinstance(percentage_table, list) or index >= len(percentage_table): raise ValueError("Invalid percentage table or index out of range.") percent = percentage_table[index]

Next Steps:

  • Run the updated code.
  • If the error persists, print ceav_table and percentage_table and share their contents.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
ago 25
219
0
ago 25
2
0
jul 25
2
0
jul 25
3
2
jul 25
476