def get_context(context): if frappe.session.user == 'Guest': frappe.local.flags.redirect_location = "/login?" + urlencode( {"redirect-to": frappe.local.request.full_path}) raise frappe.Redirect user_roles = frappe.get_roles(frappe.session.user) if 'App User' not in user_roles: raise frappe.PermissionError app = frappe.form_dict.app if not app: raise frappe.DoesNotExistError(_("Application not specified")) doc = frappe.get_doc("IOT Application", app) if frappe.session.user != 'Administrator' and doc.owner != frappe.session.user: raise frappe.PermissionError( _("You are not the owner of application {0}").format(doc.app_name)) context.no_cache = 1 context.categories = [ d.name for d in frappe.get_all("App Category", ["name"], order_by="name") ] context.protocols = [ d.name for d in frappe.get_all("App Device Protocol", ["name"], order_by="name") ] context.suppliers = [ d.name for d in frappe.get_all("App Device Supplier", ["name"], order_by="name") ] context.doc = doc
def get_undisbursed_principal(loan): """Gets undisbursed principal""" principal = frappe.get_value( 'Customer Loan Application', loan, 'loan_amount' ) if not principal: raise frappe.DoesNotExistError("Loan: {} not found".format(loan)) return principal - get_disbursed(loan)
def get_fees(loan): """Gets Loan Fees""" fees = frappe.get_value( 'Customer Loan Application', loan, 'total_fees' ) if not fees: raise frappe.DoesNotExistError("Loan: {} not found".format(loan)) return fees
def get_payable_interest(loan): """Gets Loan Interest Amount""" interest_amount = frappe.get_value( 'Customer Loan Application', loan, 'total_payable_interest' ) if not interest_amount: raise frappe.DoesNotExistError("Loan: {} not found".format(loan)) return interest_amount
def default_field_resolver(obj: Any, info: GraphQLResolveInfo, **kwargs): parent_type: GraphQLObjectType = info.parent_type if not isinstance(info.parent_type, GraphQLObjectType): frappe.throw("Invalid GraphQL") if parent_type.name == "Query": # This section is executed on root query type fields dt = get_singular_doctype(info.field_name) if dt: if is_single(dt): kwargs["name"] = dt elif not frappe.db.exists(dt, kwargs.get("name")): raise frappe.DoesNotExistError( frappe._("{0} {1} not found").format(frappe._(dt), kwargs.get("name"))) return frappe._dict( doctype=dt, name=kwargs.get("name") ) plural_doctype = get_plural_doctype(info.field_name) if plural_doctype: frappe.has_permission(doctype=plural_doctype, throw=True) return CursorPaginator(doctype=plural_doctype).resolve(obj, info, **kwargs) if not isinstance(obj, (dict, Document)): return None should_resolve_from_doc = not not (obj.get("name") and ( obj.get("doctype") or get_singular_doctype(parent_type.name))) # check if requested field can be resolved # - default resolver for simple objects # - these form the resolvers for # "SET_VALUE_TYPE", "SAVE_DOC_TYPE", "DELETE_DOC_TYPE" mutations if obj.get(info.field_name) is not None: value = obj.get(info.field_name) if isinstance(value, CursorPaginator): return value.resolve(obj, info, **kwargs) if not should_resolve_from_doc: return value if should_resolve_from_doc: # this section is executed for Fields on DocType object types. hooks_cmd = frappe.get_hooks("gql_default_document_resolver") resolver = document_resolver if len(hooks_cmd): resolver = frappe.get_attr(hooks_cmd[-1]) return resolver( obj=obj, info=info, **kwargs ) return None
def get_loan_schedule_status(loan, principal_amount, interest_amount, repayment_status): """Gets Schesule Status""" principal_amount = frappe.db.sql( """ Select principal_amount from `tabLoan Repayment Schedule` where parent=%s order by idx""", loan) repayment = frappe.get_value( 'Loan Repayment Schudle', loan, 'loan_amount' ) if not principal_amount: raise frappe.DoesNotExistError("Loan: {} not found".format(loan)) return principal_amount - get_disbursed(loan)
def get_context(context): if frappe.session.user == 'Guest': frappe.local.flags.redirect_location = "/login?" + urlencode( {"redirect-to": frappe.local.request.full_path}) raise frappe.Redirect app = frappe.form_dict.app if not app: raise frappe.DoesNotExistError(_("Application not specified")) device_link = frappe.form_dict.device app_inst = frappe.form_dict.app_inst version_want = frappe.form_dict.version if device_link and (not app_inst or not version_want): frappe.local.flags.redirect_location = "/app_editor?" + urlencode( {"app": app}) raise frappe.Redirect app_doc = frappe.get_doc("IOT Application", app) user_roles = frappe.get_roles(frappe.session.user) if 'App User' not in user_roles: raise frappe.PermissionError if frappe.session.user != 'Administrator' and app_doc.owner != frappe.session.user: raise frappe.PermissionError( _("You are not the owner of application {0}").format( app_doc.app_name)) context.no_cache = 1 context.doc = app_doc context.device_link = device_link context.app_inst = app_inst context.releases = frappe.db.get_all("IOT Application Version", fields="*", filters={"app": app}, limit=10, order_by="version desc") version_editor = editor_worksapce_version(app) or -1 context.version_editor = version_editor if version_want is not None: version_want = int(version_want) context.version_want = version_want if version_editor == -1: version_editor = version_want from app_center.editor import editor_revert editor_revert(app, version_editor) context.version_editor = version_editor if version_editor != version_want: context.show_version_warning = True
def get_disbursed(loan): """Gets disbursed principal""" loan_account = frappe.get_value('Microfinance Loan', loan, 'loan_account') if not loan_account: raise frappe.DoesNotExistError("Loan: {} not found".format(loan)) conds = [ "account = '{}'".format(loan_account), "voucher_type = 'Microfinance Disbursement'", "against_voucher_type = 'Microfinance Loan'", "against_voucher = '{}'".format(loan) ] return frappe.db.sql(""" SELECT sum(debit) FROM `tabGL Entry` WHERE {} """.format(" AND ".join(conds)))[0][0] or 0
def get_disbursed(loan): """Gets disbursed principal""" customer_loan_account = frappe.get_value('Customer Loan Appliaction', loan, 'customer_loan_account') if not customer_loan_account: raise frappe.DoesNotExistError("Loan: {} not found".format(loan)) conds = [ "account = '{}'".format(customer_loan_account), "against_voucher_type = 'Customer Loan Application'", "against_voucher = '{}'".format(loan) ] return frappe.db.sql(""" SELECT sum(debit) FROM `tabGL Entry` WHERE {} """.format(" AND ".join(conds)))[0][0] or 0
def get_context(context): app = frappe.form_dict.app if not app: raise frappe.DoesNotExistError(_("Application not specified")) tab = frappe.form_dict.tab or "description" doc = frappe.get_doc("IOT Application", app) context.no_cache = 1 context.tab = tab context.doc = doc context.comments = get_comments(app) context.reviews = get_reviews(app) context.issues = get_issues(app) context.releases = get_releases(app) context.has_release = len(context.releases) > 0
def get_context(context): if frappe.session.user == 'Guest': frappe.local.flags.redirect_location = "/login?" + urlencode( {"redirect-to": frappe.local.request.full_path}) raise frappe.Redirect app = frappe.form_dict.app if not app: raise frappe.DoesNotExistError(_("Application not specified")) app_doc = frappe.get_doc("IOT Application", app) user_roles = frappe.get_roles(frappe.session.user) if 'App User' not in user_roles: raise frappe.PermissionError if frappe.session.user != 'Administrator' and app_doc.owner != frappe.session.user: raise frappe.PermissionError( _("You are not the owner of application {0}").format( app_doc.app_name)) context.no_cache = 1 context.doc = app_doc
def get_undisbursed_principal(loan): """Gets undisbursed principal""" principal = frappe.get_value('Microfinance Loan', loan, 'loan_principal') if not principal: raise frappe.DoesNotExistError("Loan: {} not found".format(loan)) return principal - get_disbursed(loan)