[18.0][MIG] website_sale_affiliate migration from 16.0 to 18.0#1228
[18.0][MIG] website_sale_affiliate migration from 16.0 to 18.0#1228jans23 wants to merge 8 commits into
Conversation
08325cd to
1f5d6ec
Compare
|
@fcayre please review. |
|
@pilarvargas-tecnativa could you review this please? |
fe0825f to
3c41315
Compare
pilarvargas-tecnativa
left a comment
There was a problem hiding this comment.
Hello,
Thank you for your contribution. Please check the commit history as it is incomplete.
Regards!
26aed71 to
cb183c3
Compare
@pilarvargas-tecnativa thank you for the review. Could you please check if the current PR version has been prepared as expected? Thanks! |
|
@pilarvargas-tecnativa Updated accordingly. Please check. |
| compute='_compute_sales_per_request', | ||
| help='Sale count / Request count', | ||
| compute="_compute_sales_per_request", | ||
| help="Sale count / Request count", |
There was a problem hiding this comment.
Changing ' to " doesn't help with the migration; it just makes the diff bigger
There was a problem hiding this comment.
According to the OCA module migration technical guidelines (https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-18.0#technical-method-to-migrate-a-module-from-170-to-180-branch), pre-commit needs to be run during migration. Running pre-commits causes these changes, so I think it's correct.
There was a problem hiding this comment.
In any case, it is advisable to run pre-commit and save any changes you make in a separate commit, rather than including them in the migration commit. This ensures that the functional changes made by the migration are clearly separated from the automatic formatting adjustments, making it easier to review and track the commit history.
pre-commit run -a
git add -A
git commit -m "[IMP] affiliate: pre-commit auto fixes" --no-verify
There was a problem hiding this comment.
@KDRdev following strictly the migration guide you have referred, that changes are isolated in its own commit, not on the migration commit.
There was a problem hiding this comment.
Ok, so migration itself (syntactic, Odoo-standard business logic-dependent changes) should be a separate commit, pre-commit should be a separate commit, correct?. If there are some extra changes/additional functions, each should be a separate commit, but can still be included in this PR, right?
| "valid_hours": 24, | ||
| "valid_sales": 1, | ||
| } | ||
| ) |
There was a problem hiding this comment.
This change doesn't make any difference either
There was a problem hiding this comment.
Caused by pre-commit, which is recommended during module migration according to OCA
There was a problem hiding this comment.
Moved to a separate commit from migration commit.
| """Returns existing affiliate request record matching aff_key | ||
| from kwargs when match already exists""" | ||
| kwargs = {'aff_key': self.demo_request.name} | ||
| kwargs = {"aff_key": self.demo_request.name} |
There was a problem hiding this comment.
Caused by pre-commit, which is recommended during module migration according to OCA
There was a problem hiding this comment.
Moved to a separate commit from migration commit.
|
|
||
| from odoo.addons.website_sale.controllers.main import WebsiteSale as Base | ||
|
|
||
| _logger = logging.getLogger(__name__) |
There was a problem hiding this comment.
Is it necessary?
| request.session['affiliate_request'] = affiliate_request.id | ||
| except (AttributeError, ValueError): | ||
| pass | ||
| affiliate = request.env["sale.affiliate"].sudo().find_from_kwargs(**kwargs) |
There was a problem hiding this comment.
This change doesn't help with the migration either; it just adds noise to the diff
There was a problem hiding this comment.
Probably appeared after running pre-commit, which is expected during module migration.
There was a problem hiding this comment.
I understand that pre-commit may have changed the formatting, but this diff does not look like a pure formatting change to me.
It removes the try/except block and the assignment to request.session["affiliate_request"], so it seems to change the behavior, not just the style. Could you please check whether this change was intentional and, if so, explain why it is needed for the migration?
There was a problem hiding this comment.
Finally, this change does not appear to stem from a pre-commit or an automatic version update. The flow of _store_affiliate_info is being modified, removing the original try/except block and changing how cases without an affiliate or without an affiliate_request are handled. That may be correct, but it should then be justified as a functional change and covered by tests. If it is not strictly necessary for the migration, it would be better to revert it to reduce noise and risk.
There was a problem hiding this comment.
@pilarvargas-tecnativa the flow has been modified to fix pylint error [W8138(except-pass), WebsiteSale._store_affiliate_info] pass into block except. If you really need to use the pass consider logging that exception. Current execution fixes this error and doesn't change the functionality and doesn't remove original session header assignment. I think it's better than just logging the error as per pylint suggestion. It's covered by tests in 'test_website_sale.py' and is a very minor change that doesn't produce extra noise. I hope this explanation justifies the change and it can be included in the migrated module.
There was a problem hiding this comment.
@pilarvargas-tecnativa I've reconsidered my opinion and removed the change as it may have caused some tests to fail. I've added a fix for pylint error as per linter suggestion.
| affiliate = request.env["sale.affiliate"].sudo().find_from_kwargs(**kwargs) | ||
| if not affiliate: | ||
| return | ||
|
|
There was a problem hiding this comment.
It is best to avoid leaving spaces between lines of code
There was a problem hiding this comment.
In this case I'd argue that this change can stay since we're separating different logical blocks (line 16 is a return statement).
| self._store_affiliate_info(**kwargs) | ||
| def product(self, *args, **post): | ||
| res = super().product(*args, **post) | ||
| self._store_affiliate_info(**post) |
There was a problem hiding this comment.
It's added to allow generating affiliate links with '/shop/product...'. Then we can track if order source used affiliate links by checking the field affiliate_request_idon sale order.
There was a problem hiding this comment.
I understand the purpose, but this is a functional change, not a migration one.
If /shop affiliate links were not supported before, adding support for them should not be part of the migration commit. For a 16.0 to 18.0 migration, we should keep the existing behavior working in 18.0 and avoid introducing new tracking flows unless they are required by a framework/API change.
Could you please move this to a separate commit/PR, or explain which 18.0 change makes it necessary for the migration?
| res = super(WebsiteSale, self).shop(page, category, | ||
| search, ppg, **post) | ||
| def shop(self, *args, **post): | ||
| res = super().shop(*args, **post) |
There was a problem hiding this comment.
It's added to allow generating affiliate links with '/shop/...'. Then we can track if order source uses affiliate links by checking the field affiliate_request_idon sale order.
There was a problem hiding this comment.
This is now changed only due to change in Odoo standard /shop endpoint changes and to make sure unit tests pass
cb183c3 to
e357fc7
Compare
|
@pilarvargas-tecnativa I've replied to your comments, could you please have a look. Thank you! |
e357fc7 to
c2c9f95
Compare
* [ADD] website_sale_affiliate: Create module * Add sale.affiliate and sale.affiliate.request models * Override WebsiteSale controller shop method to store affiliate id & key kwargs of shop urls in session * Override sale order create method to store affiliate request * Add affiliate and request views, links in Sales/Affiliates * Add affiliate_request_id to sale.order form view * Add request sequence record, make default for new affiliates * Add access rights to sales users/managers * Add tests * Add readme instructions * [IMP] website_sale_affiliate: Make requested changes * Update readme * Add controller override to catch product urls * Remove redundant return None * Replace if statements with try/except when appropriate * Change api decorator on sale.affiliate.find_from_session method from model -> model_cr_context * Add check to avoid unnecessary db search in find_from_session if no affiliate_id * Fix tests * Add new tests * [IMP] website_sale_affiliate: Make requested changes * Un-nest try/except statements for readability * Rename kwargs: ref, key -> aff_ref, aff_key * Improve request search speed for large recordsets * Document similarly-named methods for clarity * Tweak tests as needed * Add additional test * Add roadmap to readme * [REM] website_sale_affiliate: Remove affiliate request IP-matching * [IMP] website_sale_affiliate: Change affiliate request creation * Create affiliate requests regardless of whether a sale occurs * Add basic conversion/sales stats to affiliate model and views * Update tests * Add demo data * Clean up views * Remove line used for debugging * Add field string for clarity * [FIX] website_sale_affiliate: Fix compatibility issues, tests * Fix controller method overrides to avoid conflicts * Match assertAlmostEqual decimal places to amount used in fields * Remove/replace tests with unneeded url_open calls * Rename files, variables for clarity * Clean up demo/test data * [IMP] website_sale_affiliate: Clarify affiliate request name * Add help to name field on affiliate request model
* Handle the case of no web session, which will raise a `RuntimeError('object unbound')` when attempting to access it. This happens during XML record creations, but likely other places such as in the shell
a5795f7 to
69a9eac
Compare
1e2c380 to
7e7ae03
Compare
|
@pilarvargas-tecnativa I've made changes as per your suggestions, could you please have another look? Thanks! |
|
@pilarvargas-tecnativa just a friendly reminder for you. Thanks! |
No description provided.