Payment Entry - Sales Partner Commission

Hello,

I have a case where Sales Partners receive their commission when payments are received from customers. Customers have the chance to pay the total of a Sales Order along a 12 months period, but the Sales Partners have to collect payments on time.

You know that ‘Payment Entry’ and ‘Payment Entry Reference’ doesn’t use same names at fields like are at ‘Sales Order’. I need to fetch ‘Sales Partner’ and ‘Commission rate’ relative to the ‘Sales Order’.

I’ve being trying doing changes with this, but no luck. It has to be with javascript, because the account is hosted at Frappe.

With this…

frappe.ui.form.on("Payment Entry",{
	onload: function(frm) {
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "Sales Order",
				name: frm.doc.reference_name,
			},
			callback: function(r) {
				$.each(frm.doc.references || [], function(i, v) {
					frappe.model.set_value(v.doctype, v.name, "sales_partner", r.sales_partner),
					frappe.model.set_value(v.doctype, v.name, "commission_rate", r.commission_rate)
				})
				frm.refresh_field('references');
			}
		})
	}
})

I get…

With this (Payment Entry Reference)…

frappe.ui.form.on("Payment Entry Reference",{
	onload: function(frm) {
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "Sales Order",
				name: frm.doc.reference_name,
			},

I get nothing when load. But if I erase the Sales Order (‘Name’), then…

I have 3 days trying make it work…
Any help would be really appreciated!

@Francisco_Buendia

Instead of onload can you please check on the trigger of reference_name and instead of payment entry use doctype payment entry reference

frappe.ui.form.on('Payment Entry Reference', {
  reference_name: function (frm) {
     //Write your code here
  }
})

This is a very good feature, can you contribute this feature

Hi @rohit_w,
Thanks in advance for your help.

frappe.ui.form.on("Payment Entry Reference",{
	reference_name: function(frm) {
		frappe.call({

Nothing when it loads, but if a erase the value on ‘Name’ (reference_name or Sales Order number), results on “Server error: Please check your server logs”.

I’ve even tried using
frappe.client.get_value instead of frappe.client.get

Any other idea?
Don’t you find any mistake in the script?


I have in mind a major feature, precisely about the possibility to collect payments along 12 (or any number) of months or periods. There might be necessary to use a financial formula known as “Present Value”. Of course, I would like to contribute with ERPNext!!! After many attempts I was able to figure the script to calculate it and works perfectly.

Regards.

Yeah I missed one thing to mention in my previous reply, you have not defined the name of fields which you want to retrieve from the sales order. Please try below code

frappe.ui.form.on("Payment Entry Reference",{
	reference_name: function(frm, cdt, cdn) {
		var child = locals[cdt][cdn];
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "Sales Order",
				name: child.reference_name,
				fieldname: ['sales_partner', 'commission_rate']
			},
			callback: function(r) {
				frappe.model.set_value(cdt, cdn, "sales_partner", r.message.sales_partner),
				frappe.model.set_value(cdt, cdn, "commission_rate", r.message.commission_rate)
			}
		})
	}
})

Noup… nothing.

Same, nothing when loads the ‘Payment Entry’. If it’s erased the value at ‘Name’(reference_name or Sales Order number), results on “Server error: Please check your server logs”.

What could be failing?

Any error on browser’s console log? If yes please share traceback

@rohit_w,

No, when loads no. But when I erase ‘Name’ to see if any changes, shows message “Server error: Please check your server logs”. Appears two errors at console:

POST https://colinadeldescanso.erpnext.com/ 500 (INTERNAL SERVER ERROR)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
frappe.request.call @ desk.min.js?ver=1507717132.0:1464
frappe.call @ desk.min.js?ver=1507717132.0:1358
reference_name @ VM4468:1119
runner @ form.min.js?ver=1507717132.0:2550
(anonymous) @ form.min.js?ver=1507717132.0:2565
Promise resolved (async)
(anonymous) @ desk.min.js?ver=1507717132.0:665
frappe.run_serially @ desk.min.js?ver=1507717132.0:663
trigger @ form.min.js?ver=1507717132.0:2580
(anonymous) @ form.min.js?ver=1507717132.0:272
(anonymous) @ desk.min.js?ver=1507717132.0:5708
each @ jquery.min.js:2
runner @ desk.min.js?ver=1507717132.0:5706
(anonymous) @ desk.min.js?ver=1507717132.0:5725
Promise resolved (async)
(anonymous) @ desk.min.js?ver=1507717132.0:665
frappe.run_serially @ desk.min.js?ver=1507717132.0:663
trigger @ desk.min.js?ver=1507717132.0:5729
(anonymous) @ desk.min.js?ver=1507717132.0:5681
Promise resolved (async)
(anonymous) @ desk.min.js?ver=1507717132.0:665
frappe.run_serially @ desk.min.js?ver=1507717132.0:663
set_value @ desk.min.js?ver=1507717132.0:5692
set_model_value @ control.min.js?ver=1507717132.0:210
(anonymous) @ control.min.js?ver=1507717132.0:179
Promise resolved (async)
(anonymous) @ desk.min.js?ver=1507717132.0:665
frappe.run_serially @ desk.min.js?ver=1507717132.0:663
set @ control.min.js?ver=1507717132.0:178
validate_and_set_in_model @ control.min.js?ver=1507717132.0:195
parse_validate_and_set_in_model @ control.min.js?ver=1507717132.0:168
(anonymous) @ control.min.js?ver=1507717132.0:1080
dispatch @ jquery.min.js:3
$event.dispatch @ report.min.js?ver=1507717132.0:3008
r.handle @ jquery.min.js:3

Uncaught (in promise) {readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}abort: ƒ (a)arguments: nullcaller: nulllength: 1name: “abort"prototype: {constructor: ƒ}constructor: ƒ (a)arguments: nullcaller: nulllength: 1name: “abort"prototype: constructor: ƒ (a)arguments: nullcaller: nulllength: 1name: “abort"prototype: {constructor: ƒ}proto: ƒ ()[[FunctionLocation]]: jquery.min.js:4[[Scopes]]: Scopes[3]proto: Object__proto__: ƒ ()[[FunctionLocation]]: jquery.min.js:4[[Scopes]]: Scopes[3]proto: Object__proto__: ƒ ()[[FunctionLocation]]: jquery.min.js:4[[Scopes]]: Scopes[3]always: ƒ ()complete: ƒ ()done: ƒ ()error: ƒ ()fail: ƒ ()getAllResponseHeaders: ƒ ()getResponseHeader: ƒ (a)overrideMimeType: ƒ (a)pipe: ƒ ()progress: ƒ ()promise: ƒ (a)readyState: 4responseJSON: {exc: “[“Traceback (most recent call last):\n File “/ho…details() takes exactly 3 arguments (2 given)\n”]”}responseText: “{“exc”:”[“Traceback (most recent call last):\n File \”/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/app.py\”, line 57, in application\n response = frappe.handler.handle()\n File \”/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/handler.py\”, line 22, in handle\n data = execute_cmd(cmd)\n File \”/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/handler.py\", line 53, in execute_cmd\n return frappe.call(method, **frappe.form_dict)\n File \"/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/init.py\", line 923, in call\n return fn(*args, **newargs)\nTypeError: get_reference_details() takes exactly 3 arguments (2 given)\n"]"}"setRequestHeader: ƒ (a,b)state: ƒ ()status: 500statusCode: ƒ (a)statusText: "INTERNAL SERVER ERROR"success: ƒ ()then: ƒ ()proto: Object

ResponseJSON:
exc : “[“Traceback (most recent call last):\n File “/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/app.py”, line 57, in application\n response = frappe.handler.handle()\n File “/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/handler.py”, line 22, in handle\n data = execute_cmd(cmd)\n File “/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/handler.py”, line 53, in execute_cmd\n return frappe.call(method, **frappe.form_dict)\n File “/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/init.py”, line 923, in call\n return fn(*args, **newargs)\nTypeError: get_reference_details() takes exactly 3 arguments (2 given)\n”]”

responseText: “{“exc”:”[“Traceback (most recent call last):\n File \”/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/app.py\", line 57, in application\n response = frappe.handler.handle()\n File \"/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/handler.py\", line 22, in handle\n data = execute_cmd(cmd)\n File \"/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/handler.py\", line 53, in execute_cmd\n return frappe.call(method, **frappe.form_dict)\n File \"/home/frappe/benches/bench-2017-10-11/apps/frappe/frappe/init.py\", line 923, in call\n return fn(*args, **newargs)\nTypeError: get_reference_details() takes exactly 3 arguments (2 given)\n"]"}"

@rohit_w any other idea that could work?
I have tried other ways, based on same scripts, but non works.

Thanks for all the time you have given on this!
Regards.