ERPNext Conference 2019* ERPNext.com Blog

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


#1

hello,

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.


#2

i have tried to code but fails:

frappe.ui.form.on("Purchase Order", {
  refresh: function(frm) {
    frm.add_custom_button(__('Sales Order'), function() {
      erpnext.utils.map_current_doc({
      					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],
      						company: frm.doc.company
      					}
      				})
      }, __('Get items from'));
  },
})

i got error

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 62, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 939, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/mapper.py”, line 38, in map_docs
target_doc = method(src, target_doc)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/selling/doctype/sales_order/sales_order.py”, line 744, in make_purchase_order_for_drop_shipment
}, target_doc, set_missing_values)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/mapper.py”, line 110, in get_mapped_doc
postprocess(source_doc, target_doc)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/selling/doctype/sales_order/sales_order.py”, line 704, in set_missing_values
target.run_method(“set_missing_values”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1024, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1007, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 749, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py”, 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, company=self.company))
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, 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/init.py”, line 323, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 309, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 282, in _raise_exception
raise raise_exception(encode(msg))


#3

Hi,

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,
Bithons