-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
faet: print change sales person item
- Loading branch information
1 parent
5bd74d0
commit 7feb0fe
Showing
5 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import frappe | ||
from frappe.utils import today | ||
|
||
LIMIT_PER_DAY = 2 | ||
|
||
@frappe.whitelist() | ||
def increment_print_count(): | ||
current_date = today() | ||
|
||
print_log = frappe.cache().hget('global_daily_print_log', 'count') or {} | ||
|
||
if print_log.get('date') != current_date: | ||
print_log = {'count': 0, 'date': current_date} | ||
|
||
if print_log['count'] > LIMIT_PER_DAY: | ||
return {'limit_reached': True} | ||
|
||
print_log['count'] += 1 | ||
frappe.cache().hset('global_daily_print_log', 'count', print_log) | ||
|
||
return {'limit_reached': False} | ||
|
||
def before_print(_, __, ___): | ||
current_date = today() | ||
|
||
print_log = frappe.cache().hget('global_daily_print_log', 'count') | ||
|
||
if not print_log: | ||
return | ||
|
||
if print_log.get('date') != current_date: | ||
return | ||
|
||
if print_log['count'] > LIMIT_PER_DAY: | ||
frappe.throw('The daily print limit for all documents has been reached.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$(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(); | ||
} | ||
}, | ||
}); | ||
}); | ||
}, 500); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters