ERPNext Conference 2019* Blog

How to make "get items from sales order" in purchase order



could you please give me some hints how to make “get items from sales order” in purchase order? although i can make purchase order from sales order but this way is not what i want.

i have tried to read source code of sales invoice or delivery note about get items from sales order, but i do not have idea how to modify and make this work on purchase order.

please give some hints. thank you.


i have tried to code but fails:

frappe.ui.form.on("Purchase Order", {
  refresh: function(frm) {
    frm.add_custom_button(__('Sales Order'), function() {
      					method: "erpnext.selling.doctype.sales_order.sales_order.make_purchase_order_for_drop_shipment",
      					source_doctype: "Sales Order",
      					target: frm,
                for_supplier: frm.doc.supplier,
      					setters: {
      						customer: frm.doc.customer || undefined,
      					get_query_filters: {
      						docstatus: 1,
      						status: ["!=", "Closed"],
      						per_billed: ["<", 99.99],
      }, __('Get items from'));

i got error

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 62, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 53, in execute_cmd
return, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 939, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 38, in map_docs
target_doc = method(src, target_doc)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/selling/doctype/sales_order/”, line 744, in make_purchase_order_for_drop_shipment
}, target_doc, set_missing_values)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 110, in get_mapped_doc
postprocess(source_doc, target_doc)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/selling/doctype/sales_order/”, line 704, in set_missing_values
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1024, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1007, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 749, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/”, line 67, in set_missing_values
self.update_if_missing(get_party_details(self.supplier, party_type=“Supplier”, ignore_permissions=self.flags.ignore_permissions, doctype=self.doctype,
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/”, line 31, in get_party_details
frappe.throw(_("{0}: {1} does not exists").format(party_type, party))
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 323, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 309, in msgprint
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 282, in _raise_exception
raise raise_exception(encode(msg))



I am also interested in this feature. It should be even more perfect if I can directly create purchase order after a sales orders.

Best Regards,