def getLinkedDocName(): data = get_linked_docs(doctype='Delivery Note', name='DN-00021', linkinfo={"Sales Invoice": { "fieldname": "name" }}) return data
def get_document_completion_status(doctypes, frm_doctype, frm_docname): if isinstance(doctypes, basestring): doctypes = json.loads(doctypes) doc = frappe.get_doc(frm_doctype, frm_docname) linkinfo = get_linked_doctypes(frm_doctype) flow_completion = {} if hasattr(doc, "prev_link_mapper"): for doctype in doc.prev_link_mapper: fieldname = doc.prev_link_mapper[doctype]["fieldname"] lookup_doctype = doc.prev_link_mapper[doctype]["doctype"] limit = doc.prev_link_mapper[doctype].get("limit") or 1 condition = make_condition(doc.prev_link_mapper[doctype].get("filters")) if condition: condition = "where {condition}".format(condition=condition) else: condition = "" result = frappe.db.sql_list("select {fieldname} from `tab{doctype}` \ {condition} limit {limit}".format(fieldname=fieldname, doctype=lookup_doctype, condition=condition, limit=limit)) if result: flow_completion[doctype] = True for doctype in doctypes: if doctype not in flow_completion: links = get_linked_docs(frm_doctype, frm_docname, linkinfo, for_doctype=doctype) if links: flow_completion[doctype] = True return flow_completion
def get_linked_docs_info(doctype,docname): linkinfo = get_linked_doctypes(doctype) linked_doc = get_linked_docs(doctype,docname,linkinfo) linked_doc_list =[] if linked_doc: for key, value in linked_doc.items() : if key != "Activity Log": for val in value: dco_info = { "doctype" : key, "docname" : val.name, "docstatus": val.docstatus, } linked_doc_list.append(dco_info) return linked_doc_list
def reasign_batch(item_code, batch, stock_entry): doc_batch = frappe.get_doc("Batch",batch) if "Nouveau" in stock_entry: frappe.throw("l'entrée de marchandise doit être enregistrée avant de pouvoir utiliser cette fonction.") return linked_doctypes = get_linked_doctypes("Batch") if print_debug: frappe.errprint("linked_doctypes : " + cstr(linked_doctypes)) if print_debug: frappe.errprint("stock_entry : " + cstr(stock_entry)) linked_doc = get_linked_docs("Batch",batch, linked_doctypes) if linked_doc: if print_debug: frappe.errprint("linked_doc : " + cstr(linked_doc)) for key, value in linked_doc.items(): if print_debug: frappe.errprint("key : " + cstr(key)) if print_debug: frappe.errprint("value : " + cstr(value)) if key != "Stock Entry" and key != "Purchase Receipt": frappe.throw(_("Le lot {0} est lié au document {1}. Veuillez supprimer tous les liens avec le lot {0} avant de continuer").format(batch,cstr(value))) if key == "Stock Entry": for link in value: stock_entry_split = stock_entry.split('-') if not stock_entry_split[1] in link.name: if print_debug: frappe.errprint("stock_entry : " + stock_entry) if print_debug: frappe.errprint("link.name : " + link.name) frappe.throw(_("Le lot {0} est lié au document {1}. Veuillez supprimer tous les liens avec le lot {0} avant de continuer").format(batch,link.name)) for stock_entry_detail_name in frappe.get_all("Stock Entry Detail", {"batch_no":batch,"parent":link.name}, "name"): frappe.db.set_value("Stock Entry Detail", stock_entry_detail_name, "batch_no","") if key == "Purchase Receipt": for link in value: stock_entry_split = stock_entry.split('-') if not stock_entry_split[1] in link.name: if print_debug: frappe.errprint("stock_entry : " + stock_entry) if print_debug: frappe.errprint("link.name : " + link.name) frappe.throw(_("Le lot {0} est lié au document {1}. Veuillez supprimer tous les liens avec le lot {0} avant de continuer").format(batch,link.name)) for doc_detail_name in frappe.get_all("Purchase Receipt Item", {"batch_no":batch,"parent":link.name}, "name"): frappe.db.set_value("Purchase Receipt Item", doc_detail_name, "batch_no","") frappe.db.set_value("Batch", batch, "item",item_code)
def test_linked_with(self): results = get_linked_docs("Role", "System Manager", linkinfo=get_linked_doctypes("Role")) self.assertTrue("User" in results) self.assertTrue("DocType" in results)