Try ERPNext Buy Support Partners Foundation

Where is the syntax for "conditions" documented?

I see that various doctypes have fields for setting the conditions under which the doctype processes certain settings.

Here are the very few examples I was able to find searching this forum and the web:

Example: Salary Component …

base*1 if nationality == “saudi” and base < 4500 else 45 if nationality ==“saudi” and base >= 4500 else 40

Example: Sales Order …

eval:!in_list([“Services”, “Test”], doc.item_group)

Specifically, I’m trying without success to put multiple conditions of an “on_change” webhook for a Sales Invoice.

What works:

doc.status != "Draft"
doc.xml_file != "Home"

What fails:

eval: doc.status != "Draft"
eval:!(doc.status == "Draft")
eval: (doc.status != "Draft")
doc.xml_file != "Home",
doc.status != "Draft"
doc.xml_file not null and doc.status != "Draft"
doc.xml_file is not null and doc.status != "Draft"
doc.xml_file != "Home" && doc.status != "Draft"
!doc.xml_file

Questions:

Is it JavaScript? What vintage of Javascript?
Is it SQL? Can I use any where clause condition function?
is it Python?
When is eval necessary?
Where do base*1 and inlist come from?
Where are the docs?
Where’s the code?

Martin

My 2 cents the Salary code is regional setup, like for example:

in_list is Javascript?

My guess is depends_on is in the asyncio_posix.py MVC event loop?

eval() is a builtin function to evaluate REPL “read-eval-print loop” https://www.w3schools.com/python/ref_func_eval.asp

LOL yup Python and JS is kinda primitive, this ain’t Smalltalk - the batteries included code browser, builtin debugger, MVC, the full meal deal environment

No wonder it spawned Windows 1.0 and Macintosh!
:slight_smile:

This is fun of a different sort

Are you saying conditions syntax varies from doctype to doctype?

To me this is code browsing exercise perhaps someone can point us to a good example :wink:

Well fuck me, I found something that actually works…

doc.xml_file == "Home" and doc.status != "Draft"

It seems to be “sort of, kind of, maybe” SQL, but then again maybe not so much that either…
is null won’t work…

doc.xml_file is null and doc.status != "Draft"

It looks to me like the WebHooks developer went, “Oh, WebHooks need to be constrained by conditions!. COOL I’ve always wanted an excuse to develop my own Domain Specific Language. Yay!”

I’m really not in the mood to go spelunking something like that to figure out what it permits and what it doesn’t.

Except I cannot find a way to include it that the WebHooks doctype validator doesn’t immediately reject.

That’s not helpful.

Nope. Not SQL either. It might be a Frappe created MariaDb Stored Procedure. Who the fuck knows. Oh, hey it is a function in R language!! Well sheeee-it … conditions have to programmed in R! There ya go. Obvious once you see it.

This test I found nicely demos how depends_on and eval: work

I am a BIG believer in tests, ya know keep it simple LOL

If you can capture your conditional code learning in a test that would be superb etc

Yes.

But eval, used exactly as shown there, does not work as a part of a condition for a webhook.

It seems this is key to the puzzle but no expression parser or syntax scanner apparent here…

Both webhook condition:

And salary condition formula call safe_eval:

Now I recall this too Multiple conditions on Salary Structure with a single formula

Hope this helps

And oh yes for the sake of decorum please null the f- bombs Martin thanks!

Here’s test code that exercises one term conditions and formulae expressions

Sorry if I get exasperated.

I don’t know if you have understood what I have been working on.

Below I have posted a component diagram to clarify the main elements of the sequence diagram that follows it. They show the focus of my efforts for weeks now.

I think the record of my questions here shows that I have had to dedicate at least an entire day sometimes 3 or 4 days, picking through forum posts for each new major step in the operations shown:

  • Create new DocType as installed app.
  • Launch and Configure NodeJs app from within new DocType
  • Use socketio with NodeJs (complete fail, documented example does not work)
  • Hook action in Node Js from internal event with conditions
  • Customize DocType
  • Attach File to DocType
  • Obtain Record through API
  • Update Record through API

Including having to deal with yet more initial install and startup issues I have been at it for over three weeks.

The record also shows that I have tried to post complete functioning, useful solutions to the documentation deficiencies I encountered in every step of the process.

This nonsense with “conditions” was the last straw. I think I’ve earned the right be a tiny bit indelicate.


Components:

Electronic Invoice Handling Sequence:

I get this is how you express your need for help. Nonetheless discipline and respect will win you responses to fulfil your need. Just sayin!