def _update_settings(): def update(doctype, params): doc = frappe.get_single(doctype) doc.update(params) doc.save(ignore_permissions=True) mapr(lambda x: update(*x), settings().items())
def _create_docs(): def insert_or_update(doctype, args): docname = frappe.db.exists(doctype, args) if not docname: frappe.get_doc(merge({"doctype": doctype}, args)).insert( ignore_permissions=True ) else: doc = frappe.get_doc(doctype, docname) doc.update(args) doc.save(ignore_permissions=True) for doctype, docs in documents().items(): mapr(lambda x: insert_or_update(doctype, x), docs)
def _setup_workflow(): def make_action(name): if not frappe.db.exists("Workflow Action Master", name): frappe.get_doc( {"doctype": "Workflow Action Master", "workflow_action_name": name} ).insert(ignore_permissions=True) def make_state(name, style=None): if not frappe.db.exists("Workflow State", name): frappe.get_doc( { "doctype": "Workflow State", "workflow_state_name": name, "style": style, } ).insert(ignore_permissions=True) else: doc = frappe.get_doc("Workflow State", name) doc.update({"style": style}) doc.save(ignore_permissions=True) def make_role(name, desk_access=1): if not frappe.db.exists("Role", name): frappe.get_doc( {"doctype": "Role", "role_name": name, "desk_access": desk_access} ).insert(ignore_permissions=True) def make_workflow(name, args): if args.get("transitions"): mapr(lambda x: make_action(x.get("action")), args.get("transitions")) if args.get("states"): mapr( lambda x: make_state(x.get("state"), x.get("style")), args.get("states") ) mapr(lambda x: make_role(x.get("allow_edit")), args.get("states")) if not frappe.db.exists("Workflow", name): frappe.get_doc( merge({"doctype": "Workflow", "workflow_name": name}, args) ).insert(ignore_permissions=True) else: doc = frappe.get_doc("Workflow", name) doc.update(args) doc.save(ignore_permissions=True) mapr(lambda x: make_workflow(*x), workflows().items())
def make_gl_entry(self): settings = frappe.get_single("Wire Transfer Settings") sign = -1 if self.workflow_action in [RETURN, REVERSE] else 1 if self.workflow_action in [ACCEPT, RETURN]: make_gl_entries( mapr( self.get_gl_dict, [ { "account": self.cash_account, "against": self.account, "debit": self.total * sign, }, { "account": settings.income_account, "against": self.account, "credit": self.fees * sign, "cost_center": settings.cost_center, }, { "account": settings.transit_account, "party": self.account, "credit": self.amount * sign, }, ], ) ) elif self.workflow_action in [TRANSFER, REVERSE]: make_gl_entries( mapr( self.get_gl_dict, [ { "account": self.bank_account, "against": self.account, "credit": self.amount * sign, "remarks": self._get_remarks(), }, { "account": settings.transit_account, "against": self.bank_account, "debit": self.amount * sign, }, ], ) )
def make_workflow(name, args): if args.get("transitions"): mapr(lambda x: make_action(x.get("action")), args.get("transitions")) if args.get("states"): mapr( lambda x: make_state(x.get("state"), x.get("style")), args.get("states") ) mapr(lambda x: make_role(x.get("allow_edit")), args.get("states")) if not frappe.db.exists("Workflow", name): frappe.get_doc( merge({"doctype": "Workflow", "workflow_name": name}, args) ).insert(ignore_permissions=True) else: doc = frappe.get_doc("Workflow", name) doc.update(args) doc.save(ignore_permissions=True)
def _get_data(clauses, values, keys): rows = frappe.db.sql( """ SELECT name AS wire_transfer, account, account_holder, status, request_datetime, transfer_datetime, amount, fees, total FROM `tabWire Transfer` WHERE {clauses} """.format( clauses=clauses ), values=values, as_dict=1, ) make_row = partial(pick, keys) return mapr(make_row, rows)