Hi all
Hope this will help someone.
How to calculate fields in SEBLOD, short tutorial based on my needs. In my case Article <-> Product.
Idea: I have three fields need to multiply two of them to get third value and store it in DB. price_eur * exchange_rate = price_lvl
- price_eur - simple text field, I insert here product price in EUR, IT is PRIMARY and only changeable field for product, it means, I insert only price in EUR - one number, for example 100.
- exchange_rate - this field is hidden or in admin form is "somewhere in corner" away from eyes. Could make it visible, so if needed can change exchange rate, up to needs. IMPORTANT, when field is created you should insert default value for it, so you do not need insert it every time you make new product. And exchange rate is always saved in DB in my case. I believe that it is possible to make it more complicated with separate table with exchange rates, but ... then it is different story.
- price_lvl - text field which is empty until you fill field price_eur with some number and have Computation rules. After you fill price_eur and hit Tab or save product, field is calculated and saved in DB.
So, you have made 3 fields all are in Admin form.
Before this
VERY IMPORTANT thing is to check and to know SEBLOD Settings for computation rules and see what is used here comma or point. 123,4 or 123.4 . I have made mistake and my exchange rate was 0.7 but computation rules in Settings were with comma. So it never worked out.
Check SEBLOD Settings Next step, field price_lvl calculation. In admin form press 5 and for field Add computation rules in modal window
I have made Custom computation, but I believe that there are already made function, so I do not need to make it Custom, but it is up to you and your experiments. Add fields with which you want to make computation and save, try it then how it works.
For Computation modal window fields and formulas ... I didn't experimented, but I think that added fields are ordered as they stand in Fields column ordered a,b,c ... after in formulas the same a, b, c, d ... so you build formulas as (a*(d+c-d))/d , but I do not know is it so, so please experiment and let everyone to know.
I used Format/Precision toFixed with value 2 which gave me 2 numbers after comma.
So, in short: In Admin form I insert price in EUR , price for LVL is calculated and saved in DB.
Hope that it helps to someone.
Regards