Ver a proveniência

fix(naming): added multiple rules for naming series

version-14
Rushabh Mehta há 4 anos
ascendente
cometimento
334ae82e52
14 ficheiros alterados com 149 adições e 63 eliminações
  1. +1
    -1
      frappe/core/doctype/document_naming_rule/document_naming_rule.js
  2. +26
    -25
      frappe/core/doctype/document_naming_rule/document_naming_rule.json
  3. +3
    -2
      frappe/core/doctype/document_naming_rule/document_naming_rule.py
  4. +6
    -4
      frappe/core/doctype/document_naming_rule/test_document_naming_rule.py
  5. +0
    -0
      frappe/core/doctype/document_naming_rule_condition/__init__.py
  6. +8
    -0
      frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.js
  7. +49
    -0
      frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.json
  8. +10
    -0
      frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.py
  9. +10
    -0
      frappe/core/doctype/document_naming_rule_condition/test_document_naming_rule_condition.py
  10. +3
    -0
      frappe/desk/form/save.py
  11. +2
    -2
      frappe/public/js/frappe/form/form.js
  12. +0
    -4
      frappe/public/js/frappe/form/save.js
  13. +0
    -22
      frappe/utils/__init__.py
  14. +31
    -3
      frappe/utils/data.py

+ 1
- 1
frappe/core/doctype/document_naming_rule/document_naming_rule.js Ver ficheiro

@@ -15,7 +15,7 @@ frappe.ui.form.on('Document Naming Rule', {
return {label: `${d.label} (${d.fieldname})`, value: d.fieldname};
});
frm.set_df_property('naming_field', 'options', fieldnames);
frm.set_df_property('filter_ny', 'options', fieldnames);
frappe.meta.get_docfield('Document Naming Rule Condition', 'field', frm.doc.name).options = fieldnames;
});
}
}


+ 26
- 25
frappe/core/doctype/document_naming_rule/document_naming_rule.json Ver ficheiro

@@ -7,10 +7,10 @@
"field_order": [
"document_type",
"disabled",
"section_break_3",
"conditions",
"naming_section",
"naming_by",
"apply_filter",
"filter_by",
"filter_value",
"naming_field",
"prefix",
"prefix_digits",
@@ -36,7 +36,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Naming By",
"options": "Numbered\nField Value\nTimestamp\nExpression\nDefault"
"options": "Numbered\nField Value"
},
{
"depends_on": "eval:doc.naming_by===\"Field Value\"",
@@ -45,12 +45,6 @@
"label": "Naming Field",
"mandatory_depends_on": "eval:doc.naming_by===\"Field Value\""
},
{
"default": "0",
"fieldname": "apply_filter",
"fieldtype": "Check",
"label": "Apply Filter"
},
{
"depends_on": "eval:doc.naming_by===\"Numbered\"",
"fieldname": "prefix",
@@ -59,36 +53,43 @@
"mandatory_depends_on": "eval:doc.naming_by===\"Numbered\""
},
{
"depends_on": "apply_filter",
"fieldname": "filter_by",
"fieldtype": "Select",
"label": "Filter By"
},
{
"depends_on": "apply_filter",
"fieldname": "filter_value",
"fieldtype": "Data",
"label": "Filter Value"
},
{
"depends_on": "eval:doc.naming_by === 'Numbered'",
"fieldname": "counter",
"fieldtype": "Int",
"label": "Counter",
"read_only": 1
},
{
"default": "5",
"depends_on": "eval:doc.naming_by==='Numbered'",
"description": "Example: 00001",
"fieldname": "prefix_digits",
"fieldtype": "Int",
"label": "Digits",
"mandatory_depends_on": "eval:doc.naming_by===\"Numbered\"",
"options": "5"
"mandatory_depends_on": "eval:doc.naming_by===\"Numbered\""
},
{
"fieldname": "naming_section",
"fieldtype": "Section Break",
"label": "Naming"
},
{
"collapsible": 1,
"collapsible_depends_on": "conditions",
"fieldname": "section_break_3",
"fieldtype": "Section Break",
"label": "Rule Conditions"
},
{
"fieldname": "conditions",
"fieldtype": "Table",
"label": "Conditions",
"options": "Document Naming Rule Condition"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2020-09-07 17:03:07.995818",
"modified": "2020-09-08 12:30:38.870359",
"modified_by": "Administrator",
"module": "Core",
"name": "Document Naming Rule",


+ 3
- 2
frappe/core/doctype/document_naming_rule/document_naming_rule.py Ver ficheiro

@@ -5,11 +5,12 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe.utils.data import evaluate_filters

class DocumentNamingRule(Document):
def apply(self, doc):
if self.apply_filter:
if doc.get(self.filter_by) != self.filter_value:
if self.conditions:
if not evaluate_filters(doc, [(d.field, d.condition, d.value) for d in self.conditions]):
return

if self.naming_by == 'Field Value':


+ 6
- 4
frappe/core/doctype/document_naming_rule/test_document_naming_rule.py Ver ficheiro

@@ -51,14 +51,16 @@ class TestDocumentNamingRule(unittest.TestCase):
naming_by = 'Numbered',
prefix = 'test-high-',
prefix_digits = 5,
apply_filter = 1,
filter_by = 'priority',
filter_value = 'High'
conditions = [dict(
field = 'priority',
condition = '=',
value = 'High'
)]
)).insert()

