Why the custom doctype status is not saved condition after we save that doctype

I created the custom doctype. Once I save, the alert message showing it is “saved” but the status of the document is still “not saved” condition.

@Syed_Ahamed really hard to say anything about!

Pls share the investigation you did!

Things like an screen record, or screenshots of the browser console may will help you to get usefull information to address your issue!

  1. the sub total, vat 5% etc fields are fetch automatically once we enter the details in table. Note: before save

2.But once i save It’s showing like below image

It is saved but the status not changing

could you share the code you wrote?, so we might find related issue

1 Like

frappe.ui.form.on(‘Project Report’, {
onload: function(frm) {
if (frm.doc.docstatus === 0) {
calculateTotals(frm);
}
},
refresh: function(frm) {
if (frm.doc.docstatus === 0) {
calculateTotals(frm);
}
},
table_add: function(frm, cdt, cdn) {
if (frm.doc.docstatus === 0) {
calculateTotals(frm);
}
},
table_remove: function(frm, cdt, cdn) {
if (frm.doc.docstatus === 0) {
calculateTotals(frm);
}
}
});

frappe.ui.form.on(‘PR Table’, {
item_code: function(frm, cdt, cdn) {
if (frm.doc.docstatus === 0) {
var item = frappe.get_doc(cdt, cdn);
var price_list = frm.doc.price_list;
var item_code = item.item_code;

        frappe.call({
            method: 'frappe.client.get_value',
            args: {
                doctype: 'Item Price',
                filters: {
                    item_code: item_code,
                    price_list: price_list
                },
                fieldname: 'price_list_rate'
            },
            callback: function(response) {
                if (response && response.message) {
                    frappe.model.set_value(cdt, cdn, 'rate', response.message.price_list_rate);
                    var quantity = item.quantity;
                    var rate = response.message.price_list_rate;
                    var amount = quantity * rate;
                    frappe.model.set_value(cdt, cdn, 'amount', amount);
                    
                    // Calculate Total Budget
                    var budget_per_unit = item.budgetunit || 0;
                    var total_budget = budget_per_unit * quantity;
                    frappe.model.set_value(cdt, cdn, 'total_budget', total_budget);
                    
                    // Calculate Total Hours
                    var hrs_per_unit = item.no_of_hrsunit || 0;
                    var total_hours = hrs_per_unit * quantity;
                    frappe.model.set_value(cdt, cdn, 'total_hours', total_hours);
                    
                    // Recalculate totals after setting values
                    calculateTotals(frm);
                }
            }
        });
    }
},
quantity: function(frm, cdt, cdn) {
    if (frm.doc.docstatus === 0) {
        var item = frappe.get_doc(cdt, cdn);
        var quantity = item.quantity;
        var rate = item.rate;
        var amount = quantity * rate;
        frappe.model.set_value(cdt, cdn, 'amount', amount);
        
        // Calculate Total Budget
        var budget_per_unit = item.budgetunit || 0;
        var total_budget = budget_per_unit * quantity;
        frappe.model.set_value(cdt, cdn, 'total_budget', total_budget);
        
        // Calculate Total Hours
        var hrs_per_unit = item.no_of_hrsunit || 0;
        var total_hours = hrs_per_unit * quantity;
        frappe.model.set_value(cdt, cdn, 'total_hours', total_hours);
        
        // Recalculate totals after setting values
        calculateTotals(frm);
    }
},
budgetunit: function(frm, cdt, cdn) {
    if (frm.doc.docstatus === 0) {
        var item = frappe.get_doc(cdt, cdn);
        var quantity = item.quantity;
        var budget_per_unit = item.budgetunit || 0;
        var total_budget = budget_per_unit * quantity;
        frappe.model.set_value(cdt, cdn, 'total_budget', total_budget);
        
        // Recalculate totals after setting values
        calculateTotals(frm);
    }
},
no_of_hrsunit: function(frm, cdt, cdn) {
    if (frm.doc.docstatus === 0) {
        var item = frappe.get_doc(cdt, cdn);
        var quantity = item.quantity;
        var hrs_per_unit = item.no_of_hrsunit || 0;
        var total_hours = hrs_per_unit * quantity;
        frappe.model.set_value(cdt, cdn, 'total_hours', total_hours);
        
        // Recalculate totals after setting values
        calculateTotals(frm);
    }
}

});

function calculateTotals(frm) {
var subtotalAmount = 0;
var totalBudgets = 0;

frm.doc.table.forEach(function(row) {
    subtotalAmount += row.amount;
    totalBudgets += row.total_budget || 0; // Add total_budget of each row
});

// Calculate VAT 5% with two decimal places
var vat5 = (subtotalAmount * 0.05).toFixed(2);

// Calculate Grand Total
var grandTotal = parseFloat(subtotalAmount) + parseFloat(vat5);

// Calculate Gross Margin
var grossMargin = subtotalAmount - totalBudgets;

// Calculate G Margin Percent
var gMarginPercent = ((subtotalAmount - totalBudgets) / subtotalAmount) * 100;

frm.set_value('sub_total', subtotalAmount);
frm.set_value('vat_5', vat5);
frm.set_value('grand_amount', grandTotal);
frm.set_value('total_budgets', totalBudgets);
frm.set_value('grossmargin', grossMargin);
frm.set_value('gmargin', gMarginPercent);

}

As far as I can see, your code runs in the refresh and onload events when the page is refreshed. So your status is not updated. Try to comment on the refresh and onload event, then check it.

2 Likes

I don’t get the last line u told.

try to remove load and refresh events . Then save

comment this code, otherwise, use before_save.

1 Like

:+1: :+1: :+1: