import re with open('stock.php', 'r') as f: content = f.read() # Update openItemModal definition content = content.replace( "function openItemModal(sku = '', name = '', price = '', cost_price = '', base_stock = '', vat = '', category_id = '', supplier_id = '', unit_id = '', image_url = '') {", "function openItemModal(sku = '', name = '', price = '', cost_price = '', base_stock = '', vat = '', category_id = '', supplier_id = '', unit_id = '', image_url = '', in_catalog = 0) {" ) # Add UI toggle in the form switch_html = """
""" content = content.replace( '
\n ', switch_html + '
\n ' ) # Update Javascript form handling content = content.replace( "document.getElementById('item_unit').value = unit_id;", "document.getElementById('item_unit').value = unit_id;\n document.getElementById('item_in_catalog').checked = (parseInt(in_catalog) === 1);" ) content = content.replace( "formData.append('unit_id', document.getElementById('item_unit').value);", "formData.append('unit_id', document.getElementById('item_unit').value);\n formData.append('in_catalog', document.getElementById('item_in_catalog').checked ? '1' : '0');" ) # Replace the onclick in the button where we pass the arguments search_str = "onclick=\"openItemModal('', '', '', '', '', '', '', '', '', '')\"" replace_str = "onclick=\"openItemModal('', '', '', '', '', '', '', '', '', '', '')\"" content = content.replace(search_str, replace_str) with open('stock.php', 'w') as f: f.write(content)