naming_rule_1 = frappe.copy_doc(naming_rule)
naming_rule_1.prefix = 'test-medium-'
naming_rule_1.filter_value = 'Medium'
naming_rule_1.conditions[0].value = 'Medium'
naming_rule_1.insert()

todo = frappe.get_doc(dict(


+ 0
- 0
frappe/core/doctype/document_naming_rule_condition/__init__.py Ver ficheiro


+ 8
- 0
frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.js Ver ficheiro

@@ -0,0 +1,8 @@
// Copyright (c) 2020, Frappe Technologies and contributors
// For license information, please see license.txt

frappe.ui.form.on('Document Naming Rule Condition', {
// refresh: function(frm) {

// }
});

+ 49
- 0
frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.json Ver ficheiro

@@ -0,0 +1,49 @@
{
"actions": [],
"creation": "2020-09-08 10:17:54.366279",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"field",
"condition",
"value"
],
"fields": [
{
"fieldname": "field",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Field",
"reqd": 1
},
{
"fieldname": "condition",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Condition",
"options": "=\n!=\n>\n<\n>=\n<=",
"reqd": 1
},
{
"fieldname": "value",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Value",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2020-09-08 10:19:56.192949",
"modified_by": "Administrator",
"module": "Core",
"name": "Document Naming Rule Condition",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

+ 10
- 0
frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.py Ver ficheiro

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document

class DocumentNamingRuleCondition(Document):
pass

+ 10
- 0
frappe/core/doctype/document_naming_rule_condition/test_document_naming_rule_condition.py Ver ficheiro

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

# import frappe
import unittest

class TestDocumentNamingRuleCondition(unittest.TestCase):
pass

+ 3
- 0
frappe/desk/form/save.py Ver ficheiro

@@ -23,6 +23,8 @@ def savedocs(doc, action):
# update recent documents
run_onload(doc)
send_updated_docs(doc)

frappe.msgprint(frappe._("Saved"), indicator='green', alert=True)
except Exception:
frappe.errprint(frappe.utils.get_traceback())
raise
@@ -36,6 +38,7 @@ def cancel(doctype=None, name=None, workflow_state_fieldname=None, workflow_stat
doc.set(workflow_state_fieldname, workflow_state)
doc.cancel()
send_updated_docs(doc)
frappe.msgprint(frappe._("Cancelled"), indicator='red', alert=True)

except Exception:
frappe.errprint(frappe.utils.get_traceback())


+ 2
- 2
frappe/public/js/frappe/form/form.js Ver ficheiro

@@ -1265,7 +1265,7 @@ frappe.ui.form.Form = class FrappeForm {

set_df_property(fieldname, property, value, docname, table_field) {
var df;
if (!docname && !table_field){
if (!docname && !table_field) {
df = this.get_docfield(fieldname);
} else {
var grid = this.fields_dict[table_field].grid,
@@ -1273,7 +1273,7 @@ frappe.ui.form.Form = class FrappeForm {
if (fname && fname.length)
df = frappe.meta.get_docfield(fname[0].parent, fieldname, docname);
}
if(df && df[property] != value) {
if (df && df[property] != value) {
df[property] = value;
refresh_field(fieldname, table_field);
}


+ 0
- 4
frappe/public/js/frappe/form/save.js Ver ficheiro

@@ -215,10 +215,6 @@ frappe.ui.form.save = function (frm, action, callback, btn) {
$(btn).prop("disabled", false);
frappe.ui.form.is_saving = false;

if (!r.exc) {
frappe.show_alert({message: __('Saved'), indicator: 'green'});
}

if (r) {
var doc = r.docs && r.docs[0];
if (doc) {


+ 0
- 22
frappe/utils/__init__.py Ver ficheiro

@@ -621,28 +621,6 @@ def parse_json(val):
val = frappe._dict(val)
return val

def cast_fieldtype(fieldtype, value):
if fieldtype in ("Currency", "Float", "Percent"):
value = flt(value)

elif fieldtype in ("Int", "Check"):
value = cint(value)

elif fieldtype in ("Data", "Text", "Small Text", "Long Text",
"Text Editor", "Select", "Link", "Dynamic Link"):
value = cstr(value)

elif fieldtype == "Date":
value = getdate(value)

elif fieldtype == "Datetime":
value = get_datetime(value)

elif fieldtype == "Time":
value = to_timedelta(value)

return value

def get_db_count(*args):
"""
Pass a doctype or a series of doctypes to get the count of docs in them


+ 31
- 3
frappe/utils/data.py Ver ficheiro

@@ -411,6 +411,28 @@ def has_common(l1, l2):
"""Returns truthy value if there are common elements in lists l1 and l2"""
return set(l1) & set(l2)

def cast_fieldtype(fieldtype, value):
if fieldtype in ("Currency", "Float", "Percent"):
value = flt(value)

elif fieldtype in ("Int", "Check"):
value = cint(value)

elif fieldtype in ("Data", "Text", "Small Text", "Long Text",
"Text Editor", "Select", "Link", "Dynamic Link"):
value = cstr(value)

elif fieldtype == "Date":
value = getdate(value)

elif fieldtype == "Datetime":
value = get_datetime(value)

elif fieldtype == "Time":
value = to_timedelta(value)

return value

def flt(s, precision=None):
"""Convert to float (ignore commas)"""
if isinstance(s, string_types):
@@ -1017,20 +1039,22 @@ def evaluate_filters(doc, filters):
if isinstance(filters, dict):
for key, value in iteritems(filters):
f = get_filter(None, {key:value})
if not compare(doc.get(f.fieldname), f.operator, f.value):
if not compare(doc.get(f.fieldname), f.operator, f.value, f.fieldtype):
return False

elif isinstance(filters, (list, tuple)):
for d in filters:
f = get_filter(None, d)
if not compare(doc.get(f.fieldname), f.operator, f.value):
if not compare(doc.get(f.fieldname), f.operator, f.value, f.fieldtype):
return False

return True


def compare(val1, condition, val2):
def compare(val1, condition, val2, fieldtype=None):
ret = False
if fieldtype:
val2 = cast_fieldtype(fieldtype, val2)
if condition in operator_map:
ret = operator_map[condition](val1, val2)

@@ -1044,6 +1068,7 @@ def get_filter(doctype, f, filters_config=None):
"fieldname":
"operator":
"value":
"fieldtype":
}
"""
from frappe.model import default_fields, optional_fields
@@ -1095,6 +1120,9 @@ def get_filter(doctype, f, filters_config=None):
f.doctype = df.options
break

df = frappe.get_meta(f.doctype).get_field(f.fieldname)
f.fieldtype = df.fieldtype if df else None

return f

def make_filter_tuple(doctype, key, value):


Carregando…
Cancelar
Guardar