示例#1
0
def log_field_changes(new_dict, old_dict):
    ignored_fields = ["modified", "creation", "__onload"]
    for k, v in old_dict.iteritems():
        if type(new_dict[k]) != type(old_dict[k]):
            new_dict[k] = str(new_dict[k])
            old_dict[k] = str(old_dict[k])
        if new_dict[k] != old_dict[k] and k not in ignored_fields:
            doc = {
                "doctype": get_analytics_doctype_name(old_dict['doctype']),
                "changed_doctype": new_dict['doctype'],
                "changed_doc_name": new_dict['name'],
                "fieldname": k,
                "old_value": old_dict[k],
                "new_value": new_dict[k],
                "modified_by_user": new_dict["modified_by"],
                "date": new_dict["modified"]
            }
            # can't save old/new value as list -> means child table.
            if type(doc['old_value']) is not list:
                make_doctype_maybe(doc['doctype'])
                history = Document(doc)
                history.insert()
            else:
                for idx, entry in enumerate(doc['old_value']):
                    log_field_changes(doc['new_value'][idx], entry)
示例#2
0
def create_vars_from_doc(doc: Document, key=None) -> list:
  """
  Utility function to prepare the template vars from a doc
  :param doc: The document as a dictionary
  :param key: Optionally specify the key name. If not specified, the scrub name of the doctype will be used
              For instance, Sales Order will be called sales_order
  :return:
  """
  if not doc:
    return []
  doc = doc.as_dict(convert_dates_to_str=True, no_nulls=True)
  if len(doc) == 0:
    return []
  doctype = doc.get("doctype").lower()
  template_vars = []
  to_del = []
  for k, v in doc.items():
    # Remove iterables from the variables
    if isinstance(v, (list, tuple, dict)):
      to_del.append(k)
      continue
    # Convert date object to string
    if isinstance(v, datetime.date):
      doc[k] = get_datetime_str(v)
  for k in to_del:
    del doc[k]
  template_vars.append({"name": key if key is not None else frappe.scrub(doctype), "content": doc})
  return template_vars
def log_field_changes(new_dict, old_dict):
    ignored_fields = ["modified", "creation", "__onload"]
    for k, v in old_dict.iteritems():
        if type(new_dict[k]) != type(old_dict[k]):
            new_dict[k] = str(new_dict[k])
            old_dict[k] = str(old_dict[k])
        if new_dict[k] != old_dict[k] and k not in ignored_fields:
                doc = {
                    "doctype": get_analytics_doctype_name(old_dict['doctype']),
                    "changed_doctype": new_dict['doctype'],
                    "changed_doc_name": new_dict['name'],
                    "fieldname": k,
                    "old_value": old_dict[k],
                    "new_value": new_dict[k],
                    "modified_by_user": new_dict["modified_by"],
                    "date": new_dict["modified"]
                    }
                # can't save old/new value as list -> means child table.
                if type(doc['old_value']) is not list:
                    make_doctype_maybe(doc['doctype'])
                    history = Document(doc)
                    history.insert()
                else:
                    for idx, entry in enumerate(doc['old_value']):
                        log_field_changes(doc['new_value'][idx], entry)
def log_field_changes(new_dict, old_dict):
    ignored_fields = ["modified", "creation", "__onload"]
    for k, v in old_dict.iteritems():

# these are commented out b/c they're causing issues with datetimes
# string comparison is wrong, says they're changed b/c Y-m-d != m-d-Y
#        if type(new_dict[k]) != type(old_dict[k]):
#            new_dict[k] = str(new_dict[k])
#            old_dict[k] = str(old_dict[k])

        if new_dict[k] != old_dict[k] and k not in ignored_fields:
                doc = {
                    "doctype": get_analytics_doctype_name(old_dict['doctype']),
                    "changed_doctype": new_dict['doctype'],
                    "changed_doc_name": new_dict['name'],
                    "fieldname": k,
                    "old_value": old_dict[k],
                    "new_value": new_dict[k],
                    "modified_by_user": new_dict["modified_by"],
                    "date": new_dict["modified"]
                    }
                # can't save old/new value as list -> means child table.
                if type(doc['old_value']) is not list:
                    make_doctype_maybe(doc['doctype'])
                    history = Document(doc)
                    history.insert()
                else:
                    for idx, entry in enumerate(doc['old_value']):
                        log_field_changes(doc['new_value'][idx], entry)
