computed values in extrafields

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

computed values in extrafields

Christophe Battarel

Hello,

I am trying to use computed values in extrafields but cannot understand how it works :

example : $object->id in a product extrafield !

i have done some investigations in the code and here is where i am :

there is two places where  ShowOutputField is coded : commonobject.class.php (where the dol_eval is called) and extrafields.class.php (used in product card to display extrafields but not calling dol_eval !).

doeas anyone (@eldy ?) can help me ? (i am on the develop branch).

Best regards

Christophe


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
Reply | Threaded
Open this post in threaded view
|

Re: computed values in extrafields

Maxime Kohlhaas
Hi Christophe,

On my side I tested with a simple formula :
image.png

And on the product card and in the product list I have this field calculated.
Test done in 9.0

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 10:52, Christophe Battarel <[hidden email]> a écrit :

Hello,

I am trying to use computed values in extrafields but cannot understand how it works :

example : $object->id in a product extrafield !

i have done some investigations in the code and here is where i am :

there is two places where  ShowOutputField is coded : commonobject.class.php (where the dol_eval is called) and extrafields.class.php (used in product card to display extrafields but not calling dol_eval !).

doeas anyone (@eldy ?) can help me ? (i am on the develop branch).

Best regards

Christophe

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
Reply | Threaded
Open this post in threaded view
|

Re: computed values in extrafields

Christophe Battarel

Hi Maxime,

Thanks for this quick answer !

unfortunately the following code is present in 9.0 but not in develop in extrafields.class.php :

        // If field is a computed field, value must become result of compute
        if ($computed)
        {
            // Make the eval of compute string
            //var_dump($computed);
            $value = dol_eval($computed, 1, 0);
        }

i do not understand why !

also, why this method is in two classes ? (extrafields and commonobject) not very easy to maintain, isnt'it ?

Best regards

Christophe


Le 11/07/2019 à 10:57, Maxime Kohlhaas a écrit :
Hi Christophe,

On my side I tested with a simple formula :
image.png

And on the product card and in the product list I have this field calculated.
Test done in 9.0

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 10:52, Christophe Battarel <[hidden email]> a écrit :

Hello,

I am trying to use computed values in extrafields but cannot understand how it works :

example : $object->id in a product extrafield !

i have done some investigations in the code and here is where i am :

there is two places where  ShowOutputField is coded : commonobject.class.php (where the dol_eval is called) and extrafields.class.php (used in product card to display extrafields but not calling dol_eval !).

doeas anyone (@eldy ?) can help me ? (i am on the develop branch).

Best regards

Christophe

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
Reply | Threaded
Open this post in threaded view
|

Re: computed values in extrafields

Maxime Kohlhaas
No idea why it's in 2 places.
I think I saw a pull request from someone who wanted to store the result of the computation. Maybe that's why the code isn't there in develop.

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 11:12, Christophe Battarel <[hidden email]> a écrit :

Hi Maxime,

Thanks for this quick answer !

unfortunately the following code is present in 9.0 but not in develop in extrafields.class.php :

        // If field is a computed field, value must become result of compute
        if ($computed)
        {
            // Make the eval of compute string
            //var_dump($computed);
            $value = dol_eval($computed, 1, 0);
        }

i do not understand why !

also, why this method is in two classes ? (extrafields and commonobject) not very easy to maintain, isnt'it ?

Best regards

Christophe


Le 11/07/2019 à 10:57, Maxime Kohlhaas a écrit :
Hi Christophe,

On my side I tested with a simple formula :
image.png

And on the product card and in the product list I have this field calculated.
Test done in 9.0

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 10:52, Christophe Battarel <[hidden email]> a écrit :

Hello,

I am trying to use computed values in extrafields but cannot understand how it works :

example : $object->id in a product extrafield !

i have done some investigations in the code and here is where i am :

there is two places where  ShowOutputField is coded : commonobject.class.php (where the dol_eval is called) and extrafields.class.php (used in product card to display extrafields but not calling dol_eval !).

doeas anyone (@eldy ?) can help me ? (i am on the develop branch).

Best regards

Christophe

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
Reply | Threaded
Open this post in threaded view
|

Re: computed values in extrafields

Mickaël PENHARD
Maybe random fix / with a random merge ?

