def __init__(self, dimension): totals_definition = NullValue() display_definition = totals_definition \ if dimension.has_display_field \ else None super(TotalsDimension, self).__init__(dimension.key, label=dimension.label, definition=totals_definition, display_definition=display_definition, hyperlink_template=dimension.hyperlink_template)
Field, Index, Interval, JSON, Not, NullValue, SystemTimeValue, Parameter, Rollup, Tuple, CustomFunction, ) # noinspection PyUnresolvedReferences from pypika.utils import ( CaseException, GroupingException, JoinException, QueryException, RollupException, SetOperationException, FunctionException, ) __author__ = "Timothy Heys" __email__ = "*****@*****.**" __version__ = "0.42.0" NULL = NullValue() SYSTEM_TIME = SystemTimeValue()
def set_value( self, dt, dn, field, val=None, modified=None, modified_by=None, update_modified=True, debug=False, for_update=True, ): """Set a single value in the database, do not call the ORM triggers but update the modified timestamp (unless specified not to). **Warning:** this function will not call Document events and should be avoided in normal cases. :param dt: DocType name. :param dn: Document name. :param field: Property / field name or dictionary of values to be updated :param value: Value to be updated. :param modified: Use this as the `modified` timestamp. :param modified_by: Set this user as `modified_by`. :param update_modified: default True. Set as false, if you don't want to update the timestamp. :param debug: Print the query in the developer / js console. :param for_update: Will add a row-level lock to the value that is being set so that it can be released on commit. """ is_single_doctype = not (dn and dt != dn) to_update = field if isinstance(field, dict) else {field: val} if update_modified: modified = modified or now() modified_by = modified_by or frappe.session.user to_update.update({ "modified": modified, "modified_by": modified_by }) if is_single_doctype: frappe.db.delete("Singles", filters={ "field": ("in", tuple(to_update)), "doctype": dt }, debug=debug) singles_data = ((dt, key, sbool(value)) for key, value in to_update.items()) query = (frappe.qb.into("Singles").columns( "doctype", "field", "value").insert(*singles_data)).run(debug=debug) frappe.clear_document_cache(dt, dt) else: table = DocType(dt) if for_update: docnames = tuple(x[0] for x in self.get_values( dt, dn, "name", debug=debug, for_update=for_update)) or ( NullValue(), ) query = frappe.qb.update(table).where( table.name.isin(docnames)) for docname in docnames: frappe.clear_document_cache(dt, docname) else: query = self.query.build_conditions(table=dt, filters=dn, update=True) # TODO: Fix this; doesn't work rn - [email protected] # frappe.cache().hdel_keys(dt, "document_cache") # Workaround: clear all document caches frappe.cache().delete_value("document_cache") for column, value in to_update.items(): query = query.set(column, value) query.run(debug=debug) if dt in self.value_cache: del self.value_cache[dt]