# Supplier scorecard only when there is movement

Hi,

I have some suppliers that do not deal with me very often, but that I need to evaluate, due to regulatory requirements.

How can I test this supplier only when there is a delivery or relationship with him?

An example below: The supplier X had some transactions with my company only in months 1,2,4 and 7. The system is actually generating these scores:

Instead of test only the months that really exist some purchase:

How can I change my weighting_funcion to allow this math?

Result 1:

``````({total_accepted_items} / {total_received_items})*100
else 100
``````

This code above will give your supplier 100% score when there are no received items. weirdly, the If statement comes after the line of code that is run if the condition is true.

``````<statement if condition true>
if <condition>
else <statement if condition is false>
``````
1 Like

Hey fishter,

My point is, this â€śelse 100â€ť (when the supplier doesnâ€™t have any received items) will increase the score, in its averageâ€¦ otherwise, if I use â€śelse 0â€ť, the score will decreaseâ€¦

So, the workaround we did was â€śelse 50â€ť. But it is so far from an ideal workaroundâ€¦

Unfortunately there doesnâ€™t seem to be a way to reference the previous periodâ€™s score in order to â€ścarry it forwardâ€ť, or simply ignore a period with no useful data.

Yeapâ€¦ Soâ€¦ nevermind, and thanks for your help!

After trying to understand GPT and ERPNext working together, Iâ€™ve found a possible solution to this issue/improvement:

def calculate_all_supplier_scorecard_variables():
supplier_scorecard_variables = frappe.get_all(â€śSupplier Scorecard Variableâ€ť, fields=[â€śnameâ€ť, â€śfrequencyâ€ť, â€ścalculation_methodâ€ť, â€śscorecard_criteriaâ€ť])

``````movement_weeks = []

# Iterate over supplier_scorecard_variables to find the weeks with movement in criteria
for index, variable in enumerate(supplier_scorecard_variables):
if variable.frequency == "Weekly":
week_has_movement = False
for c in criteria:
if c.get("has_movement"):
week_has_movement = True
break
if week_has_movement:
movement_weeks.append(index)

# Iterate over supplier_scorecard_variables again, but only perform calculation for weeks with movement
for i in movement_weeks:
variable = supplier_scorecard_variables[i]
if variable.calculation_method:
frappe.get_doc("Supplier Scorecard Variable", variable.name).calculate_variable()
``````

Is that a possible solution?

Tks!