The problem seem's to be because extrafield usage is not consistante, depend on where it is in the code :
  • sometimes directly from the source object showOutputField,
  • sometimes the calculation is done before and load with : $value = $object->array_options["options_" . $key]; but it's a commit of 2014 so the pull request do not change anything with this case and computation of the value was already done somewhere else, moreover in this case the computed value is pass to showOutputField and not the key like ask by the function.
  • sometimes extrafield is direclty called with key and showOutputField, now this do not work anymore.

real fix is possible, but can't commit on the repo so good luck :D

Reminder :

Best Regards,
Mickaël PENHARD

Le jeu. 11 juil. 2019 à 12:00, Maxime Kohlhaas <[hidden email]> a écrit :
No idea why it's in 2 places.
I think I saw a pull request from someone who wanted to store the result of the computation. Maybe that's why the code isn't there in develop.

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 11:12, Christophe Battarel <[hidden email]> a écrit :

Hi Maxime,

Thanks for this quick answer !

unfortunately the following code is present in 9.0 but not in develop in extrafields.class.php :

        // If field is a computed field, value must become result of compute
        if ($computed)
        {
            // Make the eval of compute string
            //var_dump($computed);
            $value = dol_eval($computed, 1, 0);
        }

i do not understand why !

also, why this method is in two classes ? (extrafields and commonobject) not very easy to maintain, isnt'it ?

Best regards

Christophe


Le 11/07/2019 à 10:57, Maxime Kohlhaas a écrit :
Hi Christophe,

On my side I tested with a simple formula :
image.png

And on the product card and in the product list I have this field calculated.
Test done in 9.0

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 10:52, Christophe Battarel <[hidden email]> a écrit :

Hello,

I am trying to use computed values in extrafields but cannot understand how it works :

example : $object->id in a product extrafield !

i have done some investigations in the code and here is where i am :

there is two places where  ShowOutputField is coded : commonobject.class.php (where the dol_eval is called) and extrafields.class.php (used in product card to display extrafields but not calling dol_eval !).

doeas anyone (@eldy ?) can help me ? (i am on the develop branch).

Best regards

Christophe

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
Reply | Threaded
Open this post in threaded view
|

Re: computed values in extrafields

Christophe Battarel
In reply to this post by Maxime Kohlhaas

thanks to all.

there is in fact several problems :

1) the showOutputField (and showInputField) function is present twice (in extrafields.class.php and in commonobject.class.php)

2) some code was removed in extrafields.class.php : https://github.com/Dolibarr/dolibarr/pull/10376 (by @atm-maxime ;-) ) in january

3) the variables $db, $mysoc, $object, etc shown in the computed value tooltip may be inconsistency depending of the context (maybe that is why it was removed from extrafields class)

Best regards

Christophe


Le 11/07/2019 à 12:00, Maxime Kohlhaas a écrit :
No idea why it's in 2 places.
I think I saw a pull request from someone who wanted to store the result of the computation. Maybe that's why the code isn't there in develop.

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 11:12, Christophe Battarel <[hidden email]> a écrit :

Hi Maxime,

Thanks for this quick answer !

unfortunately the following code is present in 9.0 but not in develop in extrafields.class.php :

        // If field is a computed field, value must become result of compute
        if ($computed)
        {
            // Make the eval of compute string
            //var_dump($computed);
            $value = dol_eval($computed, 1, 0);
        }

i do not understand why !

also, why this method is in two classes ? (extrafields and commonobject) not very easy to maintain, isnt'it ?

Best regards

Christophe


Le 11/07/2019 à 10:57, Maxime Kohlhaas a écrit :
Hi Christophe,

On my side I tested with a simple formula :
image.png

And on the product card and in the product list I have this field calculated.
Test done in 9.0

Bien cordialement,

--
Maxime Kohlhaas | Consultant associé
------------------------------------------------------------------------------------
Tél : 06 33 42 92 43


Le jeu. 11 juil. 2019 à 10:52, Christophe Battarel <[hidden email]> a écrit :

Hello,

I am trying to use computed values in extrafields but cannot understand how it works :

example : $object->id in a product extrafield !

i have done some investigations in the code and here is where i am :

there is two places where  ShowOutputField is coded : commonobject.class.php (where the dol_eval is called) and extrafields.class.php (used in product card to display extrafields but not calling dol_eval !).

doeas anyone (@eldy ?) can help me ? (i am on the develop branch).

Best regards

Christophe

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

_______________________________________________
Dolibarr-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev