Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0][FIX] fix issue when creating binding from the main record #607

Merged
merged 2 commits into from
Apr 24, 2020

Conversation

sebastienbeau
Copy link
Contributor

Indeed the implementation of write on one2many (see odoo/fields.py:2235)
call the method create/write in mode norecompute
This mean that the field is_urls_sync_required is not computed after
the call to super of write/create of the binding but later during the
create/write of the main record.

To solve the issue we sync the url after calling the method
"_recompute_done".
This also simplify the code \o/

@sebastienbeau
Copy link
Contributor Author

@lmignon @rousseldenis

@sebastienbeau sebastienbeau changed the title [FIX] fix issue when creating binding from the main record [10.0][FIX] fix issue when creating binding from the main record Apr 3, 2020
@sebastienbeau
Copy link
Contributor Author

@bguillot

@sebastienbeau sebastienbeau force-pushed the 10.0-fix-sync-url branch 2 times, most recently from 5cb868b to 40aada4 Compare April 4, 2020 07:51
@codecov-io
Copy link

codecov-io commented Apr 4, 2020

Codecov Report

Merging #607 into 10.0 will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             10.0     #607      +/-   ##
==========================================
+ Coverage   90.39%   90.45%   +0.06%     
==========================================
  Files         151      151              
  Lines        4048     4054       +6     
==========================================
+ Hits         3659     3667       +8     
+ Misses        389      387       -2     
Impacted Files Coverage Δ
base_url/models/abstract_url.py 92.30% <100.00%> (-0.36%) ⬇️
shopinvader/services/abstract_sale.py 100.00% <0.00%> (ø)
...nvader/wizards/shopinvader_partner_binding_line.py 100.00% <0.00%> (ø)
...ader_delivery_carrier/services/delivery_carrier.py 100.00% <0.00%> (ø)
shopinvader_delivery_carrier/services/cart.py 92.30% <0.00%> (+0.64%) ⬆️
shopinvader/models/shopinvader_category.py 97.18% <0.00%> (+1.40%) ⬆️
...invader_delivery_carrier/services/abstract_sale.py 96.87% <0.00%> (+3.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b81b921...9e0b939. Read the comment docs.

Indeed the implementation of write on one2many (see odoo/fields.py:2235)
call the method create/write in mode norecompute
This mean that the field is_urls_sync_required is not computed after
the call to super of write/create of the binding but later during the
create/write of the main record.

To solve the issue we sync the url after calling the method
"_recompute_done".
This also simplify the code \o/
@sebastienbeau
Copy link
Contributor Author

After several hours of fight again several issue when loading fake class I try to implement a new version. Indeed fake model that inherit existing class was not loading the field correctly (if you active the option custom='manual', field are not loaded correctly, if you do not active it field still exist in the registry). Try an alternative approche. For now to not merge yet. Play with the same code here : OCA/search-engine#46

@simahawk
Copy link
Contributor

simahawk commented Apr 6, 2020

which issue did you have?
If the issue is related to adding fields to existing records, you could probably solve it with this https://github.com/OCA/search-engine/blob/12.0/connector_search_engine/tests/models_mixin.py#L35

@sebastienbeau
Copy link
Contributor Author

@simahawk I have seen this hack
So I was adding the field "binding_ids" as a "custom='manual' and also adding in _test_purge_fields.
But custom field are not loaded correctly and so I had issue when using the field "partner.binding_ids" didn't work correctly.

I try to remove custom option but I was not able to purge the registry correctly.
so I start to try to understand what was happening.

As the file "model" is loaded at python execution the odoo class are already processed.
This mean that the variable "MetaModel.module_to_models" already "keep in mind" that there is odoo class to use.

When we call the _build_model it will register for ever the ResPartnerFake into the registry 'by modifying the base property of the registry['res.partner'] (you can see it this by looking in registry['res.partner'].mro()).
So this mean that every python code put in the Fake model that inherit existing class need to be purge also...
As it's start to be hard to purge everything correctly I try an alternative way and try to restore the initial base of the class inherited
I still have some issue with search-engine case, but I am not very far.

@sebastienbeau
Copy link
Contributor Author

I will work on it at this end of the week and try to publish the code in a python lib compatible for odoo 10/11/12/13 so we can reuse it everywhere without copy/paste

Copy link
Contributor

@hparfr hparfr left a comment

Choose a reason for hiding this comment

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

I tested this fix in v12.
The binding issue was not related to this fix. But since it looks to be shorter and cleaner I approve it :-)

Btw the problem (at least in v12) was in automatic_url_key calc definition. I will provide a patch soon. After my fix, and this one, it works well.

[EDIT]: I've tested with my fix and without this one, and it's true this fix resolve another issue. So both fixes are needed.

@sebastienbeau
Copy link
Contributor Author

@simahawk it's done now we have a generic helper for loading fake model https://github.com/akretion/odoo-test-helper working on version 10, 11, 12, 13 !

@simahawk
Copy link
Contributor

simahawk commented Apr 19, 2020

@simahawk it's done now we have a generic helper for loading fake model https://github.com/akretion/odoo-test-helper working on version 10, 11, 12, 13 !

great! Some things missing (eg: xmlid generation, ACL generation, etc) but it's good start!
Can we propose it to OCA?

@shopinvader-git-bot
Copy link

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). 🤖

@simahawk
Copy link
Contributor

@sebastienbeau I'm testing the test helper somewhere else. I found some issue -> I'll open a PR.

@simahawk
Copy link
Contributor

@lmignon
Copy link
Collaborator

lmignon commented Apr 20, 2020

@sebastienbeau I'm a little overwhelmed at the moment but it would be nice in your library to take credit for this work on Simone and me too. I've spent a lot of time on it and as far as I know I'm the original author of this code.
It's a great idea to make it an external lib compatible between versions but it shouldn't hide the work done by others.

Friendly,

lmi

@simahawk
Copy link
Contributor

@sebastienbeau I'm a little overwhelmed at the moment but it would be nice in your library to take credit for this work on Simone and me too. I've spent a lot of time on it and as far as I know I'm the original author of this code.
It's a great idea to make it an external lib compatible between versions but it shouldn't hide the work done by others.

Friendly,

lmi

👍 I planned to open a PR for this 😉
Also, it could be move to this org maybe, before pushing for OCA adoption.

@sebastienbeau
Copy link
Contributor Author

@lmignon I am going to fix it,
@simahawk I am ok for moving it to OCA or Shopinvader, what do yo prefer?
@simahawk I am going to test your PR right now

@lmignon
Copy link
Collaborator

lmignon commented Apr 20, 2020

@lmignon I am going to fix it,

Thank you

@simahawk I am ok for moving it to OCA or Shopinvader, what do yo prefer?

OCA is IMO the right choice.

@sebastienbeau
Copy link
Contributor Author

I also think OCA will be the best place.
Regarding credit : OCA/odoo-test-helper#5 tell me if it's ok

@simahawk
Copy link
Contributor

OCA is fine, that's the final plan. I only said "before pushing for OCA adoption" ;)
Thanks for the change! I'l check later

@sebastienbeau
Copy link
Contributor Author

/ocabot merge minor

@shopinvader-git-bot
Copy link

On my way to merge this fine PR!
Prepared branch 10.0-ocabot-merge-pr-607-by-sebastienbeau-bump-minor, awaiting test results.

@shopinvader-git-bot shopinvader-git-bot merged commit 6aad99a into shopinvader:10.0 Apr 24, 2020
@shopinvader-git-bot
Copy link

Congratulations, your PR was merged at d9accf6. Thanks a lot for contributing to shopinvader. ❤️

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.

6 participants