Skip to content

Commit

Permalink
fix: permission error after submitting exchange rate revaluation (#25432
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nextchamp-saqib committed Apr 22, 2021
1 parent e3b8057 commit 3d4acf9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ frappe.ui.form.on('Exchange Rate Revaluation', {

refresh: function(frm) {
if(frm.doc.docstatus==1) {
frappe.db.get_value("Journal Entry Account", {
'reference_type': 'Exchange Rate Revaluation',
'reference_name': frm.doc.name,
'docstatus': 1
}, "sum(debit) as sum", (r) =>{
let total_amt = 0;
frm.doc.accounts.forEach(d=> {
total_amt = total_amt + d['new_balance_in_base_currency'];
});
if(total_amt !== r.sum) {
frm.add_custom_button(__('Journal Entry'), function() {
return frm.events.make_jv(frm);
}, __('Create'));
frappe.call({
method: 'check_journal_entry_condition',
doc: frm.doc,
callback: function(r) {
if (r.message) {
frm.add_custom_button(__('Journal Entry'), function() {
return frm.events.make_jv(frm);
}, __('Create'));
}
}
}, 'Journal Entry');
});
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ def validate_mandatory(self):
if not (self.company and self.posting_date):
frappe.throw(_("Please select Company and Posting Date to getting entries"))

@frappe.whitelist()
def check_journal_entry_condition(self):
total_debit = frappe.db.get_value("Journal Entry Account", {
'reference_type': 'Exchange Rate Revaluation',
'reference_name': self.name,
'docstatus': 1
}, "sum(debit) as sum")

total_amt = 0
for d in self.accounts:
total_amt = total_amt + d.new_balance_in_base_currency

if total_amt != total_debit:
return True

return False

@frappe.whitelist()
def get_accounts_data(self, account=None):
accounts = []
Expand Down

0 comments on commit 3d4acf9

Please sign in to comment.