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?

1 Like

Martin

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

https://github.com/frappe/erpnext/blob/develop/erpnext/regional/india/setup.py#L95

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” Python eval() Function

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…

https://github.com/frappe/frappe/blob/develop/frappe/\_\_init\_\_.py#L1597

Both webhook condition:

https://github.com/frappe/frappe/blob/develop/frappe/integrations/doctype/webhook/\_\_init\_\_.py#L65

And salary condition formula call safe_eval:

https://github.com/frappe/erpnext/blob/develop/erpnext/hr/doctype/salary_slip/salary_slip.py#L418

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
https://github.com/frappe/erpnext/blob/develop/erpnext/hr/doctype/salary_slip/test_salary_slip.py#L442

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:

1 Like

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!

1 Like

What we have tried as a condition for triggering a webhook when submitting a Sales Order:

for item in doc.get("items"):
  if "t-shirt bio" == item.item_code:
    return True

However, multiple lines are not allowed in ERPenxt, but needed with python. Anybody else solved a query in the item.code list?

So the condition field uses Python and the code you can write in here is
exactly what is allowed inside any “condition” in Python (like in if condition).

This is the same reason why multiple lines wont work, as python doesnt accept linebreaks in conditions without escapes.

If the conditions are many, then you will have to use and, or or or others like below, without linebreaks:
a==b and b!=c or c!=a and c>b

With escapes:
a==b and b~=c \
or c!=a and c>b

1 Like

Trying now this to send a welcome message to the customer as a condition for a Sales Order:

"package pro small" in [d.item_code for d in doc.get("items")] \
or "package pro medium" in [d.item_code for d in doc.get("items")] \
or "package pro large" in [d.item_code for d in doc.get("items")]

Is that a question?

@MartinHBramwell, here is another post after 1 year! :slight_smile:

Did you find out how to use conditions in webhook? Do you know if the conditions in webhook is the same as that in Salary Structure/Salary Slip?

I’m trying to access HolidayList from Salary Structure, and I tried using doc.get(“holidays”), and it says doc doesn’t exist.

Do you mind sharing how to look up other DocType’s variables?

Sorry. I’ve not looked at that since then. Two years gone by, in fact! Is it still undocumented?

May be we need to pay for this info… I’m not sure. what do you think?