示例#5
0
def sort_changed_field(doc):
    """ Gets changed field from doc hook, sorts into correct table, and
    removes doc from Frappe's Changed Fields table"""
    to_doctype_name = get_analytics_doctype_name(doc.changed_doctype)
    make_doctype_maybe(to_doctype_name)
    new_doc = Document(sanitize_document(doc, to_doctype_name))
    new_doc.save()
    doc.delete()
def sort_changed_field(doc):
    """ Gets changed field from doc hook, sorts into correct table, and
    removes doc from Frappe's Changed Fields table"""
    to_doctype_name = get_analytics_doctype_name(doc.changed_doctype)
    make_doctype_maybe(to_doctype_name)
    new_doc = Document(sanitize_document(doc, to_doctype_name))
    new_doc.save()
    doc.delete()
def make_doc(new_dict, old_dict, k):
    doc = prep_doc(new_dict, old_dict, k)
    if type(doc['new_value']) is not list:
        make_doctype_maybe(doc['doctype'])
        history = Document(doc)
        history.insert()
    elif doc['old_value'] != None:
        for idx, entry in enumerate(doc['old_value']):
            log_field_changes(doc['new_value'][idx], entry)
示例#8
0
 def __init__(self, queue_doc: Document, is_background_task: bool = False):
     self.queue_doc = queue_doc
     self.is_background_task = is_background_task
     self.email_account_doc = queue_doc.get_email_account()
     self.smtp_server = self.email_account_doc.get_smtp_server()
     self.sent_to = [
         rec.recipient for rec in self.queue_doc.recipients
         if rec.is_main_sent()
     ]
示例#9
0
	def set_custom_permissions(self):
		'''Reset `permissions` with Custom DocPerm if exists'''
		if frappe.flags.in_patch or frappe.flags.in_install:
			return

		if not self.istable and self.name not in ('DocType', 'DocField', 'DocPerm',
			'Custom DocPerm'):
			custom_perms = frappe.get_all('Custom DocPerm', fields='*',
				filters=dict(parent=self.name), update=dict(doctype='Custom DocPerm'))
			if custom_perms:
				self.permissions = [Document(d) for d in custom_perms]
def insert_new_doc(dictionary):
    ignored_fields = ["modified", "creation", "__onload"]
    for k, v in dictionary.iteritems():
        if k not in ignored_fields:
            doc = {
                "doctype": get_analytics_doctype_name(dictionary['doctype']),
                "changed_doctype": dictionary['doctype'],
                "changed_doc_name": dictionary['name'],
                "fieldname": k,
                "old_value": None,
                "new_value": dictionary[k],
                "modified_by_user": dictionary["modified_by"],
                "date": dictionary["modified"]
                }
            if type(doc['new_value']) is not list:
                make_doctype_maybe(doc['doctype'])
                history = Document(doc)
                history.insert()
            else:
                for idx, entry in enumerate(doc['new_value']):
                    insert_new_doc(doc['new_value'][idx])
示例#11
0
文件: meta.py 项目: erpnext-tm/frappe
	def set_custom_permissions(self):
		"""Reset `permissions` with Custom DocPerm if exists"""
		if frappe.flags.in_patch or frappe.flags.in_install:
			return

		if not self.istable and self.name not in ("DocType", "DocField", "DocPerm", "Custom DocPerm"):
			custom_perms = frappe.get_all(
				"Custom DocPerm",
				fields="*",
				filters=dict(parent=self.name),
				update=dict(doctype="Custom DocPerm"),
			)
			if custom_perms:
				self.permissions = [Document(d) for d in custom_perms]
示例#12
0
    def test_doctype_link_resolve(self, get_meta, get_doc):
        # set test side effects
        get_meta.side_effect = build_get_meta_side_effects(
            [QUOTATION_META, CUSTOMER_META])
        get_doc.side_effect = build_get_doc_side_effect([
            Document({
                "doctype": "Quotation",
                "name": "test-quotation",
                "customer_name": "test-customer"
            }),
            Document({
                "doctype": "Customer",
                "name": "test-customer",
                "full_name": "Mr. Test Customer"
            })
        ])

        ctx = {"#VARS": {"doc": frappe.get_doc("Quotation", "test-quotation")}}
        full_name = resolve_expression(
            [CMD_VAR, "doc", "customer_name", "full_name"], ctx)

        get_doc.assert_called()
        get_meta.assert_called()
        self.assertTrue(full_name == "Mr. Test Customer")
	def autoname(self):
		naming_series = Document.get("guardian_naming_series")
		if naming_series:
			self.naming_series = naming_series