Identification



Welcome, Guest
Please Login or Register.    Lost Password?

howto transf. customfields from proposal to order
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: howto transf. customfields from proposal to order
#21290
howto transf. customfields from proposal to order 8 Months, 1 Week ago Karma: 0
Hi,

I'm just adapting the brilliant dolibarr 3.2.2 for my needs by using customfields (free edition) which I use for quotations, orders and invoices.

How can I achieve that customfields are automatically transfer from my quotations to orders and orders to invoices?

1) is this a feature of the customfield pro edition?

2) or is there an article in dollibars wiki (I couldn't find any)?

any help is appreciated - thanks in advance.

best regards
tom
Fresh Boarder
Posts: 11
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#21294
Re:howto transf. customfields from proposal to order 8 Months ago Karma: 6
Hello,

I am the developper of CustomFields.

I don't understand what you mean by quotation, could you provide more details about what module you are talking about?

About your question, no there's no automatic transfer of custom fields from modules to modules, because noone asked for such a feature before.

However, this may not be necessary. For example, orders that are converted to invoices produce a link between the order and the invoice. Thus, you can access the order's custom fields from the invoice. For example, if you want to print custom fields of your order but print them on the PDF generated from the invoice, this is totally possible.

You can find a full tutorial on how to do this with CustomFields Pro here:
wiki.dolibarr.org/index.php/Module_Custo...wo_different_modules

And a full documentation is available on the Dolibarr's wiki:
wiki.dolibarr.org/index.php/Module_CustomFields

CustomFields Free edition should also be able to do that, but it will be a lot more complex because the customfields_fill_object() function, which does a lot of the job for you, is not available in the Free edition.

If this is not a viable solution for what you want to achieve, please give me more details so that I can better understand your goal.
lrq3000
Senior Boarder
Posts: 74
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2012/10/16 16:40 By lrq3000.
The administrator has disabled public write access.
 
#21298
Re:howto transf. customfields from proposal to order 8 Months ago Karma: 10
Hi Irq3000... quotation means: offre de prix
humphrey
Expert Boarder
Posts: 155
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2012/10/16 18:11 By humphrey.
The administrator has disabled public write access.
 
#21299
Re:howto transf. customfields from proposal to order 8 Months ago Karma: 6
Ah ok thank's Humphrey. Your first translation quotation = propale was better in the context of Dolibarr since it's how the module is called

Ok then Tom, when you convert a quotation to order and then to invoice, every one of these gets linked inside the Dolibarr database in the table llx_element_element, so then you can easily recreate the link with CustomFields using customfields_fill_object() as indicated in the tutorial I've given you, thus avoiding you the need to transfer/copy the custom fields (which would not be very clean: with the method I present you, you can set different custom fields for every one of these modules, and still link them, fetch them and use them whenever you need).
lrq3000
Senior Boarder
Posts: 74
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#21302
Re:howto transf. customfields from proposal to order 8 Months ago Karma: 0
Hi lrq3000, thank's for your answers.

1) since I am new to dolibarr I would like to know if it's a good way to use a trigger-event (e.g. ORDER_CREATE) to run customfields_fill_object() (as per "linking dolibarr objects from two diff. modules") to fill CustomFields of my new Order with CustomFields from my Quotation (=propale). I assume that I can see (and edit) these newly filled CustomFields afterwards in the invoice module.

2) Is there a way to distinguish in an ORDER_CREATE trigger event between a new order converted from a quote (propale) or a "blank" new order?
(maybe some kind of state information?)

Thanks in advance for helping me !
best regards
Tom
tom
Fresh Boarder
Posts: 11
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#21307
Re:howto transf. customfields from proposal to order 8 Months ago Karma: 6
Hello Tom,

1) Yes that would be a pretty clean way to do that. You could make a trigger file on ORDER_CREATE which would fetch the Quotation's custom fiels using customfields_fill_object() and table llx_element_element (or maybe directly $object may contain the link) and create a new custom field for orders using createCustomField() by just passing the object returned by customfields_fill_object (just be sure that the $object->table_element = 'order' or 'commande' and not 'propal').
But as I said, copying custom fields is not necessary to fetch them since you can get the links using llx_element_element.

