import frappe
from frappe.custom.doctype.property_setter.property_setter import make_property_setter

def show_item_tax_template_in_sales_invoice():
    """
    Создает Property Setters для показа item_tax_template в Sales Invoice Item
    """
    
    property_setters = [
        {
            'doctype': 'Sales Invoice Item',
            'fieldname': 'item_tax_template',
            'property': 'hidden',
            'value': 0
        },
        {
            'doctype': 'Sales Invoice Item', 
            'fieldname': 'item_tax_template',
            'property': 'in_list_view',
            'value': 1
        },
        {
            'doctype': 'Sales Invoice Item',
            'fieldname': 'item_tax_template', 
            'property': 'columns',
            'value': 2
        },
        {
            'doctype': 'Sales Invoice Item',
            'fieldname': 'item_tax_template',
            'property': 'insert_after', 
            'value': 'item_name'
        }
    ]
    
    for ps in property_setters:
        try:
            make_property_setter(
                doctype=ps['doctype'],
                fieldname=ps['fieldname'],
                property=ps['property'],
                value=ps['value'],
                property_type=get_property_type(ps['property'])
            )
            print(f"✓ Set {ps['fieldname']}.{ps['property']} = {ps['value']}")
        except Exception as e:
            print(f"✗ Error: {e}")
    
    frappe.clear_cache()

def get_property_type(property_name):
    """Возвращает тип свойства"""
    types = {
        'hidden': 'Check',
        'in_list_view': 'Check', 
        'columns': 'Int',
        'insert_after': 'Data'
    }
    return types.get(property_name, 'Data')