├── .gitignore
├── MANIFEST.in
├── README.md
├── frappe_helper
├── __init__.py
├── api.py
├── config
│ ├── __init__.py
│ ├── desktop.py
│ └── docs.py
├── frappe_helper
│ ├── __init__.py
│ └── doctype
│ │ ├── __init__.py
│ │ ├── desk_form
│ │ ├── __init__.py
│ │ ├── desk_form.js
│ │ ├── desk_form.json
│ │ ├── desk_form.py
│ │ ├── templates
│ │ │ ├── desk_form.html
│ │ │ └── desk_form_row.html
│ │ └── test_desk_form.py
│ │ └── desk_form_field
│ │ ├── __init__.py
│ │ ├── desk_form_field.json
│ │ └── desk_form_field.py
├── hooks.py
├── modules.txt
├── patches.txt
├── public
│ ├── css
│ │ ├── desk-form.css
│ │ ├── frappe-helper.css
│ │ └── num-pad.css
│ └── js
│ │ ├── desk-form-class.js
│ │ ├── desk-modal.js
│ │ ├── frappe-form-class.js
│ │ ├── frappe-helper-api.js
│ │ ├── jshtml-class.js
│ │ └── num-pad-class.js
├── setup
│ └── install.py
└── templates
│ ├── __init__.py
│ └── pages
│ └── __init__.py
├── license.txt
├── requirements.txt
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.pyc
3 | *.egg-info
4 | *.swp
5 | tags
6 | .idea
7 | /.idea/
8 | %SystemDrive%/ProgramData/Microsoft/Windows/Caches/cversions.2.db
9 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include MANIFEST.in
2 | include requirements.txt
3 | include *.json
4 | include *.md
5 | include *.py
6 | include *.txt
7 | recursive-include frappe_helper *.css
8 | recursive-include frappe_helper *.csv
9 | recursive-include frappe_helper *.html
10 | recursive-include frappe_helper *.ico
11 | recursive-include frappe_helper *.js
12 | recursive-include frappe_helper *.json
13 | recursive-include frappe_helper *.md
14 | recursive-include frappe_helper *.png
15 | recursive-include frappe_helper *.py
16 | recursive-include frappe_helper *.svg
17 | recursive-include frappe_helper *.txt
18 | recursive-exclude frappe_helper *.pyc
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
Frappe Helper
4 |
5 |
6 | ___
7 | > ### Frappe Helper includes the following functionalities:
8 |
9 | 1. Customized Desk Form based on Frappe Web Form functionalities.
10 | 2. Integrated NumPad to manage inputs.
11 | 3. Automatic installation of the desk forms created in the different applications.
12 | 4. Dynamic rendering of desk forms.
13 | 5. Compatible with Dark Theme.
14 |
15 | ___
16 | ### Frappe Helper requires
17 | 1. [Frappe Framework](https://github.com/quantumbitcore/frappe_helper.git)
18 |
19 | ___
20 | ### How to Install
21 |
22 | #### Self Host:
23 | 1. `bench get-app https://github.com/quantumbitcore/frappe_helper.git`
24 | 2. `bench setup requirements`
25 | 3. `bench build --app frappe_helper`
26 | 4. `bench restart`
27 | 5. `bench --site [site.name] install-app frappe_helper`
28 | 6. `bench --site [site.name] migrate`
29 |
30 | #### Frappe Cloud:
31 | >Available in your hosting on FrappeCloud [here](https://frappecloud.com/marketplace/apps/frappe_helper)
32 |
33 | ___
34 | ### How to Use
35 | > See the documentation [here](https://github.com/quantumbitcore/frappe_helper/wiki)
36 |
37 | ___
38 | ### Compatibility
39 | > V13, V14
40 |
41 | ___
42 | Frappe Helper is based on [Frappe Framework](https://github.com/frappe/frappe).
43 |
44 | ___
45 |
46 | ### License
47 | > GNU / General Public License (see [license.txt](license.txt))
48 |
49 | > The Frappe Helper code is licensed under the GNU General Public License (v3).
--------------------------------------------------------------------------------
/frappe_helper/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | __version__ = '0.3.3'
--------------------------------------------------------------------------------
/frappe_helper/api.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Copyright (c) 2021, Quantum Bit Core and contributors
3 | # For license information, please see license.txt
4 |
5 | from __future__ import unicode_literals
6 | import frappe
7 | import json
8 | import hashlib
9 |
10 |
11 | @frappe.whitelist()
12 | def call(model, name, method, args=None):
13 | doc = frappe.get_doc(model, name)
14 | if args is not None:
15 | _args = json.loads(args)
16 | # args = [_args[arg] for arg in _args]
17 | kwargs = {arg: _args[arg] for arg in _args}
18 | return getattr(doc, method)(**kwargs)
19 | # return doc.run_method(method, **kwargs)
20 | else:
21 | return getattr(doc, method)
22 |
23 |
24 | def encrypt(data, method):
25 | if not isinstance(data, bytes):
26 | data = data.encode('utf-8')
27 |
28 | if method == 'md5':
29 | return hashlib.md5(data).hexdigest()
30 | if method == 'sha1':
31 | return hashlib.sha1(data).hexdigest()
32 | if method == 'sha224':
33 | return hashlib.sha3_224(data).hexdigest()
34 |
35 |
36 | @frappe.whitelist()
37 | def validate_link():
38 | """validate link when updated by user"""
39 | import frappe
40 | import frappe.utils
41 |
42 | value, options, fetch = frappe.form_dict.get('value'), frappe.form_dict.get('options'), frappe.form_dict.get('fetch')
43 |
44 | # no options, don't validate
45 | if not options or options=='null' or options=='undefined':
46 | frappe.response['message'] = 'Ok'
47 | return
48 |
49 | valid_value = frappe.db.get_all(options, filters=dict(name=value), as_list=1, limit=1)
50 |
51 | if valid_value:
52 | valid_value = valid_value[0][0]
53 |
54 | # get fetch values
55 | if fetch:
56 | # escape with "`"
57 | fetch = ", ".join(("`{0}`".format(f.strip()) for f in fetch.split(",")))
58 | fetch_value = None
59 | try:
60 | fetch_value = frappe.db.sql("select %s from `tab%s` where name=%s"
61 | % (fetch, options, '%s'), (value,))[0]
62 | except Exception as e:
63 | error_message = str(e).split("Unknown column '")
64 | fieldname = None if len(error_message)<=1 else error_message[1].split("'")[0]
65 | frappe.msgprint(_("Wrong fieldname {0} in add_fetch configuration of custom client script").format(fieldname))
66 | frappe.errprint(frappe.get_traceback())
67 |
68 | if fetch_value:
69 | frappe.response['fetch_values'] = [frappe.utils.parse_val(c) for c in fetch_value]
70 |
71 | frappe.response['valid_value'] = valid_value
72 | frappe.response['message'] = 'Ok'
73 |
74 |
--------------------------------------------------------------------------------
/frappe_helper/config/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/config/__init__.py
--------------------------------------------------------------------------------
/frappe_helper/config/desktop.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 | from frappe import _
4 |
5 | def get_data():
6 | return [
7 | {
8 | "module_name": "Frappe Helper",
9 | "color": "grey",
10 | "icon": "octicon octicon-file-directory",
11 | "type": "module",
12 | "label": _("Frappe Helper")
13 | }
14 | ]
15 |
--------------------------------------------------------------------------------
/frappe_helper/config/docs.py:
--------------------------------------------------------------------------------
1 | """
2 | Configuration for docs
3 | """
4 |
5 | # source_link = "https://github.com/[org_name]/frappe_helper"
6 | # docs_base_url = "https://[org_name].github.io/frappe_helper"
7 | # headline = "App that does everything"
8 | # sub_heading = "Yes, you got that right the first time, everything"
9 |
10 | def get_context(context):
11 | context.brand_html = "Frappe Helper"
12 |
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/frappe_helper/__init__.py
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/frappe_helper/doctype/__init__.py
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/frappe_helper/doctype/desk_form/__init__.py
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form/desk_form.js:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021, Quantum Bit Core and contributors
2 | // For license information, please see license.txt
3 |
4 | frappe.desk_form = {
5 | set_fieldname_select: function(frm) {
6 | return new Promise(resolve => {
7 | var me = this, doc = frm.doc;
8 |
9 | if (doc.doc_type) {
10 | frappe.model.with_doctype(doc.doc_type, function() {
11 | var fields = $.map(frappe.get_doc("DocType", frm.doc.doc_type).fields, function(d) {
12 | if (frappe.model.no_value_type.indexOf(d.fieldtype) === -1 ||
13 | d.fieldtype === 'Table') {
14 | return { label: d.label + ' (' + d.fieldtype + ')', value: d.fieldname };
15 | } else {
16 | return null;
17 | }
18 | });
19 | var currency_fields = $.map(frappe.get_doc("DocType", frm.doc.doc_type).fields, function(d) {
20 | if (d.fieldtype === 'Currency' || d.fieldtype === 'Float') {
21 | return { label: d.label, value: d.fieldname };
22 | } else {
23 | return null;
24 | }
25 | });
26 |
27 | frm.fields_dict.desk_form_fields.grid.update_docfield_property(
28 | 'fieldname', 'options', fields
29 | );
30 |
31 | resolve();
32 | });
33 | }
34 | });
35 | }
36 | };
37 |
38 | frappe.ui.form.on("Desk Form", {
39 | refresh: function(frm) {
40 | // show is-standard only if developer mode
41 | frm.get_field("is_standard").toggle(frappe.boot.developer_mode);
42 |
43 | frappe.desk_form.set_fieldname_select(frm);
44 |
45 | if (frm.doc.is_standard && !frappe.boot.developer_mode) {
46 | frm.set_read_only();
47 | frm.disable_save();
48 | }
49 |
50 | frm.add_custom_button(__('Get Fields'), () => {
51 | let webform_fieldtypes = frappe.meta.get_field('Desk Form Field', 'fieldtype').options.split('\n');
52 | let fieldnames = (frm.doc.fields || []).map(d => d.fieldname);
53 | frappe.model.with_doctype(frm.doc.doc_type, () => {
54 | let meta = frappe.get_meta(frm.doc.doc_type);
55 | for (let field of meta.fields) {
56 | if (webform_fieldtypes.includes(field.fieldtype)
57 | && !fieldnames.includes(field.fieldname)) {
58 | frm.add_child('desk_form_fields', {
59 | fieldname: field.fieldname,
60 | label: field.label,
61 | fieldtype: field.fieldtype,
62 | options: field.options,
63 | reqd: field.reqd,
64 | default: field.default,
65 | read_only: field.read_only,
66 | depends_on: field.depends_on,
67 | mandatory_depends_on: field.mandatory_depends_on,
68 | read_only_depends_on: field.read_only_depends_on,
69 | hidden: field.hidden,
70 | description: field.description
71 | });
72 | }
73 | }
74 | frm.refresh();
75 | });
76 | });
77 | },
78 |
79 | title: function(frm) {
80 | if (frm.doc.__islocal) {
81 | var page_name = frm.doc.title.toLowerCase().replace(/ /g, "-");
82 | frm.set_value("route", page_name);
83 | frm.set_value("success_url", "/" + page_name);
84 | }
85 | },
86 |
87 | doc_type: function(frm) {
88 | frappe.desk_form.set_fieldname_select(frm);
89 | }
90 | });
91 |
92 |
93 | frappe.ui.form.on("Desk Form Field", {
94 | fieldtype: function(frm, doctype, name) {
95 | var doc = frappe.get_doc(doctype, name);
96 | if (['Section Break', 'Column Break', 'Page Break'].includes(doc.fieldtype)) {
97 | doc.fieldname = '';
98 | frm.refresh_field("desk_form_fields");
99 | }
100 | },
101 | fieldname: function(frm, doctype, name) {
102 | var doc = frappe.get_doc(doctype, name);
103 | var df = $.map(frappe.get_doc("DocType", frm.doc.doc_type).fields, function(d) {
104 | return doc.fieldname == d.fieldname ? d : null;
105 | })[0];
106 |
107 | doc.label = df.label;
108 | doc.reqd = df.reqd;
109 | doc.options = df.options;
110 | doc.fieldtype = frappe.meta.get_docfield("Desk Form Field", "fieldtype")
111 | .options.split("\n").indexOf(df.fieldtype) === -1 ? "Data" : df.fieldtype;
112 | doc.description = df.description;
113 | doc["default"] = df["default"];
114 | }
115 | });
116 |
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form/desk_form.json:
--------------------------------------------------------------------------------
1 | {
2 | "actions": [],
3 | "allow_rename": 1,
4 | "autoname": "field:route",
5 | "creation": "2021-07-15 19:11:24.656019",
6 | "doctype": "DocType",
7 | "document_type": "Document",
8 | "engine": "InnoDB",
9 | "field_order": [
10 | "title",
11 | "route",
12 | "doc_type",
13 | "module",
14 | "column_break_4",
15 | "is_standard",
16 | "published",
17 | "login_required",
18 | "route_to_success_link",
19 | "allow_edit",
20 | "allow_multiple",
21 | "show_in_grid",
22 | "allow_delete",
23 | "allow_print",
24 | "print_format",
25 | "allow_comments",
26 | "show_attachments",
27 | "allow_incomplete",
28 | "introduction",
29 | "introduction_text",
30 | "fields",
31 | "desk_form_fields",
32 | "max_attachment_size",
33 | "client_script_section",
34 | "client_script",
35 | "custom_css_section",
36 | "custom_css",
37 | "actions",
38 | "button_label",
39 | "success_message",
40 | "success_url",
41 | "advanced",
42 | "breadcrumbs"
43 | ],
44 | "fields": [
45 | {
46 | "fieldname": "title",
47 | "fieldtype": "Data",
48 | "label": "Title",
49 | "no_copy": 1,
50 | "reqd": 1
51 | },
52 | {
53 | "fieldname": "route",
54 | "fieldtype": "Data",
55 | "label": "Route",
56 | "unique": 1
57 | },
58 | {
59 | "fieldname": "doc_type",
60 | "fieldtype": "Link",
61 | "in_list_view": 1,
62 | "in_standard_filter": 1,
63 | "label": "Select DocType",
64 | "options": "DocType",
65 | "reqd": 1
66 | },
67 | {
68 | "fieldname": "module",
69 | "fieldtype": "Link",
70 | "label": "Module",
71 | "options": "Module Def"
72 | },
73 | {
74 | "fieldname": "column_break_4",
75 | "fieldtype": "Column Break"
76 | },
77 | {
78 | "default": "0",
79 | "fieldname": "is_standard",
80 | "fieldtype": "Check",
81 | "label": "Is Standard"
82 | },
83 | {
84 | "default": "0",
85 | "fieldname": "published",
86 | "fieldtype": "Check",
87 | "label": "Published"
88 | },
89 | {
90 | "default": "0",
91 | "fieldname": "login_required",
92 | "fieldtype": "Check",
93 | "label": "Login Required"
94 | },
95 | {
96 | "default": "0",
97 | "depends_on": "eval:doc.login_required",
98 | "fieldname": "route_to_success_link",
99 | "fieldtype": "Check",
100 | "label": "Route to Success Link"
101 | },
102 | {
103 | "default": "0",
104 | "depends_on": "login_required",
105 | "fieldname": "allow_edit",
106 | "fieldtype": "Check",
107 | "label": "Allow Edit"
108 | },
109 | {
110 | "default": "0",
111 | "depends_on": "login_required",
112 | "fieldname": "allow_multiple",
113 | "fieldtype": "Check",
114 | "label": "Allow Multiple"
115 | },
116 | {
117 | "default": "0",
118 | "depends_on": "allow_multiple",
119 | "fieldname": "show_in_grid",
120 | "fieldtype": "Check",
121 | "label": "Show as Grid"
122 | },
123 | {
124 | "default": "0",
125 | "depends_on": "allow_multiple",
126 | "fieldname": "allow_delete",
127 | "fieldtype": "Check",
128 | "label": "Allow Delete"
129 | },
130 | {
131 | "default": "0",
132 | "fieldname": "allow_print",
133 | "fieldtype": "Check",
134 | "label": "Allow Print"
135 | },
136 | {
137 | "depends_on": "allow_print",
138 | "fieldname": "print_format",
139 | "fieldtype": "Link",
140 | "label": "Print Format",
141 | "options": "Print Format"
142 | },
143 | {
144 | "default": "0",
145 | "depends_on": "login_required",
146 | "fieldname": "allow_comments",
147 | "fieldtype": "Check",
148 | "label": "Allow Comments"
149 | },
150 | {
151 | "default": "0",
152 | "depends_on": "login_required",
153 | "fieldname": "show_attachments",
154 | "fieldtype": "Check",
155 | "label": "Show Attachments"
156 | },
157 | {
158 | "default": "0",
159 | "description": "Allow saving if mandatory fields are not filled",
160 | "fieldname": "allow_incomplete",
161 | "fieldtype": "Check",
162 | "label": "Allow Incomplete Forms"
163 | },
164 | {
165 | "collapsible": 1,
166 | "fieldname": "introduction",
167 | "fieldtype": "Section Break",
168 | "label": "Introduction"
169 | },
170 | {
171 | "fieldname": "introduction_text",
172 | "fieldtype": "Text Editor",
173 | "label": "Introduction"
174 | },
175 | {
176 | "fieldname": "fields",
177 | "fieldtype": "Section Break",
178 | "label": "Fields"
179 | },
180 | {
181 | "fieldname": "desk_form_fields",
182 | "fieldtype": "Table",
183 | "label": "Desk Form Fields",
184 | "options": "Desk Form Field"
185 | },
186 | {
187 | "fieldname": "max_attachment_size",
188 | "fieldtype": "Int",
189 | "label": "Max Attachment Size (in MB)"
190 | },
191 | {
192 | "collapsible": 1,
193 | "fieldname": "client_script_section",
194 | "fieldtype": "Section Break",
195 | "label": "Client Script"
196 | },
197 | {
198 | "description": "For help see Client Script API and Examples",
199 | "fieldname": "client_script",
200 | "fieldtype": "Code",
201 | "label": "Client Script"
202 | },
203 | {
204 | "collapsible": 1,
205 | "fieldname": "custom_css_section",
206 | "fieldtype": "Section Break",
207 | "label": "Custom CSS"
208 | },
209 | {
210 | "fieldname": "custom_css",
211 | "fieldtype": "Code",
212 | "label": "Custom CSS",
213 | "options": "CSS"
214 | },
215 | {
216 | "collapsible": 1,
217 | "fieldname": "actions",
218 | "fieldtype": "Section Break",
219 | "label": "Actions"
220 | },
221 | {
222 | "default": "Save",
223 | "fieldname": "button_label",
224 | "fieldtype": "Data",
225 | "label": "Button Label"
226 | },
227 | {
228 | "description": "Message to be displayed on successful completion (only for Guest users)",
229 | "fieldname": "success_message",
230 | "fieldtype": "Text",
231 | "label": "Success Message"
232 | },
233 | {
234 | "description": "Go to this URL after completing the form (only for Guest users)",
235 | "fieldname": "success_url",
236 | "fieldtype": "Data",
237 | "label": "Success URL"
238 | },
239 | {
240 | "collapsible": 1,
241 | "fieldname": "advanced",
242 | "fieldtype": "Section Break",
243 | "label": "Advanced"
244 | },
245 | {
246 | "description": "List as [{\"label\": _(\"Jobs\"), \"route\":\"jobs\"}]",
247 | "fieldname": "breadcrumbs",
248 | "fieldtype": "Code",
249 | "label": "Breadcrumbs"
250 | }
251 | ],
252 | "icon": "icon-edit",
253 | "is_published_field": "published",
254 | "links": [],
255 | "modified": "2022-12-23 15:52:04.760315",
256 | "modified_by": "Administrator",
257 | "module": "Frappe Helper",
258 | "name": "Desk Form",
259 | "owner": "Administrator",
260 | "permissions": [
261 | {
262 | "create": 1,
263 | "delete": 1,
264 | "read": 1,
265 | "report": 1,
266 | "role": "System Manager",
267 | "share": 1,
268 | "write": 1
269 | }
270 | ],
271 | "sort_field": "modified",
272 | "sort_order": "DESC",
273 | "title_field": "title",
274 | "track_changes": 1
275 | }
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form/desk_form.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Copyright (c) 2021, Quantum Bit Core and contributors
3 | # For license information, please see license.txt
4 |
5 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
6 | # For license information, please see license.txt
7 |
8 | from __future__ import unicode_literals
9 |
10 | import json
11 | import os
12 |
13 | from six import iteritems
14 | from six.moves.urllib.parse import urlencode
15 |
16 | import frappe
17 | from frappe import _, scrub
18 | from frappe.core.doctype.file.file import get_max_file_size, remove_file_by_url
19 | from frappe.custom.doctype.customize_form.customize_form import docfield_properties
20 | from frappe.modules.utils import export_module_json, get_doc_module
21 | from frappe.model.document import Document
22 |
23 |
24 | class DeskForm(Document):
25 | def updateJsonFile(self):
26 | app = frappe.db.get_value('Module Def', self.module, 'app_name')
27 | path = os.path.abspath(os.path.dirname(__file__))
28 | path = os.path.join(path.split(
29 | "apps")[0], "apps", app, app, app, 'desk_form')
30 |
31 | file_name = self.name.replace('-', '_')
32 |
33 | file_path = os.path.join(path, file_name, file_name + '.json')
34 |
35 | jsonFile = open(file_path, "r") # Open the JSON file for reading
36 | data = json.load(jsonFile) # Read the JSON into the buffer
37 | jsonFile.close() # Close the JSON file
38 |
39 | ## Working with buffered content
40 | tmp = data
41 | tmp["docstatus"] = 1
42 |
43 | ## Save our changes to JSON file
44 | jsonFile = open(file_path, "w+")
45 | jsonFile.write(json.dumps(tmp))
46 | jsonFile.close()
47 |
48 | def after_delete(self):
49 | self.updateJsonFile()
50 |
51 | def onload(self):
52 | #super(DeskForm, self).onload()
53 | if self.is_standard:
54 | self.use_meta_fields()
55 |
56 | def validate(self):
57 | #super(DeskForm, self).validate()
58 |
59 |
60 | if not self.module:
61 | self.module = frappe.db.get_value('DocType', self.doc_type, 'module')
62 |
63 | if not frappe.flags.in_import:
64 | self.validate_fields()
65 |
66 | def validate_fields(self):
67 | '''Validate all fields are present'''
68 | from frappe.model import no_value_fields
69 | missing = []
70 | meta = frappe.get_meta(self.doc_type)
71 |
72 |
73 | for df in self.desk_form_fields:
74 | if not df.fieldname and df.label:
75 | df.fieldname = scrub(df.label)
76 |
77 | if df.fieldname and (df.fieldtype not in no_value_fields and not meta.has_field(df.fieldname) and not df.extra_field):
78 | missing.append(df.fieldname)
79 |
80 | if missing:
81 | frappe.throw(_('Following fields are missing:') + ' in DeskForm ' + self.title + '
' + '
'.join(missing))
82 |
83 | def reset_field_parent(self):
84 | '''Convert link fields to select with names as options'''
85 | for df in self.desk_form_fields:
86 | df.parent = self.doc_type
87 |
88 | def use_meta_fields(self):
89 | '''Override default properties for standard web forms'''
90 | meta = frappe.get_meta(self.doc_type)
91 |
92 | for df in self.desk_form_fields:
93 | meta_df = meta.get_field(df.fieldname)
94 |
95 | if not meta_df:
96 | continue
97 |
98 | for prop in docfield_properties:
99 | if df.fieldtype==meta_df.fieldtype and prop not in ("idx",
100 | "reqd", "default", "description", "default", "options",
101 | "hidden", "read_only", "label"):
102 | df.set(prop, meta_df.get(prop))
103 |
104 |
105 | # TODO translate options of Select fields like Country
106 |
107 | # export
108 | def on_update(self):
109 | """
110 | Writes the .txt for this page and if write_content is checked,
111 | it will write out a .html file
112 | """
113 | path = export_module_json(self, self.is_standard, self.module)
114 |
115 | if path:
116 | # js
117 | if not os.path.exists(path + '.js'):
118 | with open(path + '.js', 'w') as f:
119 | f.write("""frappe.ready(function() {
120 | // bind events here
121 | })""")
122 |
123 | # py
124 | if not os.path.exists(path + '.py'):
125 | with open(path + '.py', 'w') as f:
126 | f.write("""from __future__ import unicode_literals
127 |
128 | import frappe
129 |
130 | def get_context(context):
131 | # do your desk here
132 | pass
133 | """)
134 |
135 | def get_parents(self, context):
136 | parents = None
137 |
138 | if context.is_list and not context.parents:
139 | parents = [{"title": _("My Account"), "name": "me"}]
140 | elif context.parents:
141 | parents = context.parents
142 |
143 | return parents
144 |
145 | def set_desk_form_module(self):
146 | '''Get custom web form module if exists'''
147 | self.desk_form_module = self.get_desk_form_module()
148 |
149 | def get_desk_form_module(self):
150 | if self.is_standard:
151 | return get_doc_module(self.module, self.doctype, self.name)
152 |
153 | def validate_mandatory(self, doc):
154 | '''Validate mandatory web form fields'''
155 | missing = []
156 | for f in self.desk_form_fields:
157 | if f.reqd and doc.get(f.fieldname) in (None, [], ''):
158 | missing.append(f)
159 |
160 | if missing:
161 | frappe.throw(_('Mandatory Information missing:') + '
'
162 | + '
'.join(['{0} ({1})'.format(d.label, d.fieldtype) for d in missing]))
163 |
164 |
165 | @frappe.whitelist()
166 | def accept(desk_form, data, doc_name=None):
167 | '''Save the desk form'''
168 | data = frappe._dict(json.loads(data))
169 | doctype = data.doctype if not data.doctype else frappe.db.get_value('Desk Form', desk_form, 'doc_type')
170 |
171 | files = []
172 | files_to_delete = []
173 |
174 | desk_form = frappe.get_doc("Desk Form", desk_form)
175 |
176 | if data.name and not desk_form.allow_edit:
177 | frappe.throw(_("You are not allowed to update this Desk Form Document"))
178 |
179 | frappe.flags.in_desk_form = True
180 | meta = frappe.get_meta(doctype)
181 |
182 | doc = get_doc(doctype, doc_name)
183 |
184 | # set values
185 | for field in desk_form.desk_form_fields:
186 | fieldname = field.fieldname# or field.label.replace(' ', '_').lower()
187 | #frappe.throw(fieldname)
188 | df = meta.get_field(fieldname)
189 | value = data.get(fieldname, None)
190 |
191 | if df and df.fieldtype in ('Attach', 'Attach Image'):
192 | if value and 'data:' and 'base64' in value:
193 | files.append((fieldname, value))
194 | if not doc.name:
195 | doc.set(fieldname, '')
196 | continue
197 |
198 | elif not value and doc.get(fieldname):
199 | files_to_delete.append(doc.get(fieldname))
200 |
201 | doc.set(fieldname, value)
202 |
203 | if doc.new:
204 | # insert
205 | if desk_form.login_required and frappe.session.user == "Guest":
206 | frappe.throw(_("You must login to submit this form"))
207 |
208 | ignore_mandatory = True if files else False
209 |
210 | doc.insert(ignore_permissions=True, ignore_mandatory=ignore_mandatory)
211 | else:
212 | if has_desk_form_permission(doctype, doc.name, "write"):
213 | doc.save(ignore_permissions=True)
214 | else:
215 | # only if permissions are present
216 | doc.save()
217 |
218 | # add files
219 | if files:
220 | for f in files:
221 | fieldname, filedata = f
222 |
223 | # remove earlier attached file (if exists)
224 | if doc.get(fieldname):
225 | remove_file_by_url(doc.get(fieldname), doctype=doctype, name=doc.name)
226 |
227 | # save new file
228 | filename, dataurl = filedata.split(',', 1)
229 | _file = frappe.get_doc({
230 | "doctype": "File",
231 | "file_name": filename,
232 | "attached_to_doctype": doctype,
233 | "attached_to_name": doc.name,
234 | "content": dataurl,
235 | "decode": True})
236 | _file.save()
237 |
238 | # update values
239 | doc.set(fieldname, _file.file_url)
240 |
241 | doc.save(ignore_permissions = True)
242 |
243 | if files_to_delete:
244 | for f in files_to_delete:
245 | if f:
246 | remove_file_by_url(doc.get(fieldname), doctype=doctype, name=doc.name)
247 |
248 |
249 | frappe.flags.desk_form_doc = doc
250 |
251 | return doc
252 |
253 |
254 | def has_desk_form_permission(doctype, name, ptype='read'):
255 | if frappe.session.user=="Guest":
256 | return False
257 |
258 | # owner matches
259 | elif frappe.db.get_value(doctype, name, "owner")==frappe.session.user:
260 | return True
261 |
262 | elif frappe.has_website_permission(name, ptype=ptype, doctype=doctype):
263 | return True
264 |
265 | elif check_webform_perm(doctype, name):
266 | return True
267 |
268 | else:
269 | return False
270 |
271 |
272 | def check_webform_perm(doctype, name):
273 | doc = frappe.get_doc(doctype, name)
274 | if hasattr(doc, "has_webform_permission"):
275 | if doc.has_webform_permission():
276 | return True
277 |
278 | @frappe.whitelist(allow_guest=False)
279 | def get_desk_form_filters(desk_form_name):
280 | desk_form = frappe.get_doc("Desk Form", desk_form_name)
281 | return [field for field in desk_form.desk_form_fields if field.show_in_filter]
282 |
283 |
284 | @frappe.whitelist(allow_guest=False)
285 | def get_fetch_values(doctype, txt, searchfield, start, page_len, filters):
286 | if not frappe.has_permission(doctype):
287 | frappe.msgprint(_("No Permission"), raise_exception=True)
288 |
289 | if not filters:
290 | filters = {}
291 |
292 | filters.update({searchfield: ["like", "%" + txt + "%"]})
293 |
294 | return frappe.get_all(doctype, fields=["name", searchfield], filters=filters,
295 | order_by=searchfield, limit_start=start, limit_page_length=page_len)
296 |
297 |
298 | @frappe.whitelist(allow_guest=False)
299 | def get_doc(doctype, doc_name=None):
300 | name = frappe.db.get_value(doctype, {"name": doc_name}) if doc_name else None
301 |
302 | if name:
303 | doc = frappe.get_doc(doctype, name)
304 | doc.new = False
305 | else:
306 | doc = frappe.new_doc(doctype)
307 | if doc_name:
308 | doc.set("name", doc_name)
309 | doc.new = True
310 |
311 | method = getattr(doc, 'onload', None)
312 | if callable(method):
313 | doc.onload()
314 |
315 | return doc
316 |
317 | @frappe.whitelist(allow_guest=False)
318 | def get_form(form_name=None):
319 | desk_form = frappe.get_doc('Desk Form', form_name)
320 |
321 | if desk_form.login_required and frappe.session.user == 'Guest':
322 | frappe.throw(_("Not Permitted"), frappe.PermissionError)
323 |
324 | out = frappe._dict()
325 | out.desk_form = desk_form
326 |
327 | # For Table fields, server-side processing for meta
328 | for field in out.desk_form.desk_form_fields:
329 | if field.fieldtype == "Table":
330 | field.fields = get_in_list_view_fields(field.options)
331 | out.update({field.fieldname: field.fields})
332 |
333 | return out
334 |
335 | @frappe.whitelist(allow_guest=False)
336 | def get_form_data(form_name=None, doc_name=None):
337 | desk_form = frappe.get_doc('Desk Form', form_name)
338 |
339 | if desk_form.login_required and frappe.session.user == 'Guest':
340 | frappe.throw(_("Not Permitted"), frappe.PermissionError)
341 |
342 | out = frappe._dict()
343 | out.desk_form = desk_form
344 |
345 | if frappe.session.user != 'Guest' and not doc_name and not desk_form.allow_multiple:
346 | doc_name = frappe.db.get_value(
347 | desk_form.doc_type, {"owner": frappe.session.user}, "name")
348 |
349 | doc = get_doc(desk_form.doc_type, doc_name)
350 | out.doc = doc
351 | #if doc_name:
352 | # doc = frappe.get_doc(desk_form.doc_type, doc_name)
353 | # out.doc = doc
354 |
355 | # For Table fields, server-side processing for meta
356 | for field in out.desk_form.desk_form_fields:
357 | if field.fieldtype == "Table":
358 | field.fields = get_in_list_view_fields(field.options)
359 | out.update({field.fieldname: field.fields})
360 |
361 | return out
362 |
363 | @frappe.whitelist()
364 | def get_in_list_view_fields(doctype):
365 | meta = frappe.get_meta(doctype)
366 | fields = []
367 |
368 | if meta.title_field:
369 | fields.append(meta.title_field)
370 | else:
371 | fields.append('name')
372 |
373 | if meta.has_field('status'):
374 | fields.append('status')
375 |
376 | fields += [df.fieldname for df in meta.fields if df.in_list_view and df.fieldname not in fields]
377 |
378 | def get_field_df(fieldname):
379 | if fieldname == 'name':
380 | return { 'label': 'Name', 'fieldname': 'name', 'fieldtype': 'Data' }
381 | return meta.get_field(fieldname).as_dict()
382 |
383 | return [get_field_df(f) for f in fields]
384 |
385 | @frappe.whitelist(allow_guest=True)
386 | def get_link_options(desk_form_name, doctype, allow_read_on_all_link_options=False):
387 | desk_form_doc = frappe.get_doc("Desk Form", desk_form_name)
388 | doctype_validated = False
389 | limited_to_user = False
390 | if desk_form_doc.login_required:
391 | # check if frappe session user is not guest or admin
392 | if frappe.session.user != 'Guest':
393 | doctype_validated = True
394 |
395 | if not allow_read_on_all_link_options:
396 | limited_to_user = True
397 |
398 | else:
399 | for field in desk_form_doc.desk_form_fields:
400 | if field.options == doctype:
401 | doctype_validated = True
402 | break
403 |
404 | if doctype_validated:
405 | link_options = []
406 | if limited_to_user:
407 | link_options = "\n".join([doc.name for doc in frappe.get_all(doctype, filters = {"owner":frappe.session.user})])
408 | else:
409 | link_options = "\n".join([doc.name for doc in frappe.get_all(doctype)])
410 |
411 | return link_options
412 |
413 | else:
414 | raise frappe.PermissionError('Not Allowed, {0}'.format(doctype))
415 |
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form/templates/desk_form.html:
--------------------------------------------------------------------------------
1 | {% extends "templates/web.html" %}
2 |
3 | {% block page_content %}
4 | {{ title }}
5 | {% endblock %}
6 |
7 |
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form/templates/desk_form_row.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form/test_desk_form.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Copyright (c) 2021, Quantum Bit Core and Contributors
3 | # See license.txt
4 | from __future__ import unicode_literals
5 |
6 | # import frappe
7 | import unittest
8 |
9 | class TestDeskForm(unittest.TestCase):
10 | pass
11 |
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form_field/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/frappe_helper/doctype/desk_form_field/__init__.py
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form_field/desk_form_field.json:
--------------------------------------------------------------------------------
1 | {
2 | "actions": [],
3 | "creation": "2021-07-15 19:10:01.107899",
4 | "doctype": "DocType",
5 | "editable_grid": 1,
6 | "engine": "InnoDB",
7 | "field_order": [
8 | "fieldname",
9 | "fieldtype",
10 | "label",
11 | "allow_read_on_all_link_options",
12 | "reqd",
13 | "depends_on",
14 | "read_only",
15 | "show_in_filter",
16 | "hidden",
17 | "extra_field",
18 | "collapsible",
19 | "column_break_4",
20 | "options",
21 | "max_length",
22 | "max_value",
23 | "fetch_from",
24 | "fetch_if_empty",
25 | "section_break_6",
26 | "description",
27 | "column_break_8",
28 | "default"
29 | ],
30 | "fields": [
31 | {
32 | "fieldname": "fieldname",
33 | "fieldtype": "Select",
34 | "in_list_view": 1,
35 | "label": "Fieldname"
36 | },
37 | {
38 | "fieldname": "fieldtype",
39 | "fieldtype": "Select",
40 | "in_list_view": 1,
41 | "label": "Fieldtype",
42 | "options": "Attach\nAttach Image\nBarcode\nButton\nCheck\nCode\nColor\nColumn Break\nCurrency\nData\nDate\nDatetime\nDynamic Link\nFloat\nFold\nGeolocation\nHeading\nHTML\nHTML Editor\nImage\nInt\nLink\nLong Text\nMarkdown Editor\nPassword\nPercent\nRead Only\nRating\nSection Break\nSelect\nSmall Text\nTable\nTable MultiSelect\nText\nText Editor\nTime\nSignature"
43 | },
44 | {
45 | "fieldname": "label",
46 | "fieldtype": "Data",
47 | "in_list_view": 1,
48 | "label": "Label"
49 | },
50 | {
51 | "default": "0",
52 | "depends_on": "eval:doc.fieldtype === 'Link'",
53 | "fieldname": "allow_read_on_all_link_options",
54 | "fieldtype": "Check",
55 | "label": "Allow Read On All Link Options"
56 | },
57 | {
58 | "default": "0",
59 | "fieldname": "reqd",
60 | "fieldtype": "Check",
61 | "label": "Mandatory"
62 | },
63 | {
64 | "fieldname": "depends_on",
65 | "fieldtype": "Code",
66 | "label": "Depends On"
67 | },
68 | {
69 | "default": "0",
70 | "fieldname": "read_only",
71 | "fieldtype": "Check",
72 | "label": "Read Only"
73 | },
74 | {
75 | "default": "0",
76 | "fieldname": "show_in_filter",
77 | "fieldtype": "Check",
78 | "label": "Show in filter"
79 | },
80 | {
81 | "default": "0",
82 | "fieldname": "hidden",
83 | "fieldtype": "Check",
84 | "label": "Hidden"
85 | },
86 | {
87 | "fieldname": "column_break_4",
88 | "fieldtype": "Column Break"
89 | },
90 | {
91 | "fieldname": "options",
92 | "fieldtype": "Text",
93 | "in_list_view": 1,
94 | "label": "Options"
95 | },
96 | {
97 | "fieldname": "max_length",
98 | "fieldtype": "Int",
99 | "label": "Max Length"
100 | },
101 | {
102 | "depends_on": "eval:doc.fieldtype=='Int'",
103 | "fieldname": "max_value",
104 | "fieldtype": "Int",
105 | "label": "Max Value"
106 | },
107 | {
108 | "fieldname": "section_break_6",
109 | "fieldtype": "Section Break"
110 | },
111 | {
112 | "fieldname": "description",
113 | "fieldtype": "Text",
114 | "label": "Description"
115 | },
116 | {
117 | "fieldname": "column_break_8",
118 | "fieldtype": "Column Break"
119 | },
120 | {
121 | "fieldname": "default",
122 | "fieldtype": "Data",
123 | "label": "Default"
124 | },
125 | {
126 | "default": "0",
127 | "fieldname": "extra_field",
128 | "fieldtype": "Check",
129 | "label": "Extra Field"
130 | },
131 | {
132 | "fieldname": "fetch_from",
133 | "fieldtype": "Small Text",
134 | "label": "Fetch From"
135 | },
136 | {
137 | "default": "0",
138 | "fieldname": "fetch_if_empty",
139 | "fieldtype": "Check",
140 | "label": "Fetch If Empty"
141 | },
142 | {
143 | "default": "0",
144 | "fieldname": "collapsible",
145 | "fieldtype": "Check",
146 | "label": "Collapsible"
147 | }
148 | ],
149 | "istable": 1,
150 | "links": [],
151 | "modified": "2022-11-25 16:02:05.981701",
152 | "modified_by": "Administrator",
153 | "module": "Frappe Helper",
154 | "name": "Desk Form Field",
155 | "owner": "Administrator",
156 | "permissions": [],
157 | "sort_field": "modified",
158 | "sort_order": "DESC"
159 | }
--------------------------------------------------------------------------------
/frappe_helper/frappe_helper/doctype/desk_form_field/desk_form_field.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Copyright (c) 2021, Quantum Bit Core and contributors
3 | # For license information, please see license.txt
4 |
5 | from __future__ import unicode_literals
6 | # import frappe
7 | from frappe.model.document import Document
8 |
9 | class DeskFormField(Document):
10 | pass
11 |
--------------------------------------------------------------------------------
/frappe_helper/hooks.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 | from . import __version__ as app_version
4 |
5 | app_name = "frappe_helper"
6 | app_title = "Frappe Helper"
7 | app_publisher = "Quantum Bit Core"
8 | app_description = "Frappe Helper"
9 | app_icon = "octicon octicon-file-directory"
10 | app_color = "grey"
11 | app_email = "quantumbitcore.io@gmail.com"
12 | app_license = "MIT"
13 |
14 | app_include_css = [
15 | "/assets/frappe_helper/css/desk-form.css",
16 | "/assets/frappe_helper/css/frappe-helper.css",
17 | "/assets/frappe_helper/css/num-pad.css",
18 | ]
19 |
20 | after_migrate = "frappe_helper.setup.install.after_install"
21 | after_install = "frappe_helper.setup.install.after_install"
22 |
23 | # Includes in
24 | # ------------------
25 |
26 | # include js, css files in header of desk.html
27 | app_include_js = [
28 | "/assets/frappe_helper/js/jshtml-class.js",
29 | "/assets/frappe_helper/js/num-pad-class.js",
30 | "/assets/frappe_helper/js/desk-modal.js",
31 | "/assets/frappe_helper/js/frappe-helper-api.js",
32 | "/assets/frappe_helper/js/frappe-form-class.js",
33 | "/assets/frappe_helper/js/desk-form-class.js"
34 | ]
35 |
36 |
37 | # Includes in
38 | # ------------------
39 |
40 | # include js, css files in header of desk.html
41 | # app_include_css = "/assets/frappe_helper/css/frappe_helper.css"
42 | # app_include_js = "/assets/frappe_helper/js/frappe_helper.js"
43 |
44 | # include js, css files in header of web template
45 | # web_include_css = "/assets/frappe_helper/css/frappe_helper.css"
46 | # web_include_js = "/assets/frappe_helper/js/frappe_helper.js"
47 |
48 | # include custom scss in every website theme (without file extension ".scss")
49 | # website_theme_scss = "frappe_helper/public/scss/website"
50 |
51 | # include js, css files in header of web form
52 | # webform_include_js = {"doctype": "public/js/doctype.js"}
53 | # webform_include_css = {"doctype": "public/css/doctype.css"}
54 |
55 | # include js in page
56 | # page_js = {"page" : "public/js/file.js"}
57 |
58 | # include js in doctype views
59 | # doctype_js = {"doctype" : "public/js/doctype.js"}
60 | # doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
61 | # doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
62 | # doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}
63 |
64 | # Home Pages
65 | # ----------
66 |
67 | # application home page (will override Website Settings)
68 | # home_page = "login"
69 |
70 | # website user home page (by Role)
71 | # role_home_page = {
72 | # "Role": "home_page"
73 | # }
74 |
75 | # Generators
76 | # ----------
77 |
78 | # automatically create page for each record of this doctype
79 | # website_generators = ["Web Page"]
80 |
81 | # Installation
82 | # ------------
83 |
84 | # before_install = "frappe_helper.install.before_install"
85 | # after_install = "frappe_helper.install.after_install"
86 |
87 | # Desk Notifications
88 | # ------------------
89 | # See frappe.core.notifications.get_notification_config
90 |
91 | # notification_config = "frappe_helper.notifications.get_notification_config"
92 |
93 | # Permissions
94 | # -----------
95 | # Permissions evaluated in scripted ways
96 |
97 | # permission_query_conditions = {
98 | # "Event": "frappe.desk.doctype.event.event.get_permission_query_conditions",
99 | # }
100 | #
101 | # has_permission = {
102 | # "Event": "frappe.desk.doctype.event.event.has_permission",
103 | # }
104 |
105 | # DocType Class
106 | # ---------------
107 | # Override standard doctype classes
108 |
109 | # override_doctype_class = {
110 | # "ToDo": "custom_app.overrides.CustomToDo"
111 | # }
112 |
113 | # Document Events
114 | # ---------------
115 | # Hook on document methods and events
116 |
117 | # doc_events = {
118 | # "*": {
119 | # "on_update": "method",
120 | # "on_cancel": "method",
121 | # "on_trash": "method"
122 | # }
123 | # }
124 |
125 | # Scheduled Tasks
126 | # ---------------
127 |
128 | # scheduler_events = {
129 | # "all": [
130 | # "frappe_helper.tasks.all"
131 | # ],
132 | # "daily": [
133 | # "frappe_helper.tasks.daily"
134 | # ],
135 | # "hourly": [
136 | # "frappe_helper.tasks.hourly"
137 | # ],
138 | # "weekly": [
139 | # "frappe_helper.tasks.weekly"
140 | # ]
141 | # "monthly": [
142 | # "frappe_helper.tasks.monthly"
143 | # ]
144 | # }
145 |
146 | # Testing
147 | # -------
148 |
149 | # before_tests = "frappe_helper.install.before_tests"
150 |
151 | # Overriding Methods
152 | # ------------------------------
153 | #
154 | # override_whitelisted_methods = {
155 | # "frappe.desk.doctype.event.event.get_events": "frappe_helper.event.get_events"
156 | # }
157 | #
158 | # each overriding function accepts a `data` argument;
159 | # generated from the base implementation of the doctype dashboard,
160 | # along with any modifications made in other Frappe apps
161 | # override_doctype_dashboards = {
162 | # "Task": "frappe_helper.task.get_dashboard_data"
163 | # }
164 |
165 | # exempt linked doctypes from being automatically cancelled
166 | #
167 | # auto_cancel_exempted_doctypes = ["Auto Repeat"]
168 |
169 |
170 | # User Data Protection
171 | # --------------------
172 |
173 | user_data_fields = [
174 | {
175 | "doctype": "{doctype_1}",
176 | "filter_by": "{filter_by}",
177 | "redact_fields": ["{field_1}", "{field_2}"],
178 | "partial": 1,
179 | },
180 | {
181 | "doctype": "{doctype_2}",
182 | "filter_by": "{filter_by}",
183 | "partial": 1,
184 | },
185 | {
186 | "doctype": "{doctype_3}",
187 | "strict": False,
188 | },
189 | {
190 | "doctype": "{doctype_4}"
191 | }
192 | ]
193 |
194 |
--------------------------------------------------------------------------------
/frappe_helper/modules.txt:
--------------------------------------------------------------------------------
1 | Frappe Helper
--------------------------------------------------------------------------------
/frappe_helper/patches.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/patches.txt
--------------------------------------------------------------------------------
/frappe_helper/public/css/desk-form.css:
--------------------------------------------------------------------------------
1 | .desk-form .grid-delete-row,
2 | .desk-form .grid-duplicate-row,
3 | .desk-form .grid-move-row,
4 | .desk-form .grid-append-row,
5 | .desk-form .grid-insert-row,
6 | .desk-form .grid-remove-all-rows,
7 | .desk-form .grid-insert-row-below {
8 | display: none !important;
9 | }
10 |
11 | .custom-widget {
12 | margin-bottom: 10px;
13 | }
14 |
15 | .custom-widget .widget {
16 | padding: 8px;
17 | }
--------------------------------------------------------------------------------
/frappe_helper/public/css/frappe-helper.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --default-line: 1px solid rgba(119, 136, 153, 0.39);
3 | --fill-color: rgba(119, 136, 153, 0.07);
4 | --selected-color: rgba(119, 136, 153, 0.39);
5 | --margin-grid: 5px;
6 | }
7 |
8 | .jstmlefc65a6efc9cb8afbc85 {
9 | opacity: 0.4;
10 | pointer-events: none !important;
11 | cursor: not-allowed !important;
12 | filter: alpha(opacity=50);
13 | -webkit-box-shadow: none;
14 | box-shadow: none;
15 | -moz-user-select: none;
16 | -webkit-user-select: none;
17 | -ms-user-select: none;
18 | user-select: none;
19 | }
20 |
21 | .jstmlefc65a6efc9cb8afbc85-confirm {
22 | background-color: #ff5900 !important;
23 | color: #ffffff !important;
24 | font-weight: bold;
25 | animation: blinker 1.5s linear infinite;
26 | }
27 |
28 | @keyframes blinker {
29 | 50% {
30 | opacity: 0.5;
31 | }
32 | }
33 |
34 | .pdf-container {
35 | background: linear-gradient(-45deg, #161e23, #414449, #1d2226, #494c4f);
36 | background-size: 400% 400%;
37 | animation: gradient 15s ease infinite;
38 | }
39 |
40 | @keyframes gradient {
41 | 0% {
42 | background-position: 0 50%;
43 | }
44 | 50% {
45 | background-position: 100% 50%;
46 | }
47 | 100% {
48 | background-position: 0 50%;
49 | }
50 | }
--------------------------------------------------------------------------------
/frappe_helper/public/css/num-pad.css:
--------------------------------------------------------------------------------
1 | .pad-container {
2 | position: relative;
3 | width: calc(100% + 4px);
4 | height: calc(100% + 4px);
5 | border-collapse: separate;
6 | margin-left: -2px;
7 | }
8 |
9 | .pad-container .pad-col.pad-btn {
10 | background-color: var(--fg-color);
11 | border-color: rgba(119, 136, 153, 0.39);
12 | border-width: 1px;
13 | border-style: ridge;
14 | }
15 |
16 | .pad-container .pad-col.pad-btn.btn-success {
17 | background-color: var(--success);
18 | }
19 |
20 | .pad-container .pad-col.pad-btn.btn-success:hover {
21 | background-color: rgba(3, 121, 49, 0.6);
22 | }
23 |
24 | .pad-container .pad-btn:hover {
25 | background-color: rgba(37, 75, 111, 0.03);
26 | }
27 |
28 | .pad-container .pad-col {
29 | width: 100%;
30 | -webkit-user-select: none;
31 | -moz-user-select: none;
32 | -ms-user-select: none;
33 | user-select: none;
34 | -webkit-box-shadow: none;
35 | text-align: center;
36 | cursor: pointer;
37 | margin-bottom: 0;
38 | font-weight: 400;
39 | white-space: nowrap;
40 | vertical-align: middle;
41 | -ms-touch-action: manipulation;
42 | touch-action: manipulation;
43 | background-image: none;
44 | padding: 6px 12px;
45 | font-size: 14px;
46 | line-height: 1.42857143;
47 | box-shadow: none;
48 | border-radius: 3px;
49 | }
50 |
51 | .pad-container .pad-col.disabled {
52 | pointer-events: none;
53 | color: #a9a9a9 !important;
54 | }
55 |
56 | .pad-container .pad-row {
57 | height: 25%;
58 | }
59 |
60 | .pad-container .pad-col.sm {
61 | width: 15%;
62 | }
63 |
64 | .pad-container .pad-col.md {
65 | width: 20%;
66 | }
67 |
68 | .pad-container .pad-col.lg {
69 | text-align: left;
70 | width: 35%;
71 | }
72 |
73 | .pad-container .pad-col.text-lg {
74 | font-size: 25px;
75 | }
76 |
77 | .pad-container .pad-col span {
78 | font-size: 20px;
79 | }
80 |
81 | .pad-container .pad-label {
82 | background-color: transparent;
83 | text-align: right !important;
84 | padding: 0 10px 0 0;
85 | cursor: default;
86 | }
87 |
88 | .pad-container .pad-label.label-lg {
89 | font-size: 25px !important;
90 | }
--------------------------------------------------------------------------------
/frappe_helper/public/js/desk-form-class.js:
--------------------------------------------------------------------------------
1 | class DeskForm extends FrappeForm {
2 | is_hide = true;
3 | has_footer = true;
4 | has_primary_action = true;
5 | base_url = "frappe_helper.frappe_helper.doctype.desk_form.desk_form.";
6 |
7 | constructor(options) {
8 | super(options);
9 |
10 | this.in_modal = !this.location;
11 | if (this.form_name) this.initialize();
12 | }
13 |
14 | remove(){
15 | this.$$wrapper.remove();
16 | }
17 |
18 | get $$wrapper() {
19 | return this.in_modal ? $(this._wrapper.$wrapper) : this._wrapper;
20 | }
21 |
22 | get parent() {
23 | return this.body;
24 | }
25 |
26 | get body() {
27 | return this.in_modal ? $(this._wrapper.$wrapper).find('.modal-body') : this._wrapper;
28 | }
29 |
30 | get footer() {
31 | return this.in_modal ? $(this._wrapper.$wrapper).find('.modal-footer') : this.body;
32 | }
33 |
34 | get footer_buttons_wrapper() {
35 | return this.footer.find('.standard-actions');
36 | }
37 |
38 | get primary_btn() {
39 | return this.footer.find('.btn-primary');
40 | }
41 |
42 | get_primary_btn() {
43 | return this.primary_btn;
44 | }
45 |
46 | field(field_name) {
47 | return this.in_modal ? this._wrapper.fields_dict[field_name].$wrapper : null;
48 | }
49 |
50 | get_value(fieldname) {
51 | if(Array.isArray(fieldname)){
52 | const values = [];
53 | fieldname.forEach(field => {
54 | values.push(this.get_value(field));
55 | });
56 | return values;
57 | }
58 |
59 | return super.get_value(fieldname);
60 | }
61 |
62 | async initialize() {
63 | if(this.location){
64 | this.location.append(``);
65 | this._wrapper = this.location.find('.desk-form');
66 | }else{
67 | this._wrapper = new frappe.ui.Dialog({
68 | title: this.title,
69 | on_hide: () => {
70 | close_grid_and_dialog();
71 | }
72 | });
73 | }
74 |
75 | await super.initialize();
76 |
77 | function close_grid_and_dialog() {
78 | // close open grid row
79 | var open_row = $(".grid-row-open");
80 | if (open_row.length) {
81 | var grid_row = open_row.data("grid_row");
82 | grid_row.toggle_view(false);
83 | return false;
84 | }
85 |
86 | // close open dialog
87 | if (cur_dialog && !cur_dialog.no_cancel_flag) {
88 | //cur_dialog.cancel();
89 | return false;
90 | }
91 | }
92 |
93 | this.in_modal && this._wrapper && this._wrapper.wrapper.classList.add('modal-lg');
94 |
95 | this.body.show();
96 | this.show();
97 | }
98 |
99 | execute_primary_action() {
100 | this.primary_btn.focus();
101 |
102 | if (this.primary_action) {
103 | this.last_data ??= JSON.stringify(this.doc);
104 | if (this.last_data != JSON.stringify(this.doc)) {
105 | this.last_data = JSON.stringify(this.doc);
106 | this.primary_action();
107 | }
108 | } else {
109 | this.save();
110 | }
111 | }
112 |
113 | async make() {
114 | await super.make();
115 |
116 | this.customize();
117 |
118 | if (this.has_primary_action && this.in_modal) {
119 | const button = this.primary_btn;
120 | if(button){
121 | button.on('click', (event) => {
122 | event.preventDefault();
123 | event.stopPropagation();
124 | this.execute_primary_action();
125 | });
126 |
127 | button.text(this.primary_action_label || __('Save'));
128 | button.removeClass('hide');
129 | }
130 |
131 | this.footer.removeClass('hide');
132 | this.footer.css('display', 'flex');
133 | }else{
134 | this.footer.hide();
135 | }
136 |
137 | this.make_custom_buttons_wrapper();
138 | }
139 |
140 | customize() {
141 | this.body.addClass('desk-form-body');
142 | }
143 |
144 | load() {
145 | this.before_load && this.before_load();
146 | super.initialize();
147 | this.initialize_fetches();
148 | }
149 |
150 | set_value(fieldname, value, on_reload=false) {
151 | const field = this.get_field(fieldname);
152 | if (field) {
153 | field.set_value && typeof field.set_value === "function" && field.set_value(value);
154 | }
155 | }
156 |
157 | async reload(doc=null, from_server=false) {
158 | this.reloading = true;
159 | this.before_load && this.before_load();
160 | this.doc = doc || await this.get_doc(from_server);
161 |
162 | this.doc = JSON.parse(JSON.stringify(this.doc));
163 |
164 | this.refresh();
165 |
166 | this.customize();
167 | this.reloading = false;
168 |
169 | setTimeout(() => {
170 | if(this.on_reload && typeof this.on_reload === "function"){
171 | this.on_reload();
172 | }
173 | this.reloading = false;
174 | }, 100);
175 |
176 | return this;
177 | }
178 |
179 | background_reload() {
180 | this.get_doc(true).then(doc => {
181 | this.doc = JSON.parse(JSON.stringify(doc));
182 | this.refresh();
183 | });
184 | }
185 |
186 | show() {
187 | this.is_hide = false;
188 | this._wrapper.show();
189 | return this;
190 | }
191 |
192 | hide() {
193 | this.is_hide = true;
194 | this._wrapper.hide();
195 | return this;
196 | }
197 |
198 | hide_field(fieldname) {
199 | if(Array.isArray(fieldname)){
200 | fieldname.forEach(field => {
201 | this.hide_field(field);
202 | });
203 | }else{
204 | this.set_field_display(fieldname, true);
205 | }
206 | }
207 |
208 | super_container_field(fieldname) {
209 | return $(this.get_field(fieldname).$wrapper.parent()[0]).parent()[0]
210 | }
211 |
212 |
213 | show_field(fieldname) {
214 | if(Array.isArray(fieldname)){
215 | fieldname.forEach(field => {
216 | this.show_field(field);
217 | });
218 | }else{
219 | this.set_field_display(fieldname, false);
220 | }
221 | }
222 |
223 | set_field_display(fieldname, hide) {
224 | const field = this.get_field(fieldname);
225 | if (field) {
226 | //field.df.hidden = hide;
227 | //field.refresh();
228 | field.$wrapper[hide ? 'hide' : 'show']();
229 | }
230 | }
231 |
232 | toggle() {
233 | this.is_hide ? this.show() : this.hide();
234 | return this;
235 | }
236 |
237 | make_custom_buttons_wrapper() {
238 | this.body.append(`
239 |
242 | `)
243 | }
244 |
245 | add_action({ name, label, confirm = false, classes="", style="", type="default", icon="" } = {}, action) {
246 | this.actions ??= {};
247 |
248 | const wrapper = this.body.find(".custom-widget");
249 |
250 | wrapper.find(".widget-group-body").append(`
251 |
256 | ${this.#action_content("", label, icon)}
257 |
258 | `);
259 |
260 | this.actions[name] = frappe.jshtml({
261 | from_html: wrapper.find(`[data-widget-name="${name}"]`).get(0),
262 | content: this.#action_content("", "{{text}}", icon),
263 | text: `${__(label)}`
264 | }).on("click", () => {
265 | action && action();
266 | }, confirm ? DOUBLE_CLICK : null);
267 | }
268 |
269 | #action_content(value, template = "", icon = "") {
270 | return `
271 | `
280 | }
281 | }
--------------------------------------------------------------------------------
/frappe_helper/public/js/desk-modal.js:
--------------------------------------------------------------------------------
1 | class DeskModal {
2 | constructor(options) {
3 | Object.assign(this, options);
4 | this.id = "desk-modal-" + Math.random().toString(36).substr(2, 15);
5 | this.modal = null;
6 | this.construct();
7 | }
8 |
9 | set_props(props){
10 | Object.assign(this, props);
11 | }
12 |
13 | remove(){
14 | this.modal && this.modal.$wrapper.remove();
15 | }
16 |
17 | construct(){
18 | this.modal = new frappe.ui.Dialog({
19 | title: this.title,
20 | primary_action_label: __("Save")
21 | });
22 |
23 | this.show();
24 |
25 | if(this.full_page){
26 | this.modal.$wrapper.find('.modal-dialog').css({
27 | "width": "100%", "height": "100%", "left": "0", "top": "0", "margin": "0", "padding":"0", "border-style": "none",
28 | "max-width": "unset", "max-height": "unset"
29 | });
30 |
31 | this.modal.$wrapper.find('.modal-content').css({
32 | "width": "100%", "height": "100%", "left": "0", "top": "0", "border-style": "none", "border-radius": "0",
33 | "max-width": "unset", "max-height": "unset"
34 | });
35 | }
36 |
37 | setTimeout(() => {
38 | this.render();
39 | }, 200);
40 | }
41 |
42 | _adjust_height(){
43 | return typeof this.adjust_height == "undefined" ? 0 : this.adjust_height;
44 | }
45 |
46 | render(){
47 | this.set_title();
48 |
49 | if(typeof this.customize != "undefined"){
50 | this.modal.$wrapper.find(".modal-body").empty();
51 |
52 | this.modal.$wrapper.css({
53 | "height": `calc(100% - ${this._adjust_height()}px)`,
54 | "border-bottom": "var(--default-line)",
55 | });
56 |
57 | this.modal.$wrapper.find('.modal-header').css({
58 | "padding": "5px",
59 | "border-bottom": "var(--default-line)",
60 | "border-radius": "0",
61 | /*"min-height": "50px"*/
62 | });
63 |
64 | this.modal.$wrapper.find('.modal-body').css({
65 | "background-color": "transparent",
66 | "padding": "0",
67 | "border-style": "none",
68 | "border-radius": "0",
69 | "overflow-y": "auto"
70 | });
71 |
72 | this.modal.$wrapper.find('.modal-title').css({
73 | "margin": "0"
74 | });
75 |
76 | this.modal.$wrapper.find(".modal-actions").prepend("").css({
77 | "top": "5px"
78 | });
79 | }
80 |
81 | if(typeof this.from_server == "undefined") {
82 | if(this.callback){
83 | this.callback(this);
84 | }
85 | }else{
86 | this.load_data();
87 | }
88 | }
89 |
90 | set_title(title){
91 | this.modal.set_title(title);
92 | }
93 |
94 | get container(){return this.modal.$wrapper.find(".modal-body")}
95 | get title_container(){return this.modal.$wrapper.find(".modal-title")}
96 | get buttons_container(){return this.modal.$wrapper.find(".modal-actions .btn-container")}
97 |
98 | show(){
99 | this.modal.show();
100 | }
101 |
102 | hide(){
103 | this.modal.hide();
104 | }
105 |
106 | loading() {
107 | this.modal.fields_dict.ht.$wrapper.html(
108 | "" + __("Loading") + "...
"
109 | );
110 | }
111 |
112 | stop_loading() {
113 | //this.modal.fields_dict.ht.$wrapper.html("");
114 | }
115 |
116 | get _is_pdf(){
117 | return typeof this.is_pdf != "undefined" && this.is_pdf === true;
118 | }
119 |
120 | get _args() {
121 | let args = this.args;
122 | return (typeof args == "undefined" || args == null ? {} : this.args);
123 | }
124 |
125 | get _pdf_url(){
126 | let url = `/api/method/frappe.utils.print_format.download_pdf?doctype=${this.model}&name=${this.model_name}`;
127 | let args = Object.assign({
128 | no_letterhead: 1,
129 | letterhead: 'No%20Letterhead',
130 | settings: '%7B%7D'
131 | }, this._args);
132 |
133 | Object.keys(args).forEach(k => {
134 | url += '&' + k + '=' + args[k];
135 | });
136 |
137 | return url;
138 | }
139 |
140 | get pdf_template(){
141 | return `
142 |
147 | `;
148 | }
149 |
150 | load_data(){
151 | if(this._is_pdf){
152 | this.container.empty().append(this.pdf_template);
153 | }else{
154 | frappeHelper.api.call({
155 | model: this.model,
156 | name: this.model_name,
157 | method: this.action,
158 | args:{},
159 | always: (r) => {
160 | this.container.empty().append(r.message);
161 | this.stop_loading();
162 | if(this.callback){
163 | this.callback(this);
164 | }
165 | },
166 | });
167 | }
168 | }
169 |
170 | reload(){
171 | this.load_data();
172 | return this;
173 | }
174 | }
--------------------------------------------------------------------------------
/frappe_helper/public/js/frappe-form-class.js:
--------------------------------------------------------------------------------
1 | frappe.provide("frappe.ui");
2 |
3 | class FrappeForm extends frappe.ui.FieldGroup {
4 | background = false;
5 | buttons = {};
6 | button_label = "Save";
7 | fetch_dict = {};
8 |
9 | constructor(props) {
10 | super(props);
11 | }
12 |
13 | get_meta() {
14 | return this.#get("get_meta", {doctype: this.doctype});
15 | }
16 |
17 | async initialize() {
18 | this.form_name = this.desk_form ? this.desk_form.name : this.form_name;
19 | this.form_name = this.form_name.replaceAll(" ", "-").toLowerCase();
20 |
21 | if(!this.desk_form && !this.doc) {
22 | await this.get_all();
23 | }
24 |
25 | if(!this.desk_form) this.desk_form = await this.get_form();
26 | this.doctype = this.desk_form.doc_type;
27 |
28 | if (!this.doc && this.doc_name) this.doc = await this.get_doc();
29 | this.doc = JSON.parse(JSON.stringify(this.doc || {}));
30 |
31 | this.fields = this.desk_form.desk_form_fields;
32 |
33 | await this.make();
34 | }
35 |
36 | initialize_fetches() {
37 | this.desk_form.desk_form_fields.forEach(df => {
38 | if (df.fetch_from) {
39 | this.trigger(df.fetch_from.split(".")[0] , "change");
40 | }
41 | });
42 | }
43 |
44 | async make() {
45 | const setup_add_fetch = (df_fetch_from, df_fetch_to, parent=null) => {
46 | df_fetch_from.listeners ??= {};
47 | df_fetch_from.listeners.change ??= [];
48 |
49 | df_fetch_from.listeners.change.push(e => {
50 | if (parent) {
51 | const table_input = this.get_field(parent.fieldname).grid;
52 | const data = table_input.data;
53 |
54 | data.forEach((row, index) => {
55 | const row_input = table_input.get_row(index);
56 | const link_fetch = row_input.columns[df_fetch_from.fieldname].field;
57 |
58 | const target_fetch_inputs = Object.entries(df_fetch_to).map(([key, _df_fetch_to]) => {
59 | return row_input.columns[_df_fetch_to.fieldname].field
60 | }).reduce((acc, cur) => {
61 | if(cur) acc[cur.df.fieldname] = cur;
62 | return acc;
63 | }, {});
64 |
65 | this.fetch_link(link_fetch, target_fetch_inputs);
66 | });
67 | } else {
68 | const link_fetch = this.get_field(df_fetch_from.fieldname);
69 |
70 | const target_fetch_inputs = Object.entries(df_fetch_to).map(([key, df_fetch_to]) => {
71 | return this.get_field(df_fetch_to.fieldname);
72 | }).reduce((acc, cur) => {
73 | if(cur) acc[cur.df.fieldname] = cur;
74 | return acc;
75 | }, {});
76 |
77 | this.fetch_link(link_fetch, target_fetch_inputs);
78 | }
79 | });
80 |
81 | setTimeout(() => {
82 | df_fetch_from.listeners.change.forEach(listener => {
83 | this.on(df_fetch_from.fieldname, "change", (e) => {
84 | listener(e);
85 | });
86 | });
87 | }, 0);
88 | }
89 |
90 | return new Promise(resolve => {
91 | const fetches = {};
92 |
93 | const setup_fetch = (fields, df, parent=null) => {
94 | if (!df.fetch_from) return;
95 |
96 | const fetch_from = fields.find(field => field.fieldname === df.fetch_from.split(".")[0]) || {};
97 |
98 | if (([
99 | 'Data', 'Read Only', 'Text', 'Small Text', 'Currency', 'Check',
100 | 'Text Editor', 'Code', 'Link', 'Float', 'Int', 'Date', 'Select'
101 | ].includes(fetch_from.fieldtype) || [true, 1, "true", "1"].includes(fetch_from.read_only))) {
102 |
103 | const fetch_from_field = fetch_from.fieldname;
104 | const fetch_to = df.fieldname;
105 |
106 | fetches[fetch_from_field] ??= {};
107 | fetches[fetch_from_field].fetch_from = fetch_from;
108 | fetches[fetch_from_field].fetch_to ??= [];
109 | fetches[fetch_from_field].fetch_to[fetch_to] = df
110 | fetches[fetch_from_field].parent = parent;
111 | }
112 | }
113 |
114 | this.desk_form.desk_form_fields.forEach(df => {
115 | setup_fetch(this.desk_form.desk_form_fields, df);
116 |
117 | const get_field_from_field_properties = (fieldname, parent=null) => {
118 | if(this.field_properties){
119 | const field_props = this.field_properties[(parent ? parent + "." : "") + fieldname];
120 |
121 | return field_props || {};
122 | }
123 |
124 | return {}
125 | }
126 |
127 | if (df.fieldtype === 'Table') {
128 | df.get_data = () => {
129 | return this.doc ? this.doc[df.fieldname] : [];
130 | }
131 |
132 | if (this.data.hasOwnProperty(df.fieldname)) {
133 | df.fields = this.data[df.fieldname];
134 | }
135 |
136 | (df.fields || []).forEach((f, index) => {
137 |
138 | if (f.fieldname === 'name'){
139 | //const x = myArray.splice(index, 1);
140 | //df.fields.splice(index, 1);
141 | // f.read_only = 1;
142 | }else{
143 | setup_fetch(df.fields, f, df);
144 | Object.assign(f, get_field_from_field_properties(f.fieldname, df.fieldname))
145 | }
146 | });
147 |
148 | df.options = null;
149 |
150 | }else{
151 | Object.assign(df, get_field_from_field_properties(df.fieldname));
152 |
153 | if(df.read_only){
154 | df.doctype = null;
155 | df.docname = null;
156 | }
157 | }
158 |
159 | delete df.parent;
160 | delete df.parentfield;
161 | delete df.parenttype;
162 | delete df.doctype;
163 | });
164 |
165 | Object.values(fetches).forEach(fetch => {
166 | setup_add_fetch(fetch.fetch_from, fetch.fetch_to, fetch.parent);
167 | });
168 |
169 | super.make();
170 |
171 | setTimeout(() => {
172 | this.after_load && this.after_load(this);
173 | this.initialize_fetches();
174 | }, 200);
175 |
176 | resolve();
177 | });
178 | }
179 |
180 |
181 | fetch_link(link_fetch, fetches_to={}) {
182 | if (Object.keys(fetches_to).length === 0) return;
183 |
184 | const doctype = link_fetch.df.options;
185 | const from_cols = Object.values(fetches_to).map((fetch_to_df) => fetch_to_df.df.fetch_from.split('.')[1]);
186 | const doc_name = link_fetch.get_value();
187 |
188 | //if (link_fetch.last_value === doc_name) return;
189 | link_fetch.last_value = doc_name;
190 |
191 | frappe.call({
192 | method: 'frappe_helper.api.validate_link',
193 | type: "GET",
194 | args: {
195 | 'value': doc_name,
196 | 'options': doctype,
197 | 'fetch': from_cols.join(",")
198 | },
199 | no_spinner: true,
200 | callback: (r) => {
201 | const fetch_values = r.fetch_values || [];
202 | Object.values(fetches_to).map((fetch_to_df, index) => fetch_to_df.set_value(r.message == 'Ok' ? fetch_values[index] : ''));
203 | }
204 | });
205 | }
206 |
207 | refresh() {
208 | super.refresh(this.doc);
209 |
210 | this.refresh_fields();
211 | this.on_refresh && this.on_refresh();
212 | }
213 |
214 | refresh_fields(){
215 | const listeners = Object.assign({}, this.listeners || {});
216 | this.listeners = {};
217 |
218 | this.desk_form.desk_form_fields.forEach(df => {
219 | if (df.read_only) {
220 | df.doctype = null;
221 | df.docname = null;
222 |
223 | this.set_field_property(df.fieldname, "read_only", true);
224 | }
225 |
226 | if(listeners[df.fieldname]){
227 | this.set_df_property(df.fieldname, "listeners", {});
228 |
229 | Object.entries(listeners[df.fieldname]).forEach(([event, callback]) => {
230 | this.set_df_property(df.fieldname, "on"+event, []);
231 | callback.forEach(cb => {
232 | this.on(df.fieldname, event, cb);
233 | });
234 | });
235 | }
236 | });
237 | }
238 |
239 | async get_doc(from_server = false) {
240 | if (this.doc && !from_server) return this.doc;
241 | const data = await this.#get("get_doc", {doctype: this.doctype, doc_name: this.doc_name});
242 |
243 | return data;
244 | }
245 |
246 | async get_form() {
247 | const data = await this.#get("get_form", {form_name: this.form_name});
248 |
249 | return data.desk_form
250 | }
251 |
252 | async get_all() {
253 | this.data = await this.#get("get_form_data", {form_name: this.form_name, doc_name: this.doc_name});
254 |
255 | this.doc = this.data.doc;
256 | this.desk_form = this.data.desk_form;
257 | }
258 |
259 | async #get(method, args) {
260 | return new Promise(resolve => {
261 | frappe.call({
262 | method: `frappe_helper.frappe_helper.doctype.desk_form.desk_form.${method}`,
263 | args: args,
264 | freeze: this.background === false,
265 | }).then(r => {
266 | return resolve(r.message);
267 | });
268 | });
269 | }
270 |
271 | set_field_property(field_name, property, value) {
272 | if(Array.isArray(field_name)){
273 | field_name.forEach(field => {
274 | this.set_field_property(field, property, value);
275 | });
276 | return;
277 | }
278 |
279 | if(typeof property === 'object'){
280 | Object.keys(property).forEach(key => {
281 | this.set_field_property(field_name, key, property[key]);
282 | });
283 | return;
284 | }
285 |
286 | const field = this.get_field(field_name);
287 | field.doctype = field.df.doctype;
288 | field.docname = field.df.docname;
289 |
290 | this.set_df_property(field_name, property, value);
291 | }
292 |
293 | get_fields() {
294 | return this.fields_dict;
295 | }
296 |
297 | get_section(section_name) {
298 | return this.get_field(section_name);
299 | }
300 |
301 | on(fieldname, event, fn) {
302 | if(Array.isArray(fieldname)){
303 | fieldname.forEach(f => this.on(f, event, fn));
304 | return;
305 | }
306 |
307 | const field = this.get_field(fieldname);
308 |
309 | if(field && field.df){
310 | const df = field.df;
311 |
312 | df.listeners ??= {};
313 | df.listeners[event] ??= [];
314 | df.listeners[event].push(fn);
315 |
316 | this.listeners ??= {};
317 | this.listeners[df.fieldname] ??= {};
318 | this.listeners[df.fieldname][event] ??= [];
319 | this.listeners[df.fieldname][event].push(fn);
320 |
321 | df[`on${event}`] = () => {
322 | //if(this.reloading) return;
323 | df.listeners[event].forEach(fn => {
324 | fn(field, fieldname);
325 | });
326 | }
327 | }
328 | }
329 |
330 | trigger(fieldname, event) {
331 | if(Array.isArray(fieldname)){
332 | fieldname.forEach(f => this.trigger(f, event));
333 | return;
334 | }
335 | const field = this.get_field(fieldname);
336 | const e = field && field.df[`on${event}`]
337 |
338 | e && typeof e === 'function' && e(this.get_value(fieldname));
339 | }
340 |
341 | execute_event(fieldname, event) {
342 | const field = this.get_field(fieldname);
343 |
344 | if (field && field.df) {
345 | const df = field.df;
346 | df.listeners ??= {};
347 | df.listeners[event] ??= [];
348 | df.listeners[event].push(fn);
349 |
350 | df[`on${event}`] = () => {
351 | df.listeners[event].forEach(fn => {
352 | fn(this.get_value(fieldname));
353 | });
354 | }
355 | }
356 | }
357 |
358 | save(options={}, force=false) {
359 | // validation hack: get_values will check for missing data
360 | return new Promise(resolve => {
361 | setTimeout(() => {
362 | const doc_values = super.get_values(force);
363 |
364 | if (!doc_values){
365 | options.error && options.error(false);
366 | return;
367 | }
368 |
369 | if (window.saving){
370 | options.error && options.error(__("Please wait for the other operation to complete"));
371 | return;
372 | }
373 |
374 | Object.assign(this.doc, doc_values || {});
375 | this.doc.doctype = this.doctype;
376 |
377 | window.saving = true;
378 | frappe.form_dirty = false;
379 |
380 | frappe.call({
381 | type: "POST",
382 | method: this.base_url + 'accept',
383 | args: {
384 | desk_form: this.form_name,
385 | data: this.doc,
386 | doc_name: this.doc_name,
387 | },
388 | freeze: true,
389 | btn: this.buttons[this.button_label],
390 | callback: (data) => {
391 | if (!data.exc) {
392 | this.doc_name = data.message.name;
393 |
394 | this.callback && this.callback(this);
395 | this.on_save && this.on_save(data);
396 | options.success && options.success(data);
397 | } else {
398 | options.error && options.error(__('There were errors. Please report this.'));
399 | }
400 |
401 | options.always && options.always(data);
402 | },
403 | always: (r) => {
404 | options.always && options.always(r);
405 | window.saving = false;
406 | },
407 | error: function (r) {
408 | options.always && options.always(r);
409 | options.error && options.error(__('There were errors. Please report this.'));
410 | },
411 | });
412 | }, 200);
413 | });
414 | }
415 |
416 | refresh_dependency() {
417 | super.refresh_dependency();
418 |
419 | if(this.reloading) return;
420 |
421 | this.on_refresh_dependency && this.on_refresh_dependency(this);
422 | }
423 | }
--------------------------------------------------------------------------------
/frappe_helper/public/js/frappe-helper-api.js:
--------------------------------------------------------------------------------
1 | class FrappeHelperApi {
2 | #api = this;
3 | constructor() {}
4 |
5 | get api(){return this.#api}
6 |
7 | /**option{model, name, method}**/
8 | call(options={}){
9 | frappe.call({
10 | method: "frappe_helper.api.call",
11 | args: {model: options.model, name: options.name, method: options.method, args: options.args},
12 | always: function (r) {
13 | options.always && options.always(r);
14 | },
15 | callback: function (r) {
16 | options.callback && options.callback(r);
17 | },
18 | success: function (r) {
19 | options.success && options.success(r);
20 | },
21 | error: function (r) {
22 | options.error && options.error(r);
23 | },
24 | freeze: !!options.freeze
25 | });
26 | }
27 | }
28 |
29 | const frappeHelper = new FrappeHelperApi();
--------------------------------------------------------------------------------
/frappe_helper/public/js/jshtml-class.js:
--------------------------------------------------------------------------------
1 | class JSHtml {
2 | #obj = null;
3 | #disabled = false;
4 | #cursor_position = 0;
5 | #click_attempts = 0;
6 | #confirming = false;
7 | #jshtml_identifier = 'jstmlefc65a6efc9cb8afbc85';
8 | #$ = null;
9 | #properties = {};
10 | #identifier = this.uuid();
11 | #listeners = {};
12 | #content = undefined;
13 | #text = undefined;
14 | #value = undefined;
15 | #is_float = false;
16 | #is_int = false;
17 | #decimals = 2;
18 |
19 | constructor(options) {
20 | Object.assign(this, options);
21 |
22 | this.#properties = (typeof options.properties == "undefined" ? {} : options.properties);
23 | this.fusion_props();
24 | this.make();
25 | this.set_obj();
26 | this.default_listeners();
27 | this.pad_editing = false;
28 |
29 | return this;
30 | }
31 |
32 | set properties(val) { this.#properties = val }
33 | set content(val) { this.#content = val }
34 | set text(val) { this.#text = val }
35 | set cursor_position(val) {
36 | this.#cursor_position = val;
37 | if (this.#cursor_position < 0) this.#cursor_position = 0;
38 | }
39 |
40 | get obj() { return this.#obj }
41 | get disabled() { return this.#disabled }
42 | get cursor_position() { return this.#cursor_position }
43 | get click_attempts() { return this.#click_attempts }
44 | get confirming() { return this.#confirming }
45 | get jshtml_identifier() { return this.#jshtml_identifier }
46 | get $() { return this.#$ }
47 | get identifier() { return this.#identifier }
48 | get properties() { return this.#properties }
49 | get listeners() { return this.#listeners }
50 | get float_val() { return isNaN(parseFloat(this.val())) ? 0.0 : parseFloat(this.val()) }
51 | get int_val() { return parseInt(isNaN(this.val()) ? 0 : this.val()) }
52 | get content() { return this.#content }
53 | get text() { return this.#text }
54 |
55 | set_obj() {
56 | if (this.obj) return;
57 | setTimeout(() => {
58 | this.#obj = this.from_html ? this.from_html : document.querySelector(`${this.tag}[${this.identifier}='${this.identifier}']`);
59 | setTimeout(() => {
60 | if (this.obj != null) this.#obj.removeAttribute(this.identifier);
61 | }, 0);
62 | this.#$ = this.JQ();
63 | }, 0);
64 | }
65 |
66 | fusion_props() {
67 | this.#properties[this.identifier] = this.identifier;
68 | }
69 |
70 | get type() {
71 | let type = null;
72 | ["input", "button", "select", "check", "radio"].forEach(t => {
73 | if (t === this.tag) type = t;
74 | });
75 |
76 | return type;
77 | }
78 |
79 | make() {
80 | this.make_dom();
81 | }
82 |
83 | toggle_common(base_class, toggle_class) {
84 | setTimeout(() => {
85 | this.add_class(toggle_class).JQ().siblings(`.${base_class}.${toggle_class}`).removeClass(toggle_class);
86 | }, 0);
87 | }
88 |
89 | float(decimals = 2) {
90 | this.#is_float = true;
91 | this.is_editable = true;
92 | this.#decimals = decimals;
93 | if (this.type === 'input') {
94 | this.setInputFilter((value) => {
95 | return /^-?\d*[.,]?\d*$/.test(value);
96 | });
97 | }
98 | return this;
99 | }
100 |
101 | int() {
102 | this.#is_int = true;
103 | this.is_editable = true;
104 | if (this.type === 'input') {
105 | this.setInputFilter((value) => {
106 | return /^-?\d*$/.test(value);
107 | });
108 | }
109 | return this;
110 | }
111 |
112 | on(listener, fn, method = null, callBack = null) {
113 | if (typeof listener == "object") {
114 | for (let listen in listener) {
115 | if (!listener.hasOwnProperty(listen)) continue;
116 | this.set_listener(listener[listen], fn);
117 | }
118 | } else {
119 | this.set_listener(listener, fn, method, callBack);
120 | }
121 | return this;
122 | }
123 |
124 | on_listener(fn, listener) {
125 | Object.keys(this.listeners[listener]).forEach((f) => {
126 | fn(this.listeners[listener][f]);
127 | });
128 | }
129 |
130 | set_listener(listener, fn, method = null, callBack = null) {
131 | if (typeof this.listeners[listener] == "object") {
132 | this.#listeners[listener].push(fn);
133 | } else {
134 | this.#listeners[listener] = [fn];
135 | }
136 |
137 | setTimeout(() => {
138 | if (this.obj == null) return;
139 |
140 | this.on_listener((listen) => {
141 | this.obj.addEventListener(listener, (event) => {
142 | event.preventDefault();
143 | event.stopPropagation();
144 | if (this.is_disabled) return;
145 |
146 | if (method != null && method === "double_click") {
147 | if (this.click_attempts === 0) {
148 | this.#confirming = true;
149 | if (typeof this.text != "undefined" && this.text.length > 0) {
150 | this.val(__("Confirm"));
151 | }
152 | this.#click_attempts = 1;
153 | this.add_class(`${this.jshtml_identifier}-confirm`).JQ().delay(5000).queue((next) => {
154 | if (this.confirming) {
155 | this.reset_confirm();
156 | next();
157 | }
158 | });
159 | } else {
160 | this.reset_confirm();
161 | listen(this, this.obj, event, callBack);
162 | }
163 | } else {
164 | listen(this, this.obj, event, callBack);
165 | }
166 | });
167 | }, listener, fn);
168 | }, 10);
169 | }
170 |
171 | set_content(content) {
172 | this.content = content;
173 | this.val("");
174 | return this;
175 | }
176 |
177 | make_dom() {
178 | //setTimeout(() => {
179 | if (!this.wrapper) {
180 | return this.html();
181 | } else {
182 | $(this.wrapper).append(this.html());
183 | }
184 | //}, 0);
185 | }
186 |
187 | html() {
188 | let template = this.template();
189 | this.set_obj();
190 | return template.replace("{{content_rendered}}", this.get_content_rendered());
191 | }
192 |
193 | refresh() {
194 | this.content = this.get_content_rendered();
195 | return this;
196 | }
197 |
198 | reset_confirm() {
199 | this.#confirming = false;
200 | this.#click_attempts = 0;
201 | this.remove_class(`${this.jshtml_identifier}-confirm`);
202 | this.val(this.text);
203 |
204 | return this;
205 | }
206 |
207 | get_content_rendered(text = null) {
208 | let _text = this.confirming ? __("Confirm") : this.text;
209 | if (typeof this.content != "undefined") {
210 | if (typeof _text != "undefined") {
211 | if (this.content.toString().search("{{text}}") === -1) {
212 | this.content = _text;
213 | return this.content;
214 | } else {
215 | return this.content.toString().replace("{{text}}", text || _text);
216 | }
217 | } else {
218 | if (text) {
219 | this.content = text;
220 | }
221 | return this.content;
222 | }
223 | } else {
224 | return "";
225 | }
226 | }
227 |
228 | template() {
229 | return `<${this.tag} ${this.props_by_json(this.properties)}>{{content_rendered}}${this.tag}>`;
230 | }
231 |
232 | set_selection() {
233 | if (this.type === 'input') {
234 | this.cursor_position = this.obj.selectionStart;
235 | } else {
236 | if ((this.is_int || this.is_float)) {
237 | if (!isNaN(parseFloat(this.value))) {
238 | this.in_decimal = false;
239 | this.cursor_position = parseInt(this.val()).toString().length
240 | }
241 | } else {
242 | this.#cursor_position = this.val().toString().length
243 | }
244 | }
245 | }
246 |
247 | default_listeners() {
248 | setTimeout(() => {
249 | if (this.is_editable) {
250 | this.on(["click", "onkeydown", "onkeypress"], (jshtml, obj, event) => {
251 | this.set_selection();
252 | });
253 |
254 | this.on("change", (jshtml) => {
255 | if (jshtml && !jshtml.pad_editing) this.value = this.type == 'input' ? this.JQ().val() : this.JQ().html();
256 | });
257 | }
258 | }, 0);
259 | }
260 |
261 | name() {
262 | return this.get_attr("name");
263 | }
264 |
265 | get_attr(attr = "") {
266 | return this.obj.getAttribute(attr);
267 | }
268 |
269 | find(selector) {
270 | return this.JQ().find(selector);
271 | }
272 |
273 | enable(on_enable = true) {
274 | this.#disabled = false;
275 | setTimeout(() => {
276 | if (on_enable) {
277 | this.prop("disabled", false);
278 | }
279 | this.remove_class(this.jshtml_identifier);
280 | }, 0)
281 |
282 | return this;
283 | }
284 |
285 | disable(on_disable = true) {
286 | this.#disabled = true;
287 | setTimeout(() => {
288 | if (on_disable) {
289 | this.prop("disabled", true);
290 | }
291 | this.add_class(this.jshtml_identifier);
292 | }, 0);
293 |
294 | return this;
295 | }
296 |
297 | css(prop = "", val = "") {
298 | setTimeout(() => {
299 | if (this.obj) {
300 | if (typeof prop == "object") {
301 | prop.forEach((row) => {
302 | this.obj.style[row.prop] = row.value;
303 | });
304 | } else {
305 | this.obj.style[prop] = val;
306 | }
307 | }
308 | }, 0);
309 |
310 | return this;
311 | }
312 |
313 | add_class(class_name) {
314 | if (typeof class_name == "object") {
315 | for (let c in class_name) {
316 | if (!class_name.hasOwnProperty(c)) continue;
317 | this.JQ().addClass(c);
318 | }
319 | } else {
320 | this.JQ().addClass(class_name);
321 | }
322 |
323 | return this;
324 | }
325 |
326 | has_class(class_name) {
327 | return this.obj && this.obj.classList.contains(class_name);
328 | }
329 |
330 | has_classes(classes) {
331 | let has_class = false;
332 | for (let c in classes) {
333 |
334 | if (!classes.hasOwnProperty(c)) continue;
335 | if (this.has_class(classes[c])) has_class = true;
336 | }
337 | return has_class;
338 | }
339 |
340 | JQ() {
341 | return $(this.obj);
342 | }
343 |
344 | select() {
345 | setTimeout(() => {
346 | this.obj.select();
347 | }, 0)
348 |
349 | return this;
350 | }
351 |
352 | remove_class(class_name) {
353 | if (typeof class_name == "object") {
354 | for (let c in class_name) {
355 | if (!class_name.hasOwnProperty(c)) continue;
356 | this.JQ().removeClass(c);
357 | }
358 | } else {
359 | this.JQ().removeClass(class_name);
360 | }
361 | return this;
362 | }
363 |
364 | get is_disabled() {
365 | return this.disabled;
366 | }
367 |
368 | delete_selection(value, move_position = 1) {
369 | let current_value = this.val().toString();
370 | let current_selection = window.getSelection().toString();
371 |
372 | this.cursor_position = current_value.search(current_selection) + move_position;
373 |
374 | this.val(current_value.replace(current_selection, value));
375 | }
376 |
377 | has_selection() {
378 | return window.window.getSelection().toString().length;
379 | }
380 |
381 | write(value) {
382 | if (this.is_disabled) return;
383 |
384 | value = value.toString();
385 | if (this.has_selection()) {
386 | this.delete_selection(value);
387 | return;
388 | }
389 |
390 | let raw_value = this.type != 'input' ? this.raw_value : this.val();
391 | let editable_value = raw_value
392 | let decimal_value = 0;
393 |
394 | if (raw_value.toString().length === 0) this.cursor_position = 0;
395 |
396 | if (this.is_float && this.type != 'input') {
397 | if (value === ".") {
398 | this.in_decimal = true;
399 | return;
400 | }
401 |
402 | if (!isNaN(parseFloat(raw_value))) {
403 | decimal_value = raw_value.toString().split(".")[1];
404 | decimal_value = typeof decimal_value != "undefined" && !isNaN(parseInt(decimal_value)) ? parseInt(decimal_value).toString() : "";
405 | raw_value = parseInt(raw_value).toString();
406 | editable_value = raw_value;
407 | }
408 | }
409 |
410 | if (this.in_decimal) {
411 | if (this.cursor_position >= this.val().toString().length && this.val().toString().length > 0) return;
412 |
413 | if (this.cursor_position == 0) {
414 | if (decimal_value.toString().length > 1) {
415 | decimal_value = "";
416 | } else {
417 | this.cursor_position = decimal_value.toString().length;
418 | }
419 | }
420 | editable_value = decimal_value;
421 | }
422 |
423 | let left_value = editable_value.toString().substring(0, this.cursor_position).toString();
424 | let right_value = editable_value.toString().substring(this.cursor_position, editable_value.length).toString();
425 |
426 | let new_vslue = "";
427 | if (this.type != 'input') {
428 | if (this.in_decimal) {
429 | new_vslue = `${raw_value}.${left_value}${value}${right_value}`;
430 | } else {
431 | new_vslue = `${left_value}${value}${(parseInt(right_value) > 0 ? right_value : "")}${(decimal_value > 0 ? "." + decimal_value : "")}`;
432 | }
433 | } else {
434 | new_vslue = `${left_value}${value}${right_value}`;
435 | }
436 |
437 | this.pad_editing = true;
438 |
439 | this.val(new_vslue);
440 |
441 | this.cursor_position = this.cursor_position + 1;
442 |
443 | if (this.in_decimal && this.cursor_position > this.#decimals) {
444 | this.cursor_position = this.raw_value.toString().length;
445 | }
446 |
447 | if (this.raw_value.toString().length == 0) this.in_decimal = false;
448 |
449 | this.trigger("change");
450 | this.pad_editing = false;
451 | }
452 |
453 | plus(value = 1) {
454 | this.val(this.float_val + value);
455 | this.focus();
456 |
457 | return this;
458 | }
459 |
460 | minus(value = 1) {
461 | this.val(this.float_val - value);
462 | this.focus();
463 |
464 | return this;
465 | }
466 |
467 | get is_int() { return typeof this.#is_int == 'undefined' ? false : this.#is_int }
468 | get is_float() { return typeof this.#is_float == 'undefined' ? false : this.#is_float }
469 |
470 | get value() {
471 | return this.#value
472 | }
473 |
474 | get raw_value() {
475 | if ((this.is_float || this.is_int)) {
476 | return isNaN(parseFloat(this.value)) ? "" : parseFloat(this.value).toString();
477 | } else {
478 | return this.value.toString();
479 | }
480 | }
481 |
482 | set value(val) {
483 | if (this.is_float) {
484 | this.#value = parseFloat(val).toFixed(2);
485 | if (isNaN(this.#value)) this.#value = "";
486 | } else if (this.is_int) {
487 | this.#value = parseInt(val);
488 | if (isNaN(this.#value)) this.#value = "";
489 | } else {
490 | this.#value = val;
491 | }
492 | }
493 |
494 | val(val = null, change = true, filter = false) {
495 | if (val == null) {
496 | if (typeof this.value == 'undefined') {
497 | this.value = this.type == 'input' ? this.JQ().val() : this.JQ().html();
498 | }
499 | return this.value;
500 |
501 | } else {
502 | this.value = val;
503 |
504 | if (!filter && this.properties.input_type === "number") {
505 | if (this.value.toString().length > 0) {
506 | this.filter_number();
507 | }
508 | }
509 | if (!this.#confirming) this.text = this.value;
510 |
511 | setTimeout(() => {
512 | if (this.type === "input") {
513 | this.JQ().val(this.value);
514 | if (change) this.trigger("change");
515 | } else {
516 | this.empty().JQ().html(this.get_content_rendered(this.value));
517 | }
518 | }, 0);
519 |
520 | return this;
521 | }
522 | }
523 |
524 | prepend(content) {
525 | this.JQ().prepend(content);
526 | return this;
527 | }
528 |
529 | append(content) {
530 | this.JQ().append(content);
531 | return this;
532 | }
533 |
534 | empty() {
535 | this.JQ().empty();
536 | return this;
537 | }
538 |
539 | remove() {
540 | this.JQ().remove();
541 | }
542 |
543 | hide() {
544 | this.add_class("hide");
545 | this.css("display", 'none !important');
546 | return this;
547 | }
548 |
549 | show() {
550 | this.remove_class("hide");
551 | this.css("display", '');
552 | return this;
553 | }
554 |
555 | prop(prop, value = "") {
556 | if (typeof prop == "object") {
557 | for (let p in prop) {
558 | if (!prop.hasOwnProperty(p)) continue;
559 |
560 | if (p === "disabled") {
561 | if (prop[p]) {
562 | this.disable(false)
563 | } else {
564 | this.enable(false);
565 | }
566 | }
567 | this.JQ().prop(p, prop[p]);
568 | }
569 | } else {
570 | if (prop === "disabled") {
571 | if (value) {
572 | this.disable(false)
573 | } else {
574 | this.enable(false);
575 | }
576 | }
577 |
578 | this.JQ().prop(prop, value);
579 | }
580 | return this
581 | }
582 |
583 | check_changes(last_val) {
584 | setTimeout(() => {
585 | let save_cursor_position = this.cursor_position;
586 | if (this.val() !== last_val) {
587 | this.trigger("change");
588 | }
589 |
590 | this.cursor_position = save_cursor_position;
591 | this.focus();
592 | }, 0);
593 | }
594 |
595 | delete_value() {
596 | if (this.is_disabled) return;
597 | let raw_value = this.raw_value;
598 |
599 | if (raw_value.toString().length == 0) return;
600 |
601 | if (this.has_selection()) {
602 | this.delete_selection("", 0);
603 | return;
604 | }
605 |
606 | let new_value = "";
607 |
608 | let left_value = raw_value.substring(0, this.cursor_position);
609 | let right_value = raw_value.substring(this.cursor_position, raw_value.length);
610 |
611 | if (this.cursor_position === raw_value.length) {
612 | new_value = left_value.substring(0, raw_value.length - 1);
613 | this.cursor_position = this.cursor_position - 1;;
614 | } else {
615 | new_value = left_value.substring(0, this.cursor_position - 1) + right_value;
616 | this.cursor_position = this.cursor_position - 1;
617 | }
618 |
619 | if (this.cursor_position === 0 && raw_value.length > 0) {
620 | this.cursor_position = raw_value.length;
621 | }
622 |
623 | if (new_value.toString().length == 0) {
624 | this.in_decimal = false;
625 | }
626 | this.val(new_value);
627 | }
628 |
629 | trigger(event) {
630 | if (typeof this.listeners[event] != "undefined") {
631 | for (let listen in this.listeners[event]) {
632 | if (this.listeners[event].hasOwnProperty(listen)) {
633 | this.listeners[event][listen]();
634 | }
635 | }
636 | }
637 | this.focus();
638 | }
639 |
640 | focus() {
641 | //this.cursor_position = this.cursor_position < 0 ? 0 : this.cursor_position;
642 | this.JQ().focus();
643 | let pos = this.cursor_position;
644 |
645 | this.JQ().each(function (index, elem) {
646 | if (elem.setSelectionRange) {
647 | elem.setSelectionRange(pos, pos);
648 | } else if (elem.createTextRange) {
649 | let range = elem.createTextRange();
650 | range.moveEnd('character', pos);
651 | range.moveStart('character', pos);
652 | range.select();
653 | }
654 | });
655 | };
656 |
657 | setInputFilter(inputFilter) {
658 | setTimeout(() => {
659 | ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach((event) => {
660 | this.#obj.addEventListener(event, function () {
661 | if (inputFilter(this.value)) {
662 | this.oldValue = this.value;
663 | this.oldSelectionStart = this.selectionStart;
664 | this.oldSelectionEnd = this.selectionEnd;
665 | } else if (this.hasOwnProperty("oldValue")) {
666 | this.value = this.oldValue;
667 | this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
668 | } else {
669 | this.value = "";
670 | }
671 | });
672 | });
673 | })
674 | }
675 |
676 | filter_number() {
677 | let inputFilter = (value) => {
678 | return /^-?\d*[.,]?\d*$/.test(value);
679 | }
680 |
681 | if (inputFilter(this.val())) {
682 | this.oldValue = this.val();
683 | this.oldSelectionStart = this.selectionStart;
684 | this.oldSelectionEnd = this.selectionEnd;
685 | } else if (this.hasOwnProperty("oldValue")) {
686 | this.value = this.oldValue;
687 | if (this.type === 'inpunt') {
688 | this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
689 | }
690 | } else {
691 | this.value = "";
692 | }
693 | }
694 |
695 | props_by_json(props = {}) {
696 | let _html = "";
697 | for (let prop in props) {
698 | if (!props.hasOwnProperty(prop)) continue;
699 | _html += `${prop}='${props[prop]}'`;
700 | }
701 | return _html;
702 | }
703 |
704 | uuid() {
705 | let id = 'xxxxxxxx4xxxyxxxxxxx'.replace(/[xy]/g, function (c) {
706 | let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
707 | return v.toString(16);
708 | });
709 |
710 | return "jshtml" + id;
711 | }
712 |
713 | highlight() {
714 | this.add_class(`${this.jshtml_identifier}-confirm`).JQ().delay(10000).queue((next) => {
715 | this.remove_class(`${this.jshtml_identifier}-confirm`);
716 | next();
717 | });
718 | }
719 | }
720 |
721 | frappe.jshtml = (options) => {
722 | return new JSHtml(options)
723 | }
--------------------------------------------------------------------------------
/frappe_helper/public/js/num-pad-class.js:
--------------------------------------------------------------------------------
1 | class NumPad {
2 | #input = null;
3 | #html = "";
4 | constructor(options) {
5 | Object.assign(this, options);
6 | this.make();
7 | }
8 |
9 | set html(val){this.#html = val}
10 | set input(val){this.#input = val}
11 |
12 | get input(){return this.#input}
13 | get html(){return this.#html}
14 |
15 | make() {
16 | const default_class = `pad-col button btn-default`;
17 |
18 | let num_pads = [
19 | {
20 | 7: {props: {class: "sm pad-btn"}},
21 | 8: {props: {class: "sm pad-btn"}},
22 | 9: {props: {class: "sm pad-btn"}},
23 | Del: {
24 | props: {class: "md pad-btn"},
25 | content: '',
26 | action: "delete"
27 | },
28 | },
29 | {
30 | 4: {props: {class: "sm pad-btn"}},
31 | 5: {props: {class: "sm pad-btn"}},
32 | 6: {props: {class: "sm pad-btn"}},
33 | Enter: {
34 | props: {class: "md pad-btn", rowspan: "3"},
35 | content: '
',
36 | action: "enter"
37 | },
38 | },
39 | {
40 | 1: {props: {class: "sm pad-btn"}},
41 | 2: {props: {class: "sm pad-btn"}},
42 | 3: {props: {class: "sm pad-btn"}},
43 | },
44 | {
45 | 0: {props: {class: "sm pad-btn", colspan: 2}},
46 | '.': {props: {class: "sm pad-btn"}, action: "key"},
47 | }
48 | ];
49 |
50 | let html = "";
51 | num_pads.map(row => {
52 | html += "";
53 |
54 | Object.keys(row).map((key) => {
55 | let col = row[key];
56 | col.props.class += ` ${default_class}-${key}`;
57 | html += `${
58 | new JSHtml({
59 | tag: "td",
60 | properties: col.props,
61 | content: `{{text}} ${typeof col.content != "undefined" ? col.content : ""}`,
62 | text: __(key),
63 | }).on("click", () => {
64 | if (col.action === "enter") {
65 | if (this.on_enter != null) {
66 | this.on_enter();
67 | }
68 | } else if (this.input) {
69 | if (col.action === "delete") {
70 | this.input.delete_value();
71 | } else {
72 | this.input.write(key);
73 | }
74 | }
75 | }, "").html()
76 | }`
77 | });
78 | html += "
";
79 | });
80 | html += "
";
81 |
82 | this.html = html;
83 |
84 | if (typeof this.wrapper != "undefined") {
85 | $(this.wrapper).empty().append(this.html);
86 | }
87 | }
88 | }
--------------------------------------------------------------------------------
/frappe_helper/setup/install.py:
--------------------------------------------------------------------------------
1 | from __future__ import unicode_literals
2 | import frappe
3 | from itertools import chain
4 | import os
5 | import json
6 | from erpnext.setup.utils import insert_record
7 | from itertools import chain
8 |
9 | def after_install():
10 | create_desk_forms()
11 |
12 |
13 | def insert_desk_form(form_data):
14 | desk_form = frappe.new_doc("Desk Form")
15 | desk_form.update(form_data)
16 | desk_form.set("docstatus", 0)
17 |
18 | print(" Inserting Desk Form: {}".format(form_data.get("name")))
19 |
20 | desk_form.insert()
21 |
22 | def create_desk_forms():
23 | basedir = os.path.abspath(os.path.dirname(__file__))
24 | apps_dir = basedir.split("apps")[0] + "apps"
25 |
26 | frappe.db.sql("""DELETE FROM `tabDesk Form`""")
27 | frappe.db.sql("""DELETE FROM `tabDesk Form Field`""")
28 |
29 | print("Building Desk Forms")
30 |
31 | for app_name in os.listdir(apps_dir):
32 | print(" Processing Desk Forms for {} App".format(app_name))
33 |
34 | for dirpath, dirnames, filenames in os.walk(os.path.join(apps_dir, app_name, app_name, app_name, "desk_form")):
35 | for filename in filenames:
36 | _, extension = os.path.splitext(filename)
37 |
38 | if extension in ['.json']:
39 | abspath = os.path.join(dirpath, filename)
40 | f = open(abspath)
41 |
42 | insert_desk_form(json.load(f))
43 | f.close()
44 |
45 | print("Building Desk Forms Complete")
46 |
--------------------------------------------------------------------------------
/frappe_helper/templates/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/templates/__init__.py
--------------------------------------------------------------------------------
/frappe_helper/templates/pages/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/frappe_helper/templates/pages/__init__.py
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | ### GNU GENERAL PUBLIC LICENSE
2 |
3 | Version 3, 29 June 2007
4 |
5 | Copyright (C) 2007 Free Software Foundation, Inc.
6 |
7 |
8 | Everyone is permitted to copy and distribute verbatim copies of this
9 | license document, but changing it is not allowed.
10 |
11 | ### Preamble
12 |
13 | The GNU General Public License is a free, copyleft license for
14 | software and other kinds of works.
15 |
16 | The licenses for most software and other practical works are designed
17 | to take away your freedom to share and change the works. By contrast,
18 | the GNU General Public License is intended to guarantee your freedom
19 | to share and change all versions of a program--to make sure it remains
20 | free software for all its users. We, the Free Software Foundation, use
21 | the GNU General Public License for most of our software; it applies
22 | also to any other work released this way by its authors. You can apply
23 | it to your programs, too.
24 |
25 | When we speak of free software, we are referring to freedom, not
26 | price. Our General Public Licenses are designed to make sure that you
27 | have the freedom to distribute copies of free software (and charge for
28 | them if you wish), that you receive source code or can get it if you
29 | want it, that you can change the software or use pieces of it in new
30 | free programs, and that you know you can do these things.
31 |
32 | To protect your rights, we need to prevent others from denying you
33 | these rights or asking you to surrender the rights. Therefore, you
34 | have certain responsibilities if you distribute copies of the
35 | software, or if you modify it: responsibilities to respect the freedom
36 | of others.
37 |
38 | For example, if you distribute copies of such a program, whether
39 | gratis or for a fee, you must pass on to the recipients the same
40 | freedoms that you received. You must make sure that they, too, receive
41 | or can get the source code. And you must show them these terms so they
42 | know their rights.
43 |
44 | Developers that use the GNU GPL protect your rights with two steps:
45 | (1) assert copyright on the software, and (2) offer you this License
46 | giving you legal permission to copy, distribute and/or modify it.
47 |
48 | For the developers' and authors' protection, the GPL clearly explains
49 | that there is no warranty for this free software. For both users' and
50 | authors' sake, the GPL requires that modified versions be marked as
51 | changed, so that their problems will not be attributed erroneously to
52 | authors of previous versions.
53 |
54 | Some devices are designed to deny users access to install or run
55 | modified versions of the software inside them, although the
56 | manufacturer can do so. This is fundamentally incompatible with the
57 | aim of protecting users' freedom to change the software. The
58 | systematic pattern of such abuse occurs in the area of products for
59 | individuals to use, which is precisely where it is most unacceptable.
60 | Therefore, we have designed this version of the GPL to prohibit the
61 | practice for those products. If such problems arise substantially in
62 | other domains, we stand ready to extend this provision to those
63 | domains in future versions of the GPL, as needed to protect the
64 | freedom of users.
65 |
66 | Finally, every program is threatened constantly by software patents.
67 | States should not allow patents to restrict development and use of
68 | software on general-purpose computers, but in those that do, we wish
69 | to avoid the special danger that patents applied to a free program
70 | could make it effectively proprietary. To prevent this, the GPL
71 | assures that patents cannot be used to render the program non-free.
72 |
73 | The precise terms and conditions for copying, distribution and
74 | modification follow.
75 |
76 | ### TERMS AND CONDITIONS
77 |
78 | #### 0. Definitions.
79 |
80 | "This License" refers to version 3 of the GNU General Public License.
81 |
82 | "Copyright" also means copyright-like laws that apply to other kinds
83 | of works, such as semiconductor masks.
84 |
85 | "The Program" refers to any copyrightable work licensed under this
86 | License. Each licensee is addressed as "you". "Licensees" and
87 | "recipients" may be individuals or organizations.
88 |
89 | To "modify" a work means to copy from or adapt all or part of the work
90 | in a fashion requiring copyright permission, other than the making of
91 | an exact copy. The resulting work is called a "modified version" of
92 | the earlier work or a work "based on" the earlier work.
93 |
94 | A "covered work" means either the unmodified Program or a work based
95 | on the Program.
96 |
97 | To "propagate" a work means to do anything with it that, without
98 | permission, would make you directly or secondarily liable for
99 | infringement under applicable copyright law, except executing it on a
100 | computer or modifying a private copy. Propagation includes copying,
101 | distribution (with or without modification), making available to the
102 | public, and in some countries other activities as well.
103 |
104 | To "convey" a work means any kind of propagation that enables other
105 | parties to make or receive copies. Mere interaction with a user
106 | through a computer network, with no transfer of a copy, is not
107 | conveying.
108 |
109 | An interactive user interface displays "Appropriate Legal Notices" to
110 | the extent that it includes a convenient and prominently visible
111 | feature that (1) displays an appropriate copyright notice, and (2)
112 | tells the user that there is no warranty for the work (except to the
113 | extent that warranties are provided), that licensees may convey the
114 | work under this License, and how to view a copy of this License. If
115 | the interface presents a list of user commands or options, such as a
116 | menu, a prominent item in the list meets this criterion.
117 |
118 | #### 1. Source Code.
119 |
120 | The "source code" for a work means the preferred form of the work for
121 | making modifications to it. "Object code" means any non-source form of
122 | a work.
123 |
124 | A "Standard Interface" means an interface that either is an official
125 | standard defined by a recognized standards body, or, in the case of
126 | interfaces specified for a particular programming language, one that
127 | is widely used among developers working in that language.
128 |
129 | The "System Libraries" of an executable work include anything, other
130 | than the work as a whole, that (a) is included in the normal form of
131 | packaging a Major Component, but which is not part of that Major
132 | Component, and (b) serves only to enable use of the work with that
133 | Major Component, or to implement a Standard Interface for which an
134 | implementation is available to the public in source code form. A
135 | "Major Component", in this context, means a major essential component
136 | (kernel, window system, and so on) of the specific operating system
137 | (if any) on which the executable work runs, or a compiler used to
138 | produce the work, or an object code interpreter used to run it.
139 |
140 | The "Corresponding Source" for a work in object code form means all
141 | the source code needed to generate, install, and (for an executable
142 | work) run the object code and to modify the work, including scripts to
143 | control those activities. However, it does not include the work's
144 | System Libraries, or general-purpose tools or generally available free
145 | programs which are used unmodified in performing those activities but
146 | which are not part of the work. For example, Corresponding Source
147 | includes interface definition files associated with source files for
148 | the work, and the source code for shared libraries and dynamically
149 | linked subprograms that the work is specifically designed to require,
150 | such as by intimate data communication or control flow between those
151 | subprograms and other parts of the work.
152 |
153 | The Corresponding Source need not include anything that users can
154 | regenerate automatically from other parts of the Corresponding Source.
155 |
156 | The Corresponding Source for a work in source code form is that same
157 | work.
158 |
159 | #### 2. Basic Permissions.
160 |
161 | All rights granted under this License are granted for the term of
162 | copyright on the Program, and are irrevocable provided the stated
163 | conditions are met. This License explicitly affirms your unlimited
164 | permission to run the unmodified Program. The output from running a
165 | covered work is covered by this License only if the output, given its
166 | content, constitutes a covered work. This License acknowledges your
167 | rights of fair use or other equivalent, as provided by copyright law.
168 |
169 | You may make, run and propagate covered works that you do not convey,
170 | without conditions so long as your license otherwise remains in force.
171 | You may convey covered works to others for the sole purpose of having
172 | them make modifications exclusively for you, or provide you with
173 | facilities for running those works, provided that you comply with the
174 | terms of this License in conveying all material for which you do not
175 | control copyright. Those thus making or running the covered works for
176 | you must do so exclusively on your behalf, under your direction and
177 | control, on terms that prohibit them from making any copies of your
178 | copyrighted material outside their relationship with you.
179 |
180 | Conveying under any other circumstances is permitted solely under the
181 | conditions stated below. Sublicensing is not allowed; section 10 makes
182 | it unnecessary.
183 |
184 | #### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
185 |
186 | No covered work shall be deemed part of an effective technological
187 | measure under any applicable law fulfilling obligations under article
188 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
189 | similar laws prohibiting or restricting circumvention of such
190 | measures.
191 |
192 | When you convey a covered work, you waive any legal power to forbid
193 | circumvention of technological measures to the extent such
194 | circumvention is effected by exercising rights under this License with
195 | respect to the covered work, and you disclaim any intention to limit
196 | operation or modification of the work as a means of enforcing, against
197 | the work's users, your or third parties' legal rights to forbid
198 | circumvention of technological measures.
199 |
200 | #### 4. Conveying Verbatim Copies.
201 |
202 | You may convey verbatim copies of the Program's source code as you
203 | receive it, in any medium, provided that you conspicuously and
204 | appropriately publish on each copy an appropriate copyright notice;
205 | keep intact all notices stating that this License and any
206 | non-permissive terms added in accord with section 7 apply to the code;
207 | keep intact all notices of the absence of any warranty; and give all
208 | recipients a copy of this License along with the Program.
209 |
210 | You may charge any price or no price for each copy that you convey,
211 | and you may offer support or warranty protection for a fee.
212 |
213 | #### 5. Conveying Modified Source Versions.
214 |
215 | You may convey a work based on the Program, or the modifications to
216 | produce it from the Program, in the form of source code under the
217 | terms of section 4, provided that you also meet all of these
218 | conditions:
219 |
220 | - a) The work must carry prominent notices stating that you modified
221 | it, and giving a relevant date.
222 | - b) The work must carry prominent notices stating that it is
223 | released under this License and any conditions added under
224 | section 7. This requirement modifies the requirement in section 4
225 | to "keep intact all notices".
226 | - c) You must license the entire work, as a whole, under this
227 | License to anyone who comes into possession of a copy. This
228 | License will therefore apply, along with any applicable section 7
229 | additional terms, to the whole of the work, and all its parts,
230 | regardless of how they are packaged. This License gives no
231 | permission to license the work in any other way, but it does not
232 | invalidate such permission if you have separately received it.
233 | - d) If the work has interactive user interfaces, each must display
234 | Appropriate Legal Notices; however, if the Program has interactive
235 | interfaces that do not display Appropriate Legal Notices, your
236 | work need not make them do so.
237 |
238 | A compilation of a covered work with other separate and independent
239 | works, which are not by their nature extensions of the covered work,
240 | and which are not combined with it such as to form a larger program,
241 | in or on a volume of a storage or distribution medium, is called an
242 | "aggregate" if the compilation and its resulting copyright are not
243 | used to limit the access or legal rights of the compilation's users
244 | beyond what the individual works permit. Inclusion of a covered work
245 | in an aggregate does not cause this License to apply to the other
246 | parts of the aggregate.
247 |
248 | #### 6. Conveying Non-Source Forms.
249 |
250 | You may convey a covered work in object code form under the terms of
251 | sections 4 and 5, provided that you also convey the machine-readable
252 | Corresponding Source under the terms of this License, in one of these
253 | ways:
254 |
255 | - a) Convey the object code in, or embodied in, a physical product
256 | (including a physical distribution medium), accompanied by the
257 | Corresponding Source fixed on a durable physical medium
258 | customarily used for software interchange.
259 | - b) Convey the object code in, or embodied in, a physical product
260 | (including a physical distribution medium), accompanied by a
261 | written offer, valid for at least three years and valid for as
262 | long as you offer spare parts or customer support for that product
263 | model, to give anyone who possesses the object code either (1) a
264 | copy of the Corresponding Source for all the software in the
265 | product that is covered by this License, on a durable physical
266 | medium customarily used for software interchange, for a price no
267 | more than your reasonable cost of physically performing this
268 | conveying of source, or (2) access to copy the Corresponding
269 | Source from a network server at no charge.
270 | - c) Convey individual copies of the object code with a copy of the
271 | written offer to provide the Corresponding Source. This
272 | alternative is allowed only occasionally and noncommercially, and
273 | only if you received the object code with such an offer, in accord
274 | with subsection 6b.
275 | - d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 | - e) Convey the object code using peer-to-peer transmission,
288 | provided you inform other peers where the object code and
289 | Corresponding Source of the work are being offered to the general
290 | public at no charge under subsection 6d.
291 |
292 | A separable portion of the object code, whose source code is excluded
293 | from the Corresponding Source as a System Library, need not be
294 | included in conveying the object code work.
295 |
296 | A "User Product" is either (1) a "consumer product", which means any
297 | tangible personal property which is normally used for personal,
298 | family, or household purposes, or (2) anything designed or sold for
299 | incorporation into a dwelling. In determining whether a product is a
300 | consumer product, doubtful cases shall be resolved in favor of
301 | coverage. For a particular product received by a particular user,
302 | "normally used" refers to a typical or common use of that class of
303 | product, regardless of the status of the particular user or of the way
304 | in which the particular user actually uses, or expects or is expected
305 | to use, the product. A product is a consumer product regardless of
306 | whether the product has substantial commercial, industrial or
307 | non-consumer uses, unless such uses represent the only significant
308 | mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to
312 | install and execute modified versions of a covered work in that User
313 | Product from a modified version of its Corresponding Source. The
314 | information must suffice to ensure that the continued functioning of
315 | the modified object code is in no case prevented or interfered with
316 | solely because modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or
331 | updates for a work that has been modified or installed by the
332 | recipient, or for the User Product in which it has been modified or
333 | installed. Access to a network may be denied when the modification
334 | itself materially and adversely affects the operation of the network
335 | or violates the rules and protocols for communication across the
336 | network.
337 |
338 | Corresponding Source conveyed, and Installation Information provided,
339 | in accord with this section must be in a format that is publicly
340 | documented (and with an implementation available to the public in
341 | source code form), and must require no special password or key for
342 | unpacking, reading or copying.
343 |
344 | #### 7. Additional Terms.
345 |
346 | "Additional permissions" are terms that supplement the terms of this
347 | License by making exceptions from one or more of its conditions.
348 | Additional permissions that are applicable to the entire Program shall
349 | be treated as though they were included in this License, to the extent
350 | that they are valid under applicable law. If additional permissions
351 | apply only to part of the Program, that part may be used separately
352 | under those permissions, but the entire Program remains governed by
353 | this License without regard to the additional permissions.
354 |
355 | When you convey a copy of a covered work, you may at your option
356 | remove any additional permissions from that copy, or from any part of
357 | it. (Additional permissions may be written to require their own
358 | removal in certain cases when you modify the work.) You may place
359 | additional permissions on material, added by you to a covered work,
360 | for which you have or can give appropriate copyright permission.
361 |
362 | Notwithstanding any other provision of this License, for material you
363 | add to a covered work, you may (if authorized by the copyright holders
364 | of that material) supplement the terms of this License with terms:
365 |
366 | - a) Disclaiming warranty or limiting liability differently from the
367 | terms of sections 15 and 16 of this License; or
368 | - b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 | - c) Prohibiting misrepresentation of the origin of that material,
372 | or requiring that modified versions of such material be marked in
373 | reasonable ways as different from the original version; or
374 | - d) Limiting the use for publicity purposes of names of licensors
375 | or authors of the material; or
376 | - e) Declining to grant rights under trademark law for use of some
377 | trade names, trademarks, or service marks; or
378 | - f) Requiring indemnification of licensors and authors of that
379 | material by anyone who conveys the material (or modified versions
380 | of it) with contractual assumptions of liability to the recipient,
381 | for any liability that these contractual assumptions directly
382 | impose on those licensors and authors.
383 |
384 | All other non-permissive additional terms are considered "further
385 | restrictions" within the meaning of section 10. If the Program as you
386 | received it, or any part of it, contains a notice stating that it is
387 | governed by this License along with a term that is a further
388 | restriction, you may remove that term. If a license document contains
389 | a further restriction but permits relicensing or conveying under this
390 | License, you may add to a covered work material governed by the terms
391 | of that license document, provided that the further restriction does
392 | not survive such relicensing or conveying.
393 |
394 | If you add terms to a covered work in accord with this section, you
395 | must place, in the relevant source files, a statement of the
396 | additional terms that apply to those files, or a notice indicating
397 | where to find the applicable terms.
398 |
399 | Additional terms, permissive or non-permissive, may be stated in the
400 | form of a separately written license, or stated as exceptions; the
401 | above requirements apply either way.
402 |
403 | #### 8. Termination.
404 |
405 | You may not propagate or modify a covered work except as expressly
406 | provided under this License. Any attempt otherwise to propagate or
407 | modify it is void, and will automatically terminate your rights under
408 | this License (including any patent licenses granted under the third
409 | paragraph of section 11).
410 |
411 | However, if you cease all violation of this License, then your license
412 | from a particular copyright holder is reinstated (a) provisionally,
413 | unless and until the copyright holder explicitly and finally
414 | terminates your license, and (b) permanently, if the copyright holder
415 | fails to notify you of the violation by some reasonable means prior to
416 | 60 days after the cessation.
417 |
418 | Moreover, your license from a particular copyright holder is
419 | reinstated permanently if the copyright holder notifies you of the
420 | violation by some reasonable means, this is the first time you have
421 | received notice of violation of this License (for any work) from that
422 | copyright holder, and you cure the violation prior to 30 days after
423 | your receipt of the notice.
424 |
425 | Termination of your rights under this section does not terminate the
426 | licenses of parties who have received copies or rights from you under
427 | this License. If your rights have been terminated and not permanently
428 | reinstated, you do not qualify to receive new licenses for the same
429 | material under section 10.
430 |
431 | #### 9. Acceptance Not Required for Having Copies.
432 |
433 | You are not required to accept this License in order to receive or run
434 | a copy of the Program. Ancillary propagation of a covered work
435 | occurring solely as a consequence of using peer-to-peer transmission
436 | to receive a copy likewise does not require acceptance. However,
437 | nothing other than this License grants you permission to propagate or
438 | modify any covered work. These actions infringe copyright if you do
439 | not accept this License. Therefore, by modifying or propagating a
440 | covered work, you indicate your acceptance of this License to do so.
441 |
442 | #### 10. Automatic Licensing of Downstream Recipients.
443 |
444 | Each time you convey a covered work, the recipient automatically
445 | receives a license from the original licensors, to run, modify and
446 | propagate that work, subject to this License. You are not responsible
447 | for enforcing compliance by third parties with this License.
448 |
449 | An "entity transaction" is a transaction transferring control of an
450 | organization, or substantially all assets of one, or subdividing an
451 | organization, or merging organizations. If propagation of a covered
452 | work results from an entity transaction, each party to that
453 | transaction who receives a copy of the work also receives whatever
454 | licenses to the work the party's predecessor in interest had or could
455 | give under the previous paragraph, plus a right to possession of the
456 | Corresponding Source of the work from the predecessor in interest, if
457 | the predecessor has it or can get it with reasonable efforts.
458 |
459 | You may not impose any further restrictions on the exercise of the
460 | rights granted or affirmed under this License. For example, you may
461 | not impose a license fee, royalty, or other charge for exercise of
462 | rights granted under this License, and you may not initiate litigation
463 | (including a cross-claim or counterclaim in a lawsuit) alleging that
464 | any patent claim is infringed by making, using, selling, offering for
465 | sale, or importing the Program or any portion of it.
466 |
467 | #### 11. Patents.
468 |
469 | A "contributor" is a copyright holder who authorizes use under this
470 | License of the Program or a work on which the Program is based. The
471 | work thus licensed is called the contributor's "contributor version".
472 |
473 | A contributor's "essential patent claims" are all patent claims owned
474 | or controlled by the contributor, whether already acquired or
475 | hereafter acquired, that would be infringed by some manner, permitted
476 | by this License, of making, using, or selling its contributor version,
477 | but do not include claims that would be infringed only as a
478 | consequence of further modification of the contributor version. For
479 | purposes of this definition, "control" includes the right to grant
480 | patent sublicenses in a manner consistent with the requirements of
481 | this License.
482 |
483 | Each contributor grants you a non-exclusive, worldwide, royalty-free
484 | patent license under the contributor's essential patent claims, to
485 | make, use, sell, offer for sale, import and otherwise run, modify and
486 | propagate the contents of its contributor version.
487 |
488 | In the following three paragraphs, a "patent license" is any express
489 | agreement or commitment, however denominated, not to enforce a patent
490 | (such as an express permission to practice a patent or covenant not to
491 | sue for patent infringement). To "grant" such a patent license to a
492 | party means to make such an agreement or commitment not to enforce a
493 | patent against the party.
494 |
495 | If you convey a covered work, knowingly relying on a patent license,
496 | and the Corresponding Source of the work is not available for anyone
497 | to copy, free of charge and under the terms of this License, through a
498 | publicly available network server or other readily accessible means,
499 | then you must either (1) cause the Corresponding Source to be so
500 | available, or (2) arrange to deprive yourself of the benefit of the
501 | patent license for this particular work, or (3) arrange, in a manner
502 | consistent with the requirements of this License, to extend the patent
503 | license to downstream recipients. "Knowingly relying" means you have
504 | actual knowledge that, but for the patent license, your conveying the
505 | covered work in a country, or your recipient's use of the covered work
506 | in a country, would infringe one or more identifiable patents in that
507 | country that you have reason to believe are valid.
508 |
509 | If, pursuant to or in connection with a single transaction or
510 | arrangement, you convey, or propagate by procuring conveyance of, a
511 | covered work, and grant a patent license to some of the parties
512 | receiving the covered work authorizing them to use, propagate, modify
513 | or convey a specific copy of the covered work, then the patent license
514 | you grant is automatically extended to all recipients of the covered
515 | work and works based on it.
516 |
517 | A patent license is "discriminatory" if it does not include within the
518 | scope of its coverage, prohibits the exercise of, or is conditioned on
519 | the non-exercise of one or more of the rights that are specifically
520 | granted under this License. You may not convey a covered work if you
521 | are a party to an arrangement with a third party that is in the
522 | business of distributing software, under which you make payment to the
523 | third party based on the extent of your activity of conveying the
524 | work, and under which the third party grants, to any of the parties
525 | who would receive the covered work from you, a discriminatory patent
526 | license (a) in connection with copies of the covered work conveyed by
527 | you (or copies made from those copies), or (b) primarily for and in
528 | connection with specific products or compilations that contain the
529 | covered work, unless you entered into that arrangement, or that patent
530 | license was granted, prior to 28 March 2007.
531 |
532 | Nothing in this License shall be construed as excluding or limiting
533 | any implied license or other defenses to infringement that may
534 | otherwise be available to you under applicable patent law.
535 |
536 | #### 12. No Surrender of Others' Freedom.
537 |
538 | If conditions are imposed on you (whether by court order, agreement or
539 | otherwise) that contradict the conditions of this License, they do not
540 | excuse you from the conditions of this License. If you cannot convey a
541 | covered work so as to satisfy simultaneously your obligations under
542 | this License and any other pertinent obligations, then as a
543 | consequence you may not convey it at all. For example, if you agree to
544 | terms that obligate you to collect a royalty for further conveying
545 | from those to whom you convey the Program, the only way you could
546 | satisfy both those terms and this License would be to refrain entirely
547 | from conveying the Program.
548 |
549 | #### 13. Use with the GNU Affero General Public License.
550 |
551 | Notwithstanding any other provision of this License, you have
552 | permission to link or combine any covered work with a work licensed
553 | under version 3 of the GNU Affero General Public License into a single
554 | combined work, and to convey the resulting work. The terms of this
555 | License will continue to apply to the part which is the covered work,
556 | but the special requirements of the GNU Affero General Public License,
557 | section 13, concerning interaction through a network will apply to the
558 | combination as such.
559 |
560 | #### 14. Revised Versions of this License.
561 |
562 | The Free Software Foundation may publish revised and/or new versions
563 | of the GNU General Public License from time to time. Such new versions
564 | will be similar in spirit to the present version, but may differ in
565 | detail to address new problems or concerns.
566 |
567 | Each version is given a distinguishing version number. If the Program
568 | specifies that a certain numbered version of the GNU General Public
569 | License "or any later version" applies to it, you have the option of
570 | following the terms and conditions either of that numbered version or
571 | of any later version published by the Free Software Foundation. If the
572 | Program does not specify a version number of the GNU General Public
573 | License, you may choose any version ever published by the Free
574 | Software Foundation.
575 |
576 | If the Program specifies that a proxy can decide which future versions
577 | of the GNU General Public License can be used, that proxy's public
578 | statement of acceptance of a version permanently authorizes you to
579 | choose that version for the Program.
580 |
581 | Later license versions may give you additional or different
582 | permissions. However, no additional obligations are imposed on any
583 | author or copyright holder as a result of your choosing to follow a
584 | later version.
585 |
586 | #### 15. Disclaimer of Warranty.
587 |
588 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
589 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
590 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
591 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
592 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
593 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
594 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
595 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
596 | CORRECTION.
597 |
598 | #### 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
602 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
603 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
604 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
605 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
606 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
607 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
608 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
609 |
610 | #### 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | ### How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these
626 | terms.
627 |
628 | To do so, attach the following notices to the program. It is safest to
629 | attach them to the start of each source file to most effectively state
630 | the exclusion of warranty; and each file should have at least the
631 | "copyright" line and a pointer to where the full notice is found.
632 |
633 |
634 | Copyright (C)
635 |
636 | This program is free software: you can redistribute it and/or modify
637 | it under the terms of the GNU General Public License as published by
638 | the Free Software Foundation, either version 3 of the License, or
639 | (at your option) any later version.
640 |
641 | This program is distributed in the hope that it will be useful,
642 | but WITHOUT ANY WARRANTY; without even the implied warranty of
643 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
644 | GNU General Public License for more details.
645 |
646 | You should have received a copy of the GNU General Public License
647 | along with this program. If not, see .
648 |
649 | Also add information on how to contact you by electronic and paper
650 | mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands \`show w' and \`show c' should show the
661 | appropriate parts of the General Public License. Of course, your
662 | program's commands might be different; for a GUI interface, you would
663 | use an "about box".
664 |
665 | You should also get your employer (if you work as a programmer) or
666 | institute, if any, to sign a "copyright disclaimer" for the program, if
667 | necessary. For more information on this, and how to apply and follow
668 | the GNU GPL, see .
669 |
670 | The GNU General Public License does not permit incorporating your
671 | program into proprietary programs. If your program is a subroutine
672 | library, you may consider it more useful to permit linking proprietary
673 | applications with the library. If this is what you want to do, use the
674 | GNU Lesser General Public License instead of this License. But first,
675 | please read .
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphabit-technology/frappe_helper/38e3ee7ff65fa674f2ec0e81097e3af38d379861/requirements.txt
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from setuptools import setup, find_packages
3 |
4 | with open('requirements.txt') as f:
5 | install_requires = f.read().strip().split('\n')
6 |
7 | # get version from __version__ variable in frappe_helper/__init__.py
8 | from frappe_helper import __version__ as version
9 |
10 | setup(
11 | name='frappe_helper',
12 | version=version,
13 | description='Frappe Helper',
14 | author='Quantum Bit Core',
15 | author_email='qubitcore.io@gmail.com',
16 | packages=find_packages(),
17 | zip_safe=False,
18 | include_package_data=True,
19 | install_requires=install_requires
20 | )
21 |
--------------------------------------------------------------------------------