Fetch data pricing rule item code to sales invoice print format

i have child table called pricing rule item code in pricing rule and sales invoice item in sales invoice. i need to get the free_item in pricing rule based on item code in both child table for my sales invoice print format. anyone can help me with this? here is my code, maybe someone could help me modify my code. Thanks a lot !
def get_free_item(sales_invoice_name):
sales_invoice_items = frappe.get_list(‘Sales Invoice Item’, filters={‘parent’: sales_invoice_name}, fields=[‘item_code’])
bonus_items =

for sales_invoice_item in sales_invoice_items:
    item_code = sales_invoice_item.item_code    
    pricing_rule_items = frappe.get_list('Pricing Rule Item Code', filters={'item_code': item_code}, fields=['free_item'])
    for pricing_rule_item in pricing_rule_items:
        if pricing_rule_item.free_item:

return bonus_items