Skip to content

Commit

Permalink
feat: Auto-fetch previous daily electricity reading in Daily P and L
Browse files Browse the repository at this point in the history
  • Loading branch information
jabir-tridz committed Mar 22, 2024
1 parent 4e1add7 commit 8ebf0bb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ury_pulse/ury_pulse/doctype/ury_daily_p_and_l/ury_daily_p_and_l.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ frappe.ui.form.on('URY Daily P and L', {
}
});
}
},
date: function(frm){
set_electricity_closing(frm)
}
});

Expand All @@ -67,6 +70,42 @@ function set_html_data(frm) {
}
}

function set_electricity_closing(frm) {
try{
var current_date_obj = new Date(frm.doc.date);

current_date_obj.setDate(current_date_obj.getDate() - 1);

var previous_date = current_date_obj.toISOString().split('T')[0];
if (frm.doc.branch && frm.doc.date){
frappe.call({
method: 'frappe.client.get_list',
args: {
doctype: 'URY Daily P and L',
fields: ['electricity_closing'],
filters: {
'branch': frm.doc.branch,
'date': previous_date
},
order_by: 'creation desc',
},
callback: function(response) {
if (response.message && response.message.length > 0) {
console.log(response.message)
frm.set_value("electricity_opening",response.message[0].electricity_closing)
}
else {
frm.set_value("electricity_opening","")
}
}
});
}
}
catch(err){
console.log("Last P and L not found")
}
}

frappe.ui.form.on('URY P and L Materials', {
units_consumed: function(frm, cdt, cdn) {
var row = locals[cdt][cdn];
Expand Down

0 comments on commit 8ebf0bb

Please sign in to comment.