Le 02/06/2015 15:42, Guillem Barba Domingo a écrit :
2015-05-30 9:59 GMT+02:00 Christophe (net) <[email protected] <mailto:[email protected]>>:Le 28/05/2015 18:00, Marc Murray a écrit : On Thu, 2015-05-28 at 11:55 +0200, Christophe (net) wrote: Le 28/05/2015 11:46, Cédric Krier a écrit : On 28 May 11:10, Christophe (net) wrote: Le 28/05/2015 10:34, Cédric Krier a écrit : On 28 May 10:18, Christophe (net) wrote: Hello, I try to find out when I create a new address on a party if this is the first or not. Depending on the answer it must set a boolean in the address object. I seek from the method of class 'default_<name_of_field>' has reached the values of current instance. There is a way to do that (I am in v3.0) ? It sounds strange because addresses are already ordered by the field sequence. And moreover using the default value will not work properly with concurrency. Bizarre, on my installation the sequence field of the object party.address is empty, I would forget something? Because it is done like that by design. The order is on (sequence, id). Ok, but to return to my original question, is it possible (and how) to reach the values of the instance from a class method? Is there an example somewhere ? If you know any other object-oriented programming language, you would understand why your question is strange. By definition, a classmethod is a method that runs at the level of the class object itself. Not an instance. As a result, there is no way to access instance attributes from a class method. I understand, but my question was not about the object-oriented languages and their possibility, but was around Tryton. There is in the context or elsewhere the opportunity to catch the current record when the method to set the default value is executed (and as the initialization method of default values is either '@staticmethod' or '@classmethod ...) From your description though, you may want to look into the on_change_* and on_change_with_* methods. They will allow you to access instance values. But, I think they'll only allow access to the fields specified in the @fields.depends descriptor or the depends attribute of the field. If I understand correctly, this is an action on the client triggers the 'on_change' not the server and not when assigning default values. I look at the trigger conditions of the on_change_with_* you can try adding the 'addresses' in addresses field context (I didn't try it, I don't know if it will work correctly). Put something like that in party setup() method: cls.addresses.context['party_addresses'] = Eval('addresses') and in default_xxx(): Transaction().context.get('party_addresses')
Thanks to all for your answers and suggestions. I solved my issue by another way : from the object party.
But I will test your suggestion Guillem -- Christophe http://adiczion.com
