Technical mailing list archives

technical@mail.odoo.com

Avatar

Re: [SOLVEDish] Re: Some help please - onchange

by
Pedro M. Baeza
- 22/03/2017 03:39:43
This is the hack I use for one2many views that are not embedded in the main view: https://github.com/OCA/product-variant/pull/49/files#diff-f194b515e11db9b5f1384afb6c3db651R21

Maybe it's the same for this.

Regards.

2017-03-22 6:45 GMT+01:00 Graeme Gellatly <gdgellatly@gmail.com>:
OK I finally got everything kind of working in an acceptable manner.  By switching the sale order line to be editable=False on the sale order form view and popping a form everything works as expected.

This is OK for my use case as order lines are complex anyway and the tree view orderlines are too small anyway.

Things to note from suggested solutions
  • dotted notation not necessary and when the view is not integrated it raises a log warning anyway.
  • It does not matter if the dependent field that triggers the onchange is computed or onchanged or just edited - it just works.

So it seems this is a bug with editable one2many inside a form view.  Popping modals does what is expected.

I may however have another question which I'll ask separately if I can't google it.


On Tue, Mar 21, 2017 at 9:58 PM, Graeme Gellatly <gdgellatly@gmail.com> wrote:

Hi Pedro

I think because it's an m2o without embedded view it doesn't find dotted fields. But I might be able to redesign based on that commit.  That was the original design anyway since v5 but abandoned due to since resolved underscore.js bug .

Editable o2m inside editable o2m without intermediate m2o.

Using update makes no difference. Everything ultimately gets returned in an identical json response.

The only thing that came close to working was cascading back from the edited m2o. Didn't update the screen but did update on save.


On Tue, 21 Mar 2017, 8:40 PM Pedro Manuel Baeza Romero, <pedro.baeza@gmail.com> wrote:
If the fields are correct, the warning have no sense, but anyway, there has been a recent commit that can help with your issue:

https://github.com/odoo/odoo/commit/f65475d68cef09f5818841cf12fc5b22d295fe28

Try updating the code to see if it works as is.

Regards.

2017-03-21 7:35 GMT+01:00 Bohdan Lisnenko <lem8r.ka11a@gmail.com>:
Hello,

Try using update

self.update({'product_uom_qty' : self.custom_id.total})
21 бер. 2017 02:05 "Graeme Gellatly" <gdgellatly@gmail.com> пише:
Nope, thats not it. 

Tried that and get a log warning that onchange needs to be a valid field name whenever using dotted notation.

To date everything but editing the existing assigned m2o works. 

If you change record, works as expected. 
If you create record works as expected. 
If you edit an existing record the return value is as expected and the warning message as well.

In fact these 3 actions give identical onchange return values and all display the stock warning.  If I trace it all the way through to the json response it is still as expected.

My guess is that there is something on the js side saying do not update as nothing has changed.

If I add a boolean field and use that to trigger the onchange to update from the modified record it works but its real clumsy with the losing of focus etc so not a workable solution.  Sucks as it worked so nicely under the old api.  There must be some way of signalling the client to use the returned response.
On Tue, Mar 21, 2017 at 1:05 AM, Pedro Manuel Baeza Romero <pedro.baeza@gmail.com> wrote:
Hi, Graeme,

You have to add subfields in the onchange:

@api.onchange('custom_id', 'custom_id.o2m_field', 'custom_id.o2m_field.qty')
def custom_id_change(self):
   ...

Regards.
2017-03-20 5:50 GMT+01:00 Graeme Gellatly <gdgellatly@gmail.com>:
Hi,

I have the following design in v10 that I just can't get working right.

Sale Order -> Sale Order Line (o2m standard sale module)
Sale Order Line -> Custom Model (m2o on editable so line)
Custom Model -> Custom Model Lines (o2m)

  • The forms are all standard, with the addition of custom model m2o on the order line part of the sale order form.
  • The custom model contains a computed float field called total.  This works perfectly as expected.
  • The custom model has an onchange on sale order line which updates product_uom_qty.

When a new custom model is created the onchange is called and product_uom_qty updates correctly along with dependent fields such as subtotal, cascading through onchanges.

When an existing custom model record is edited in a popup modal, the model total updates and on save the onchange is called and I can see uses the correct values however the form or record is never updated.  It even triggers the out of stock warning of the product_uom_change with the correct quantity. How to get it to update?

The onchange code has changed significantly as I've hacked at it (different field depends, trying different things like setting dirty flags, clearing caches) but in simplest terms it looks like this when it works for a new record and this also triggers the product_uom_qty onchanges and raises the warning for existing records.

@api.onchange('custom_id')
def custom_id_change(self):
if self.custom_id:
self.product_uom_qty = self.custom_id.total

Kind regards,
Graeme


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


Reference