Skip to content

Commit

Permalink
fix: print logic updated
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishBarvaliya committed Aug 21, 2024
1 parent ffb8c3f commit 399e43c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
15 changes: 15 additions & 0 deletions d2h/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ def before_print(_, __, ___):
if print_log['count'] > LIMIT_PER_DAY:
frappe.throw('The daily print limit for all documents has been reached.')

@frappe.whitelist()
def get_print_limit():
current_date = today()

print_log = frappe.cache().hget('global_daily_print_log', 'count')

if not print_log:
return { "limit_reached" : False }

if print_log.get('date') != current_date:
return { "limit_reached" : False }

if print_log['count'] > LIMIT_PER_DAY:
return { "limit_reached" : True }


@frappe.whitelist()
def short_close_purchase_order(purchase_order):
Expand Down
39 changes: 23 additions & 16 deletions d2h/public/js/form.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
$(document).ready(function () {
setTimeout(() => {
$(`button[data-label='Print']`).on("click", function (e) {
frappe.call({
method: "d2h.api.increment_print_count",
callback: function (r) {
if (r.message && r.message.limit_reached) {
frappe.throw(
"The daily print limit for all documents has been reached."
);
} else {
frm.print_doc();
}
},
});
$(document).on("page-change", function () {
if (document.baseURI.includes("/app/print/")) {
$(`button[data-label='Print']`).hide();
frappe.call({
method: "d2h.api.get_print_limit",
callback: function (r) {
if (r.message && !r.message.limit_reached) {
$(`button[data-label='Print']`).show();
$(`button[data-label='Print']`).on("click", function (e) {
frappe.call({
method: "d2h.api.increment_print_count",
callback: function (r) {
if (r.message && r.message.limit_reached) {
frappe.throw(
"The daily print limit for all documents has been reached."
);
}
},
});
});
}
},
});
}, 500);
}
});

0 comments on commit 399e43c

Please sign in to comment.