Skip to content

Conversation

@sbejaoui
Copy link
Contributor

No description provided.

@sbejaoui sbejaoui force-pushed the 12.0-mig-onchange_helper branch from 840c2b1 to d8fd6ed Compare December 17, 2018 14:46
@pedrobaeza pedrobaeza added this to the 12.0 milestone Dec 17, 2018
@OCA-git-bot OCA-git-bot mentioned this pull request Dec 17, 2018
32 tasks
@sbejaoui sbejaoui force-pushed the 12.0-mig-onchange_helper branch from 1ed501c to 68b0591 Compare December 17, 2018 15:12
@sbejaoui sbejaoui force-pushed the 12.0-mig-onchange_helper branch from 5c318a1 to a132f3e Compare December 17, 2018 18:33
@sbejaoui sbejaoui force-pushed the 12.0-mig-onchange_helper branch from a132f3e to a22f10e Compare December 17, 2018 18:34
@sbejaoui sbejaoui changed the title [12.0][WIP][MIG] onchange helper [12.0][MIG] onchange helper Dec 17, 2018
Copy link
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @sbejaoui LGTM (Code review only)

other improvement:

set onchange_specs to all fields as _onchange_spec()
retrun onchange fields for default view
return field value if it's set in onchange_fields (usuful to get default value for a field)
Copy link
Contributor Author

@sbejaoui sbejaoui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmignon , I pushed some changes. can you check them please.

@lmignon
Copy link
Contributor

lmignon commented Dec 18, 2018

@astirpe @sebastienbeau @florian-dacosta Could you take a look to the two last commits PLZ?
a22f10e
0f4f8bb
These changes looks to me very useful and should be back ported into previous versions IMO.

@sbejaoui sbejaoui force-pushed the 12.0-mig-onchange_helper branch from 056b070 to 424ae0a Compare December 20, 2018 09:30
return {
f: v
for f, v in all_values.items()
if not self._fields[f].compute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks :)

# We get default values, they may be used in onchange
record_values = self.default_get(self._fields.keys())
for field in self._fields:
if field not in all_values:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbejaoui Do you remember the motivations behind the lines from 55 to 56? IMO we must exclude non stored fields. I observe that if I put all the fields of my model, my non stored fields are recomputed even if not accessed by an onchange...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to get values from existing record or defaults one to fill missing data in all_values passed to play_onchange.

if self:
self.ensure_one()
record_values = self._convert_to_write(
{
field_name: self[field_name]
for field_name, field in self._fields.items()
}
)

IMO, field_name: self[field_name] trigger the compute process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But do we really need all values.... We should let the ORM compute the one required once accessed. In my case, these lines trigger the compute of useless field and cause performance issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can exclude computed fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've the same feeling.

@bealdav
Copy link
Member

bealdav commented Feb 27, 2019

Hi, thanks for your work.

I have a use case that doesn't work with this code.

Float fields with a value of 0.0 is evaluated to False and then is not returned to vals

It's is not easy to reproduce with unit tests on res.partner.

My case :

I import csv of purchase line with only specified product_id and qty

I want this onchange played called by onchange_product_id()
https://github.com/odoo/odoo/blob/339bf145ced6fb30f10d6d2941cfdaadf594d426/addons/purchase/models/purchase.py#L630

vals = self.env['purchase.order.line'].play_onchanges(vals, ['product_id'])

price_unit is equal to 0.0, and don't reach vals but is mandatory for purchase lines.

I'll investigate deeper.

@lmignon
Copy link
Contributor

lmignon commented Feb 27, 2019

@bealdav I'm refactoring this module in V10 to improve the performances... In the same time I'm adding a lot of tests. I've a corner case that doesn't pass the tests (recursive onchange on on2many relation). I'll also add a test for this UC to see if the new code is more robust. https://github.com/OCA/server-tools/pull/1510/files

@bealdav
Copy link
Member

bealdav commented Feb 27, 2019

@lmignon thanks a lot

@astirpe astirpe mentioned this pull request Apr 4, 2019
2 tasks
Copy link

@njeudy njeudy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just install and test on a copy of a prod database.

Ok for me it works as needed !

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@rousseldenis
Copy link
Contributor

@OCA/core-maintainers

@lmignon lmignon merged commit 59714c4 into OCA:12.0 May 14, 2019
@lmignon lmignon deleted the 12.0-mig-onchange_helper branch May 14, 2019 07:21
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (15.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.