def set_step_status(self, step, status="Deleted"): del_step = find(self.deletion_steps, lambda x: x.document_type == step and x.status != status) if not del_step: del_step = find(self.deletion_steps, lambda x: x.document_type == step) del_step.status = status self.save() self.reload()
def user_permission_exists(user, allow, for_value, applicable_for=None): '''Checks if similar user permission already exists''' user_permissions = get_user_permissions(user).get(allow, []) if not user_permissions: return None has_same_user_permission = find(user_permissions, lambda perm:perm["doc"] == for_value and perm.get('applicable_for') == applicable_for) return has_same_user_permission
def user_permission_exists(user, allow, for_value, applicable_for=None): '''Checks if similar user permission already exists''' user_permissions = get_user_permissions(user).get(allow, []) if not user_permissions: return None has_same_user_permission = find(user_permissions, lambda perm:perm["doc"] == for_value and perm.get('applicable_for') == applicable_for) return has_same_user_permission
def test_db_update(self): doctype = "User" frappe.reload_doctype("User", force=True) frappe.model.meta.trim_tables("User") make_property_setter(doctype, "bio", "fieldtype", "Text", "Data") make_property_setter(doctype, "middle_name", "fieldtype", "Data", "Text") make_property_setter(doctype, "enabled", "default", "1", "Int") frappe.db.updatedb(doctype) field_defs = get_field_defs(doctype) table_columns = frappe.db.get_table_columns_description("tab{}".format(doctype)) self.assertEqual(len(field_defs), len(table_columns)) for field_def in field_defs: fieldname = field_def.get("fieldname") table_column = find(table_columns, lambda d: d.get("name") == fieldname) fieldtype = get_fieldtype_from_def(field_def) fallback_default = ( "0" if field_def.get("fieldtype") in frappe.model.numeric_fieldtypes else "NULL" ) default = field_def.default if field_def.default is not None else fallback_default self.assertEqual(fieldtype, table_column.type) self.assertIn(cstr(table_column.default) or "NULL", [cstr(default), "'{}'".format(default)])
def test_db_update(self): doctype = 'User' frappe.reload_doctype('User', force=True) frappe.model.meta.trim_tables('User') make_property_setter(doctype, 'bio', 'fieldtype', 'Text', 'Data') make_property_setter(doctype, 'middle_name', 'fieldtype', 'Data', 'Text') make_property_setter(doctype, 'enabled', 'default', '1', 'Int') frappe.db.updatedb(doctype) field_defs = get_field_defs(doctype) table_columns = frappe.db.get_table_columns_description('tab{}'.format(doctype)) self.assertEqual(len(field_defs), len(table_columns)) for field_def in field_defs: fieldname = field_def.get('fieldname') table_column = find(table_columns, lambda d: d.get('name') == fieldname) fieldtype = get_fieldtype_from_def(field_def) fallback_default = '0' if field_def.get('fieldtype') in frappe.model.numeric_fieldtypes else 'NULL' default = field_def.default if field_def.default is not None else fallback_default self.assertEqual(fieldtype, table_column.type) self.assertIn(cstr(table_column.default) or 'NULL', [cstr(default), "'{}'".format(default)])
def get_default_payment_gateway_account(cart_settings): gateways = cart_settings.get("gateways") if not gateways: gateways = get_shopping_cart_settings().gateways default_payment_gateway_account = find(gateways, lambda gateway: gateway.get("is_default")) or '' if default_payment_gateway_account: default_payment_gateway_account = default_payment_gateway_account.get("payment_gateway_account") return default_payment_gateway_account
def get_postions_to_save(old_positions, new_positions): final_positions = [] for row in new_positions: old_row = find(old_positions, lambda d: d.position == row['position']) if old_row: old_row.update(row) final_positions.append(old_row) old_positions.remove(old_row) else: final_positions.append(row) return final_positions
def get_table_column(doctype, fieldname): table_columns = frappe.db.get_table_columns_description("tab{}".format(doctype)) return find(table_columns, lambda d: d.get("name") == fieldname)