2) In any case you should be able to get the state using the table llx_element_element, but you may also find the quotation to be a sub-element of $object (order), but this is not necessarily the case! Objects linking in Dolibarr seems to be undergoing a refactoration to ease this kind of processing, but I'm not too sure about it.
An alternative would be to find the class where the orders are created from a quote, and add your own trigger there (eg: ORDER_CREATE_FROM_PROPAL), but it may already exists. Just look inside the *.class.php files.
lrq3000
Senior Boarder
Posts: 74
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2012/10/17 11:15 By lrq3000.
The administrator has disabled public write access.
 
#21403
Re:howto transf. customfields from proposal to order 7 Months, 3 Weeks ago Karma: 0
Hello lrq3000,

thanks for your last reply, which is a while ago.

In the meantime I bought the Pro version of CustomFields to be able to use 'customfields_fill_object'.

To take some CustomFields from an existing ComercialProposal into an new CustomerOrder I created a trigger with action == 'ORDER_CREATE' and followed the example of the wiki you gave me a view posts above (Linking Dolibarr objects from two different modules) to get access to all the CustomFields (both 'propal' and 'commande') using customfields_fill_object.

Code:

$object->customfields->commande->cf_someCFofOrder =
$object->customfields->propal->cf_someCFofPropale;


With above code dol_syslog shows me the same content in both CustomFields. So far so good.

But above code does not store into database of course.
How can I store my CustomFileds of the newly created CustomerOrder into the database?

I tried with 'update' which raised an error "Call to undefined method stdClass::update()".

thanks again in advance.
best regards
Tom
tom
Fresh Boarder
Posts: 11
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2012/10/29 14:34 By tom.
The administrator has disabled public write access.
 
#21409
Re:howto transf. customfields from proposal to order 7 Months, 3 Weeks ago Karma: 6
Hello Tom,

Thank you for buying CustomFields Pro. I hope it will satisfy all your needs.

tom wrote:
How can I store my CustomFileds of the newly created CustomerOrder into the database?

I tried with 'update' which raised an error "Call to undefined method stdClass::update()".


You must use the $customfields object that is returned by the customfields_fill_object() function.

Then you can simply do:

Code:


$rtncode = $customfields->update($object);



This will both update or create the custom field whether the record already exists or not (will be automatically detected by the CustomFields class).

However, the update() method expects an object with customfields stored inside $object->customfields, not $object->customfields->orders.

Thus either you can modify the code you've given above like this:
Code:


$object->customfields->cf_someCFofOrder =
$object->customfields->propal->cf_someCFofPropale;



Either you can just use 2 different objects with customfields_fill_object($object, $fromobject); where $fromobject is the propal object, and $object is the order object. Then you will be able to directly use $customfields->update($object).

For more information about the update() method and customfields_fill_object() function, please check the wiki (I've just updated the customfields_fill_object() chapter to describe its full specification):

wiki.dolibarr.org/index.php/Module_Custo...ating_a_custom_field
wiki.dolibarr.org/index.php/Module_Custo...ds_fill_object.28.29
wiki.dolibarr.org/index.php/Module_Custo...wo_different_modules
lrq3000
Senior Boarder
Posts: 74
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2012/10/29 16:28 By lrq3000.
The administrator has disabled public write access.
 
#21422
Re:howto transf. customfields from proposal to order 7 Months, 3 Weeks ago Karma: 0
Hello lrq3000,

Everything is working fine now, but I had to make following changes:
(just for Information if someone else is reading this thread):

In order to make $customfields->update($object) work, I had to use
Code:

$object->cf_someCFofOrder = $object->customfields->propal->cf_someCFofPropale;

instead of
Code:

$object->customfields->cf_someCFofOrder = ...

because $object - which is passed to update() - must be an object containing the customfields data as its properties (and not another costomfields object).

Thanks again for your quick support.

Maybe I will need your help again when I'm going to extend dolibarr's project functionalities with TimeTracking features.

Best regards
Tom
tom
Fresh Boarder
Posts: 11
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#21423
Re:howto transf. customfields from proposal to order 7 Months, 3 Weeks ago Karma: 6
Hello Tom,

Thank you for the feedback, indeed my bad! I will add a compatibility layer to easy this kind of operation in the future, so that in future versions of CustomFields one will be able to just use $object->customfields or even $object->customfields->propal.

Feel free to contact me again, your TimeTracking sure seems interesting! Don't forget that if you make a module on top of the CustomFields class, it will also work with CustomFields Free normally (since both shares a lot of code in common).
lrq3000
Senior Boarder
Posts: 74
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12