frappe.ui.form.on('Tax Free Indicator', {
    date_from: function(frm) {
        calculate_date_to(frm);
    },
    duration: function(frm) {
        calculate_date_to(frm);
    }
});

function calculate_date_to(frm) {
    if (!frm.doc.date_from || !frm.doc.duration) return;

    let from_date = frappe.datetime.str_to_obj(frm.doc.date_from);
    let to_date = new Date(from_date);
    to_date.setFullYear(to_date.getFullYear() + frm.doc.duration);

    frm.set_value('date_to', frappe.datetime.obj_to_str(to_date));
}
