def make_report(source_name, target_doclist=None): dic = get_patient_info(source_name) from webnotes.model.mapper import get_mapped_doclist def postprocess(source, doclist): doclist[0].accession_number = source_name doclist = get_mapped_doclist( "Patient Encounter Entry", source_name, { "Patient Encounter Entry": { "doctype": "Patient Report", "field_map": { "patient": "patient_id", "patient_name": "patient_name", "encounter": "modality", "start_time": "study_time", "encounter_date": "study_date", "technologist": "technologist_id", "technologist_name": "technologist_name", "referral": "referring_physician", "gender": "sex" }, "validation": { "docstatus": ["=", 0] } } }, target_doclist, postprocess) return [d if isinstance(d, dict) else d.fields for d in doclist]
def make_maintenance_schedule(source_name, target_doclist=None): maint_schedule = webnotes.conn.sql("""select t1.name from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1""", source_name) if not maint_schedule: doclist = get_mapped_doclist("Sales Order", source_name, { "Sales Order": { "doctype": "Maintenance Schedule", "field_map": { "name": "sales_order_no" }, "validation": { "docstatus": ["=", 1] } }, "Sales Order Item": { "doctype": "Maintenance Schedule Item", "field_map": { "parent": "prevdoc_docname" }, "add_if_empty": True } }, target_doclist) return [d.fields for d in doclist]
def make_quotation(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): quotation = webnotes.bean(target) quotation.run_method("onload_post_render") quotation.run_method("calculate_taxes_and_totals") doclist = get_mapped_doclist( "Opportunity", source_name, { "Opportunity": { "doctype": "Quotation", "field_map": { "enquiry_from": "quotation_to", "enquiry_type": "order_type", "name": "enq_no", }, "validation": { "docstatus": ["=", 1] } }, "Opportunity Item": { "doctype": "Quotation Item", "field_map": { "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", "uom": "stock_uom" }, "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_maintenance_visit(source_name, target_doclist=None): visit = webnotes.conn.sql("""select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1 and t1.completion_status='Fully Completed'""", source_name) if not visit: doclist = get_mapped_doclist("Sales Order", source_name, { "Sales Order": { "doctype": "Maintenance Visit", "field_map": { "name": "sales_order_no" }, "validation": { "docstatus": ["=", 1] } }, "Sales Order Item": { "doctype": "Maintenance Visit Purpose", "field_map": { "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype" }, "add_if_empty": True } }, target_doclist) return [d.fields for d in doclist]
def create_report(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Tour Details", source_name, {"Tour Details": { "doctype": "Tour Report", "field_map": { "from_date": "from_date", "to_date": "to_date" }, "validation": { "docstatus": ["=", 1] } }, "Tour Client Details": { "doctype": "Tour Daily Report", "field_map": { "client_name": "client_name", "contact_person":"contact_person" }, "add_if_empty": True } }, target_doclist) return [d if isinstance(d, dict) else d.fields for d in doclist]
def make_stock_entry(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_purpose(source, target): target[0].purpose = "Material Transfer" doclist = get_mapped_doclist("Material Request", source_name, { "Material Request": { "doctype": "Stock Entry", "validation": { "docstatus": ["=", 1], "material_request_type": ["=", "Transfer"] } }, "Material Request Item": { "doctype": "Stock Entry Detail", "field_map": { "name": "material_request_item", "parent": "material_request", "uom": "stock_uom", "warehouse": "t_warehouse" }, "postprocess": update_item } }, target_doclist, set_purpose) return [d.fields for d in doclist]
def make_maintenance_visit(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def update_status(source, target, parent): target.maintenance_type = "Scheduled" doclist = get_mapped_doclist("Maintenance Schedule", source_name, { "Maintenance Schedule": { "doctype": "Maintenance Visit", "field_map": { "name": "maintenance_schedule" }, "validation": { "docstatus": ["=", 1] }, "postprocess": update_status }, "Maintenance Schedule Item": { "doctype": "Maintenance Visit Purpose", "field_map": { "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", "incharge_name": "service_person" } } }, target_doclist) return [d.fields for d in doclist]
def make_purchase_invoice(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("set_missing_values") bean.run_method("set_supplier_defaults") doclist = get_mapped_doclist("Purchase Receipt", source_name, { "Purchase Receipt": { "doctype": "Purchase Invoice", "validation": { "docstatus": ["=", 1], } }, "Purchase Receipt Item": { "doctype": "Purchase Invoice Item", "field_map": { "name": "pr_detail", "parent": "purchase_receipt", "prevdoc_detail_docname": "po_detail", "prevdoc_docname": "purchase_order", "purchase_rate": "rate" }, }, "Purchase Taxes and Charges": { "doctype": "Purchase Taxes and Charges", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def _make_customer(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): if source.doc.company_name: target[0].customer_type = "Company" target[0].customer_name = source.doc.company_name else: target[0].customer_type = "Individual" target[0].customer_name = source.doc.lead_name target[0].customer_group = webnotes.conn.get_default("customer_group") doclist = get_mapped_doclist("Lead", source_name, {"Lead": { "doctype": "Customer", "field_map": { "name": "lead_name", "company_name": "customer_name", "contact_no": "phone_1", "fax": "fax_1" } }}, target_doclist, set_missing_values, ignore_permissions=ignore_permissions) return [d.fields for d in doclist]
def make_purchase_order(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist( "Material Request", source_name, { "Material Request": { "doctype": "Purchase Order", "validation": { "docstatus": ["=", 1], "material_request_type": ["=", "Purchase"] } }, "Material Request Item": { "doctype": "Purchase Order Item", "field_map": [["name", "prevdoc_detail_docname"], ["parent", "prevdoc_docname"], ["parenttype", "prevdoc_doctype"], ["uom", "stock_uom"], ["uom", "uom"]], "postprocess": update_item } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_quotation(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Opportunity", source_name, { "Opportunity": { "doctype": "Quotation", "field_map": { "enquiry_from": "quotation_to", "enquiry_type": "order_type", "name": "enq_no", }, "validation": { "docstatus": ["=", 1] } }, "Opportunity Item": { "doctype": "Quotation Item", "field_map": { "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", "uom": "stock_uom" }, "add_if_empty": True } }, target_doclist) return [d.fields for d in doclist]
def make_installation_note(source_name, target_doclist=None): def update_item(obj, target, source_parent): target.qty = flt(obj.qty) - flt(obj.installed_qty) target.serial_no = obj.serial_no doclist = get_mapped_doclist( "Delivery Note", source_name, { "Delivery Note": { "doctype": "Installation Note", "validation": { "docstatus": ["=", 1] } }, "Delivery Note Item": { "doctype": "Installation Note Item", "field_map": { "name": "prevdoc_detail_docname", "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", }, "postprocess": update_item, "condition": lambda doc: doc.installed_qty < doc.qty } }, target_doclist) return [d.fields for d in doclist]
def make_purchase_invoice(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("set_missing_values") bean.run_method("set_supplier_defaults") doclist = get_mapped_doclist( "Purchase Receipt", source_name, { "Purchase Receipt": { "doctype": "Purchase Invoice", "validation": { "docstatus": ["=", 1], } }, "Purchase Receipt Item": { "doctype": "Purchase Invoice Item", "field_map": { "name": "pr_detail", "parent": "purchase_receipt", "prevdoc_detail_docname": "po_detail", "prevdoc_docname": "purchase_order", "purchase_rate": "rate" }, }, "Purchase Taxes and Charges": { "doctype": "Purchase Taxes and Charges", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_sales_invoice(source_name, target_doclist=None): def update_item(obj, target, source_parent): target.export_amount = flt(obj.export_amount) - flt(obj.billed_amt) target.amount = target.export_amount * flt(source_parent.conversion_rate) target.qty = obj.export_rate and target.export_amount / flt(obj.export_rate) or obj.qty doclist = get_mapped_doclist("Sales Order", source_name, { "Sales Order": { "doctype": "Sales Invoice", "validation": { "docstatus": ["=", 1] } }, "Sales Order Item": { "doctype": "Sales Invoice Item", "field_map": { "name": "so_detail", "parent": "sales_order", "reserved_warehouse": "warehouse" }, "postprocess": update_item, "condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.export_amount }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_installation_note(source_name, target_doclist=None): def update_item(obj, target, source_parent): target.qty = flt(obj.qty) - flt(obj.installed_qty) target.prevdoc_date = source_parent.posting_date target.serial_no = obj.serial_no doclist = get_mapped_doclist("Delivery Note", source_name, { "Delivery Note": { "doctype": "Installation Note", "validation": { "docstatus": ["=", 1] } }, "Delivery Note Item": { "doctype": "Installation Note Item", "field_map": { "name": "prevdoc_detail_docname", "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", }, "postprocess": update_item, "condition": lambda doc: doc.installed_qty < doc.qty } }, target_doclist) return [d.fields for d in doclist]
def make_purchase_invoice(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("set_missing_values") bean.run_method("set_supplier_defaults") def update_item(obj, target, source_parent): target.conversion_factor = 1 target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt) target.amount = target.import_amount / flt(source_parent.conversion_rate) if flt(obj.purchase_rate): target.qty = target.amount / flt(obj.purchase_rate) doclist = get_mapped_doclist( "Purchase Order", source_name, { "Purchase Order": {"doctype": "Purchase Invoice", "validation": {"docstatus": ["=", 1]}}, "Purchase Order Item": { "doctype": "Purchase Invoice Item", "field_map": {"name": "po_detail", "parent": "purchase_order", "purchase_rate": "rate"}, "postprocess": update_item, "condition": lambda doc: doc.amount == 0 or doc.billed_amt < doc.import_amount, }, "Purchase Taxes and Charges": {"doctype": "Purchase Taxes and Charges", "add_if_empty": True}, }, target_doclist, set_missing_values, ) return [d.fields for d in doclist]
def make_stock_entry(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def update_item(obj, target, source_parent): target.conversion_factor = 1 target.qty = flt(obj.qty) - flt(obj.ordered_qty) target.transfer_qty = flt(obj.qty) - flt(obj.ordered_qty) def set_missing_values(source, target): target[0].purpose = "Material Transfer" se = webnotes.bean(target) se.run_method("get_stock_and_rate") doclist = get_mapped_doclist( "Material Request", source_name, { "Material Request": { "doctype": "Stock Entry", "validation": { "docstatus": ["=", 1], "material_request_type": ["=", "Transfer"] } }, "Material Request Item": { "doctype": "Stock Entry Detail", "field_map": { "name": "material_request_item", "parent": "material_request", "uom": "stock_uom", "warehouse": "t_warehouse" }, "postprocess": update_item } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_sales_invoice(source_name, target_doclist=None): def update_item(obj, target, source_parent): target.export_amount = flt(obj.amount) target.amount = target.export_amount / flt(source_parent.conversion_rate) target.qty = obj.basic_rate and target.amount / flt(obj.basic_rate) or obj.qty def update_accounts(source, target): si = webnotes.bean(target) si.run_method("onload_post_render") doclist = get_mapped_doclist( "Delivery Note", source_name, { "Delivery Note": {"doctype": "Sales Invoice", "validation": {"docstatus": ["=", 1]}}, "Delivery Note Item": { "doctype": "Sales Invoice Item", "field_map": { "name": "dn_detail", "parent": "delivery_note", "prevdoc_detail_docname": "so_detail", "prevdoc_docname": "sales_order", "serial_no": "serial_no", }, "postprocess": update_item, }, "Sales Taxes and Charges": {"doctype": "Sales Taxes and Charges", "add_if_empty": True}, "Sales Team": {"doctype": "Sales Team", "field_map": {"incentives": "incentives"}, "add_if_empty": True}, }, target_doclist, update_accounts, ) return [d.fields for d in doclist]
def make_maintenance_visit(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist visit = webnotes.conn.sql( """select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1 and t1.completion_status='Fully Completed'""", source_name, ) if not visit: doclist = get_mapped_doclist( "Customer Issue", source_name, { "Customer Issue": { "doctype": "Maintenance Visit", "field_map": {"complaint": "description", "doctype": "prevdoc_doctype", "name": "prevdoc_docname"}, } }, target_doclist, ) return [d.fields for d in doclist]
def make_purchase_order(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Material Request", source_name, { "Material Request": { "doctype": "Purchase Order", "validation": { "docstatus": ["=", 1], "material_request_type": ["=", "Purchase"] } }, "Material Request Item": { "doctype": "Purchase Order Item", "field_map": [ ["name", "prevdoc_detail_docname"], ["parent", "prevdoc_docname"], ["parenttype", "prevdoc_doctype"], ["uom", "stock_uom"], ["uom", "uom"] ], "postprocess": update_item } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_quotation(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): quotation = webnotes.bean(target) quotation.run_method("onload_post_render") quotation.run_method("calculate_taxes_and_totals") doclist = get_mapped_doclist("Opportunity", source_name, { "Opportunity": { "doctype": "Quotation", "field_map": { "enquiry_from": "quotation_to", "enquiry_type": "order_type", "name": "enq_no", }, "validation": { "docstatus": ["=", 1] } }, "Opportunity Item": { "doctype": "Quotation Item", "field_map": { "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", "uom": "stock_uom" }, "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_stock_entry(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def update_item(obj, target, source_parent): target.conversion_factor = 1 target.qty = flt(obj.qty) - flt(obj.ordered_qty) target.transfer_qty = flt(obj.qty) - flt(obj.ordered_qty) def set_missing_values(source, target): target[0].purpose = "Material Transfer" se = webnotes.bean(target) se.run_method("get_stock_and_rate") doclist = get_mapped_doclist("Material Request", source_name, { "Material Request": { "doctype": "Stock Entry", "validation": { "docstatus": ["=", 1], "material_request_type": ["=", "Transfer"] } }, "Material Request Item": { "doctype": "Stock Entry Detail", "field_map": { "name": "material_request_item", "parent": "material_request", "uom": "stock_uom", "warehouse": "t_warehouse" }, "postprocess": update_item } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def _make_internal_order(source_name, target_doclist=None, ignore_permissions=False): #webnotes.errprint("in make internal order 2") from webnotes.model.mapper import get_mapped_doclist customer = _make_customer(source_name, ignore_permissions) def set_missing_values(source, target): if customer: target[0].customer = customer.doc.name target[0].customer_name = customer.doc.customer_name si = webnotes.bean(target) si.run_method("onload_post_render") doclist = get_mapped_doclist("Sales Order", source_name, { "Sales Order": { "doctype": "Internal Order Form", "validation": { "docstatus": ["=", 1] } }, "Accessories Details": { "doctype": "Accessories Details", "field_map": { "parent": "prevdoc_docname" } }, "Customer Details": { "doctype": "Internal Order Customer Details", "field_map": { "parent": "prevdoc_docname" } }, "Consignee Details": { "doctype": "Internal Order Consignee Details", "field_map": { "parent": "prevdoc_docname" } }, "Sales Order Item": { "doctype": "Internal Order Item Details", "field_map": { "parent": "prevdoc_docname" } }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values, ignore_permissions=ignore_permissions) # postprocess: fetch shipping address, set missing values return [d.fields for d in doclist]
def make_stock_entry(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_purpose(source, target): target[0].purpose = "Material Transfer" doclist = get_mapped_doclist( "Material Request", source_name, { "Material Request": { "doctype": "Stock Entry", "validation": { "docstatus": ["=", 1], "material_request_type": ["=", "Transfer"] } }, "Material Request Item": { "doctype": "Stock Entry Detail", "field_map": { "name": "material_request_item", "parent": "material_request", "uom": "stock_uom", "warehouse": "t_warehouse" }, "postprocess": update_item } }, target_doclist, set_purpose) return [d.fields for d in doclist]
def make_sales_invoice(source_name, target_doclist=None): invoiced_qty_map = get_invoiced_qty_map(source_name) def update_accounts(source, target): si = webnotes.bean(target) si.doc.is_pos = 0 si.run_method("onload_post_render") si.set_doclist( si.doclist.get({"parentfield": ["!=", "entries"]}) + si.doclist.get({ "parentfield": "entries", "qty": [">", 0] })) if len(si.doclist.get({"parentfield": "entries"})) == 0: webnotes.msgprint( _("Hey! All these items have already been invoiced."), raise_exception=True) return si.doclist def update_item(source_doc, target_doc, source_parent): target_doc.qty = source_doc.qty - invoiced_qty_map.get( source_doc.name, 0) doclist = get_mapped_doclist( "Delivery Note", source_name, { "Delivery Note": { "doctype": "Sales Invoice", "validation": { "docstatus": ["=", 1] } }, "Delivery Note Item": { "doctype": "Sales Invoice Item", "field_map": { "name": "dn_detail", "parent": "delivery_note", "prevdoc_detail_docname": "so_detail", "against_sales_order": "sales_order", "serial_no": "serial_no" }, "postprocess": update_item }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "field_map": { "incentives": "incentives" }, "add_if_empty": True } }, target_doclist, update_accounts) return [d.fields for d in doclist]
def fetch_appraisal_template(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist( "Appraisal Template", source_name, {"Appraisal Template": {"doctype": "Appraisal"}, "Appraisal Template Goal": {"doctype": "Appraisal Goal"}}, target_doclist, ) return [d.fields for d in doclist]
def make_journal_voucher(source_name, target_doclist=None): doc_list = get_mapped_doclist("Sales Order", source_name, { "Sales Order Payment": { "doctype": "Journal Voucher", "field_map": { }, "validation": { "mode_of_payment": ["!=", "Cheque"] } } })
def make_purchase_invoice(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist invoiced_qty_map = get_invoiced_qty_map(source_name) def set_missing_values(source, target): pi = webnotes.bean(target) pi.run_method("set_missing_values") pi.run_method("set_supplier_defaults") pi.set_doclist( pi.doclist.get({"parentfield": ["!=", "entries"]}) + pi.doclist.get({ "parentfield": "entries", "qty": [">", 0] })) if len(pi.doclist.get({"parentfield": "entries"})) == 0: webnotes.msgprint(_("All items have already been invoiced."), raise_exception=True) return pi.doclist def update_item(source_doc, target_doc, source_parent): target_doc.qty = source_doc.qty - invoiced_qty_map.get( source_doc.name, 0) doclist = get_mapped_doclist( "Purchase Receipt", source_name, { "Purchase Receipt": { "doctype": "Purchase Invoice", "validation": { "docstatus": ["=", 1], } }, "Purchase Receipt Item": { "doctype": "Purchase Invoice Item", "field_map": { "name": "pr_detail", "parent": "purchase_receipt", "prevdoc_detail_docname": "po_detail", "prevdoc_docname": "purchase_order", "purchase_rate": "rate" }, "postprocess": update_item }, "Purchase Taxes and Charges": { "doctype": "Purchase Taxes and Charges", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_sales_invoice(source_name, target_doclist=None): invoiced_qty_map = get_invoiced_qty_map(source_name) def update_accounts(source, target): si = webnotes.bean(target) si.doc.is_pos = 0 si.run_method("onload_post_render") si.set_doclist(si.doclist.get({"parentfield": ["!=", "entries"]}) + si.doclist.get({"parentfield": "entries", "qty": [">", 0]})) if len(si.doclist.get({"parentfield": "entries"})) == 0: webnotes.msgprint(_("Hey! All these items have already been invoiced."), raise_exception=True) return si.doclist def update_item(source_doc, target_doc, source_parent): target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0) doclist = get_mapped_doclist("Delivery Note", source_name, { "Delivery Note": { "doctype": "Sales Invoice", "validation": { "docstatus": ["=", 1] } }, "Delivery Note Item": { "doctype": "Sales Invoice Item", "field_map": { "name": "dn_detail", "parent": "delivery_note", "prevdoc_detail_docname": "so_detail", "prevdoc_docname": "sales_order", "serial_no": "serial_no" }, "postprocess": update_item }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "field_map": { "incentives": "incentives" }, "add_if_empty": True } }, target_doclist, update_accounts) return [d.fields for d in doclist]
def _make_sales_order(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist customer = _make_customer(source_name, ignore_permissions) def set_missing_values(source, target): if customer: target[0].customer = customer.doc.name target[0].customer_name = customer.doc.customer_name si = webnotes.bean(target) si.run_method("onload_post_render") doclist = get_mapped_doclist("Quotation", source_name, { "Quotation": { "doctype": "Sales Order", "validation": { "docstatus": ["=", 1] } }, "Accessories Details": { "doctype": "Accessories Details", "field_map": { "parent": "prevdoc_docname" } }, "Quotation Item": { "doctype": "Sales Order Item", "field_map": { "parent": "prevdoc_docname" } }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values, ignore_permissions=ignore_permissions) # postprocess: fetch shipping address, set missing values return [d.fields for d in doclist]
def make_opportunity(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Lead", source_name, {"Lead": { "doctype": "Opportunity", "field_map": { "campaign_name": "campaign", "doctype": "enquiry_from", "name": "lead", } }}, target_doclist) return [d.fields for d in doclist]
def fetch_appraisal_template(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist( "Appraisal Template", source_name, { "Appraisal Template": { "doctype": "Appraisal", }, "Appraisal Template Goal": { "doctype": "Appraisal Goal", } }, target_doclist) return [d.fields for d in doclist]
def _calculate_testing_of_extract(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Sediment", source_name, { "Sediment": { "doctype": "Test Of Extract", "validation": { "docstatus": ["=", 1] } } },target_doclist) return [d.fields for d in doclist]
def _calculate_neutralization_value(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Resistivity and Dissipation", source_name, { "Resistivity and Dissipation": { "doctype": "Neutralization Value", "validation": { "docstatus": ["=", 1] } } },target_doclist) return [d.fields for d in doclist]
def make_opportunity(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist( "Lead", source_name, { "Lead": { "doctype": "Opportunity", "field_map": { "campaign_name": "campaign", "doctype": "enquiry_from", "name": "lead", } } }, target_doclist) return [d.fields for d in doclist]
def _make_provisional_sales_order(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist customer = _make_customer(source_name, ignore_permissions) def set_missing_values(source, target): if customer: target[0].customer = customer.doc.name target[0].customer_name = customer.doc.customer_name target[0].sales_order_type = 'Provisional' si = webnotes.bean(target) si.run_method("onload_post_render") doclist = get_mapped_doclist("Quotation", source_name, { "Quotation": { "doctype": "Sales Order", "validation": { "docstatus": ["=", 1] } }, "Quotation Item": { "doctype": "Sales Order Item", "field_map": { "parent": "prevdoc_docname" } }, # "Quotation Product": { # "doctype": "Sales Order Product", # "field_map": { # "parent": "prevdoc_docname" # } # }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values, ignore_permissions=ignore_permissions) # postprocess: fetch shipping address, set missing values return [d.fields for d in doclist]
def make_delivery_note(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("onload_post_render") def update_item(source_doc, target_doc, source_parent): target_doc.amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \ flt(source_doc.basic_rate) target_doc.export_amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \ flt(source_doc.export_rate) target_doc.qty = flt(source_doc.qty) - flt(source_doc.delivered_qty) doclist = get_mapped_doclist( "Sales Invoice", source_name, { "Sales Invoice": { "doctype": "Delivery Note", "validation": { "docstatus": ["=", 1] } }, "Sales Invoice Item": { "doctype": "Delivery Note Item", "field_map": { "name": "prevdoc_detail_docname", "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", "serial_no": "serial_no" }, "postprocess": update_item }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "field_map": { "incentives": "incentives" }, "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_sales_invoice(source_name, target_doclist=None): def set_missing_values(source, target): bean = webnotes.bean(target) bean.doc.is_pos = 0 bean.run_method("onload_post_render") def update_item(obj, target, source_parent): target.export_amount = flt(obj.export_amount) - flt(obj.billed_amt) target.amount = target.export_amount * flt( source_parent.conversion_rate) target.qty = obj.export_rate and target.export_amount / flt( obj.export_rate) or obj.qty doclist = get_mapped_doclist( "Sales Order", source_name, { "Sales Order": { "doctype": "Sales Invoice", "validation": { "docstatus": ["=", 1] } }, "Sales Order Item": { "doctype": "Sales Invoice Item", "field_map": { "name": "so_detail", "parent": "sales_order", "reserved_warehouse": "warehouse" }, "postprocess": update_item, "condition": lambda doc: doc.amount == 0 or doc.billed_amt < doc. export_amount }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_delivery_note(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("onload_post_render") def update_item(source_doc, target_doc, source_parent): target_doc.amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \ flt(source_doc.basic_rate) target_doc.export_amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \ flt(source_doc.export_rate) target_doc.qty = flt(source_doc.qty) - flt(source_doc.delivered_qty) doclist = get_mapped_doclist("Sales Invoice", source_name, { "Sales Invoice": { "doctype": "Delivery Note", "validation": { "docstatus": ["=", 1] } }, "Sales Invoice Item": { "doctype": "Delivery Note Item", "field_map": { "name": "prevdoc_detail_docname", "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", "serial_no": "serial_no" }, "postprocess": update_item }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "field_map": { "incentives": "incentives" }, "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_purchase_invoice(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("set_missing_values") bean.run_method("set_supplier_defaults") def update_item(obj, target, source_parent): target.conversion_factor = 1 target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt) target.amount = target.import_amount * flt( source_parent.conversion_rate) if flt(obj.purchase_rate): target.qty = target.amount / flt(obj.purchase_rate) doclist = get_mapped_doclist( "Purchase Order", source_name, { "Purchase Order": { "doctype": "Purchase Invoice", "validation": { "docstatus": ["=", 1], } }, "Purchase Order Item": { "doctype": "Purchase Invoice Item", "field_map": { "name": "po_detail", "parent": "purchase_order", "purchase_rate": "rate" }, "postprocess": update_item, "condition": lambda doc: doc.amount == 0 or doc.billed_amt < doc. import_amount }, "Purchase Taxes and Charges": { "doctype": "Purchase Taxes and Charges", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_purchase_invoice(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist invoiced_qty_map = get_invoiced_qty_map(source_name) def set_missing_values(source, target): pi = webnotes.bean(target) pi.run_method("set_missing_values") pi.run_method("set_supplier_defaults") pi.set_doclist(pi.doclist.get({"parentfield": ["!=", "entries"]}) + pi.doclist.get({"parentfield": "entries", "qty": [">", 0]})) if len(pi.doclist.get({"parentfield": "entries"})) == 0: webnotes.msgprint(_("All items have already been invoiced."), raise_exception=True) return pi.doclist def update_item(source_doc, target_doc, source_parent): target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0) doclist = get_mapped_doclist("Purchase Receipt", source_name, { "Purchase Receipt": { "doctype": "Purchase Invoice", "validation": { "docstatus": ["=", 1], } }, "Purchase Receipt Item": { "doctype": "Purchase Invoice Item", "field_map": { "name": "pr_detail", "parent": "purchase_receipt", "prevdoc_detail_docname": "po_detail", "prevdoc_docname": "purchase_order", "purchase_rate": "rate" }, "postprocess": update_item }, "Purchase Taxes and Charges": { "doctype": "Purchase Taxes and Charges", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def _sample_allocation_to_tester(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist # webnotes.errprint(source_name) def postprocess(source, doclist): #webnotes.errprint(source_name) doclist[0].sample_allocation_lab= source_name doclist = get_mapped_doclist("Sample Allocation To Lab", source_name, { "Sample Allocation To Lab": { "doctype": "Sample Allocation", "validation": { "docstatus": ["=", 1] } } },target_doclist ,postprocess) return [d.fields for d in doclist]
def _create_sample_allocation_to_lab(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Test Allocation Interface", source_name, { "Test Allocation Interface": { "doctype": "Sample Allocation To Lab", "validation": { "docstatus": ["=", 0] } } },target_doclist) return [d.fields for d in doclist]
def make_opportunity(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Lead", source_name, {"Lead": { "doctype": "Opportunity", "field_map": { "campaign_name": "campaign", "doctype": "enquiry_from", "name": "lead", "lead_name": "contact_display", "company_name": "customer_name", "email_id": "contact_email", "mobile_no": "contact_mobile" } }}, target_doclist) return [d if isinstance(d, dict) else d.fields for d in doclist]
def make_quotation(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Tender", source_name, {"Tender": { "doctype": "Quotation", "field_map": { # "campaign_name": "campaign", # "doctype": "enquiry_from", # "name": "lead", # "lead_name": "contact_display", # "company_name": "customer_name", # "email_id": "contact_email", # "mobile_no": "contact_mobile" } }}, target_doclist) #webnotes.msgprint([d if isinstance(d, dict) else d.fields for d in doclist]) return [d if isinstance(d, dict) else d.fields for d in doclist]
def make_delivery_note(source_name, target_doclist=None): def update_item(obj, target, source_parent): target.amount = (flt(obj.qty) - flt(obj.delivered_qty)) * flt( obj.basic_rate) target.export_amount = (flt(obj.qty) - flt(obj.delivered_qty)) * flt( obj.export_rate) target.qty = flt(obj.qty) - flt(obj.delivered_qty) doclist = get_mapped_doclist( "Sales Order", source_name, { "Sales Order": { "doctype": "Delivery Note", "field_map": { "shipping_address": "address_display", "shipping_address_name": "customer_address", }, "validation": { "docstatus": ["=", 1] } }, "Sales Order Item": { "doctype": "Delivery Note Item", "field_map": { "export_rate": "export_rate", "name": "prevdoc_detail_docname", "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", "reserved_warehouse": "warehouse" }, "postprocess": update_item, "condition": lambda doc: doc.delivered_qty < doc.qty }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_purchase_receipt(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("set_missing_values") def update_item(obj, target, source_parent): target.qty = flt(obj.qty) - flt(obj.received_qty) target.stock_qty = (flt(obj.qty) - flt(obj.received_qty)) * flt( obj.conversion_factor) target.import_amount = (flt(obj.qty) - flt(obj.received_qty)) * flt( obj.import_rate) target.amount = (flt(obj.qty) - flt(obj.received_qty)) * flt( obj.purchase_rate) doclist = get_mapped_doclist( "Purchase Order", source_name, { "Purchase Order": { "doctype": "Purchase Receipt", "validation": { "docstatus": ["=", 1], } }, "Purchase Order Item": { "doctype": "Purchase Receipt Item", "field_map": { "name": "prevdoc_detail_docname", "qty": "received_qty", "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", }, "postprocess": update_item, "condition": lambda doc: doc.received_qty < doc.qty }, "Purchase Taxes and Charges": { "doctype": "Purchase Taxes and Charges", "add_if_empty": True } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_purchase_order_based_on_supplier(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist if target_doclist: if isinstance(target_doclist, basestring): import json target_doclist = webnotes.doclist(json.loads(target_doclist)) target_doclist = target_doclist.get( {"parentfield": ["!=", "po_details"]}) material_requests, supplier_items = get_material_requests_based_on_supplier( source_name) def postprocess(source, target_doclist): target_doclist[0].supplier = source_name set_missing_values(source, target_doclist) po_items = target_doclist.get({"parentfield": "po_details"}) target_doclist = target_doclist.get({"parentfield": ["!=", "po_details"]}) + \ [d for d in po_items if d.fields.get("item_code") in supplier_items and d.fields.get("qty") > 0] return target_doclist for mr in material_requests: target_doclist = get_mapped_doclist( "Material Request", mr, { "Material Request": { "doctype": "Purchase Order", }, "Material Request Item": { "doctype": "Purchase Order Item", "field_map": [["name", "prevdoc_detail_docname"], ["parent", "prevdoc_docname"], ["parenttype", "prevdoc_doctype"], ["uom", "stock_uom"], ["uom", "uom"]], "postprocess": update_item } }, target_doclist, postprocess) return [d.fields for d in target_doclist]
def make_maintenance_visit(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist visit = webnotes.conn.sql("""select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1 and t1.completion_status='Fully Completed'""", source_name) if not visit: doclist = get_mapped_doclist("Customer Issue", source_name, { "Customer Issue": { "doctype": "Maintenance Visit", "field_map": { "complaint": "description", "doctype": "prevdoc_doctype", "name": "prevdoc_docname" } } }, target_doclist) return [d.fields for d in doclist]
def make_supplier_quotation(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist doclist = get_mapped_doclist("Material Request", source_name, { "Material Request": { "doctype": "Supplier Quotation", "validation": { "docstatus": ["=", 1], "material_request_type": ["=", "Purchase"] } }, "Material Request Item": { "doctype": "Supplier Quotation Item", "field_map": { "name": "prevdoc_detail_docname", "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype" } } }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_purchase_order(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def set_missing_values(source, target): bean = webnotes.bean(target) bean.run_method("set_missing_values") bean.run_method("get_schedule_dates") def update_item(obj, target, source_parent): target.conversion_factor = 1 doclist = get_mapped_doclist( "Supplier Quotation", source_name, { "Supplier Quotation": { "doctype": "Purchase Order", "validation": { "docstatus": ["=", 1], } }, "Supplier Quotation Item": { "doctype": "Purchase Order Item", "field_map": [["name", "supplier_quotation_item"], ["parent", "supplier_quotation"], ["uom", "stock_uom"], ["uom", "uom"], ["prevdoc_detail_docname", "prevdoc_detail_docname"], ["prevdoc_doctype", "prevdoc_doctype"], ["prevdoc_docname", "prevdoc_docname"]], "postprocess": update_item }, "Purchase Taxes and Charges": { "doctype": "Purchase Taxes and Charges", "add_if_empty": True }, }, target_doclist, set_missing_values) return [d.fields for d in doclist]
def make_material_request(source_name, target_doclist=None): def postprocess(source, doclist): doclist[0].material_request_type = "Purchase" doclist = get_mapped_doclist("Sales Order", source_name, { "Sales Order": { "doctype": "Material Request", "validation": { "docstatus": ["=", 1] } }, "Sales Order Item": { "doctype": "Material Request Item", "field_map": { "parent": "sales_order_no", "reserved_warehouse": "warehouse", "stock_uom": "uom" } } }, target_doclist, postprocess) return [(d if isinstance(d, dict) else d.fields) for d in doclist]
def make_salary_slip(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist def postprocess(source, target): sal_slip = webnotes.bean(target) sal_slip.run_method("pull_emp_details") sal_slip.run_method("get_leave_details") sal_slip.run_method("calculate_net_pay") doclist = get_mapped_doclist( "Salary Structure", source_name, { "Salary Structure": { "doctype": "Salary Slip", "field_map": { "total_earning": "gross_pay" } }, "Salary Structure Deduction": { "doctype": "Salary Slip Deduction", "field_map": [["depend_on_lwp", "d_depends_on_lwp"], ["d_modified_amt", "d_amount"], ["d_modified_amt", "d_modified_amount"]], "add_if_empty": True }, "Salary Structure Earning": { "doctype": "Salary Slip Earning", "field_map": [["depend_on_lwp", "e_depends_on_lwp"], ["modified_value", "e_modified_amount"], ["modified_value", "e_amount"]], "add_if_empty": True } }, target_doclist, postprocess) return [d.fields for d in doclist]
def make_salary_slip(source_name, target_doclist=None): return [d.fields for d in get_mapped_doclist(source_name, target_doclist)]