Community mailing list archives

Re: V8 New API questions

Camptocamp SA, Guewen Baconnier - Software Developer, Camptocamp
- 11/25/2014 08:13:46

On 11/25/2014 01:43 PM, Jos De Graeve wrote:
> Hi,
> I have two questions about the new on-change api:
> How would one implement functionality like the "warning" module with the
> new API:
> Is it required to override the 'onchange' method
> or is
> there another way to do this?

You can still returns a warning with the new api:

    def onchange_partner_id(self):
        return {'warning': {'title': 'Warning', 'message': 'Message'}}
> The env.context dictionary is a frozen dict, is there still a way to
> insert the context with a variable ?  I wanted to use the on-change api
> to set a new default value in the context.
The new way to change the context is:

    records self.with_context(new_key='abc').browse(ids)  # current
context extended with {'new_key': 'abc'} in records

    records = self.with_context({'new_key': 'abc'}).browse(ids)  #
current context replaced by {'new_key': 'abc'} in records

> My use case is sale order line entry: when a user creates a new order
> line and changes a certain field, a new default value is set in the
> context, so that the next created order line would have the same value
> as entered in the previous order line.
I don't think it is possible with the context. IMO relying on side
effects by modifying the context "in place" had always been a dangerous
and difficult to track operation so I have been glad when I saw that a
frozen dict was used in the new api (although the case you describe here
is not so bad, it looks more like a "session" object). Now, I don't know
if there is another way to do what you want to do.

> Tnx,
> Jos De Graeve - Apertoso business ICT
> Guido Gezellelaan 16 - B-9800 Deinze - Belgium
> Direct: +32 9 381 64 51
> General:+32 9 381 64 50
> Mobile: +32 475 54 68 80
> mail/im/skype:
> <> - apertoso

Guewen Baconnier
Business Solutions Software Developer

Camptocamp SA
PSE A, CH-1015 Lausanne
Phone: +41 21 619 10 39
Office: +41 21 619 10 10