Skip to content

[18.0][MIG] website_sale_affiliate migration from 16.0 to 18.0#1228

Open
jans23 wants to merge 8 commits into
OCA:18.0from
Nitrokey:18.0-mig-website_sale_affiliate
Open

[18.0][MIG] website_sale_affiliate migration from 16.0 to 18.0#1228
jans23 wants to merge 8 commits into
OCA:18.0from
Nitrokey:18.0-mig-website_sale_affiliate

Conversation

@jans23

@jans23 jans23 commented May 29, 2026

Copy link
Copy Markdown

No description provided.

@OCA-git-bot OCA-git-bot added series:18.0 mod:website_sale_affiliate Module website_sale_affiliate labels May 29, 2026
@jans23 jans23 force-pushed the 18.0-mig-website_sale_affiliate branch from 08325cd to 1f5d6ec Compare May 29, 2026 19:40
@jans23

jans23 commented May 29, 2026

Copy link
Copy Markdown
Author

@fcayre please review.

@jans23

jans23 commented May 29, 2026

Copy link
Copy Markdown
Author

@pilarvargas-tecnativa could you review this please?

@jans23 jans23 force-pushed the 18.0-mig-website_sale_affiliate branch from fe0825f to 3c41315 Compare May 29, 2026 21:40

@pilarvargas-tecnativa pilarvargas-tecnativa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello,
Thank you for your contribution. Please check the commit history as it is incomplete.
Regards!

@KDRdev KDRdev force-pushed the 18.0-mig-website_sale_affiliate branch from 26aed71 to cb183c3 Compare June 2, 2026 11:19
@KDRdev

KDRdev commented Jun 2, 2026

Copy link
Copy Markdown

Hello, Thank you for your contribution. Please check the commit history as it is incomplete. Regards!

@pilarvargas-tecnativa thank you for the review. Could you please check if the current PR version has been prepared as expected? Thanks!

@jans23

jans23 commented Jun 2, 2026

Copy link
Copy Markdown
Author

@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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changing ' to " doesn't help with the migration; it just makes the diff bigger

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@KDRdev following strictly the migration guide you have referred, that changes are isolated in its own commit, not on the migration commit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just follow the guide...

"valid_hours": 24,
"valid_sales": 1,
}
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change doesn't make any difference either

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caused by pre-commit, which is recommended during module migration according to OCA

@KDRdev KDRdev Jun 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

''

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caused by pre-commit, which is recommended during module migration according to OCA

@KDRdev KDRdev Jun 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Moved to a separate commit from migration commit.


from odoo.addons.website_sale.controllers.main import WebsiteSale as Base

_logger = logging.getLogger(__name__)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it necessary?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No, it's not needed. Thanks!

request.session['affiliate_request'] = affiliate_request.id
except (AttributeError, ValueError):
pass
affiliate = request.env["sale.affiliate"].sudo().find_from_kwargs(**kwargs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change doesn't help with the migration either; it just adds noise to the diff

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably appeared after running pre-commit, which is expected during module migration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@KDRdev KDRdev Jun 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is best to avoid leaving spaces between lines of code

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change has been removed.

res = super(WebsiteSale, self).shop(page, category,
search, ppg, **post)
def shop(self, *args, **post):
res = super().shop(*args, **post)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is now changed only due to change in Odoo standard /shop endpoint changes and to make sure unit tests pass

@KDRdev KDRdev force-pushed the 18.0-mig-website_sale_affiliate branch from cb183c3 to e357fc7 Compare June 10, 2026 15:40
@KDRdev

KDRdev commented Jun 10, 2026

Copy link
Copy Markdown

@pilarvargas-tecnativa I've replied to your comments, could you please have a look. Thank you!

@KDRdev KDRdev force-pushed the 18.0-mig-website_sale_affiliate branch from e357fc7 to c2c9f95 Compare June 11, 2026 13:47
hughesbm and others added 6 commits June 11, 2026 15:51
* [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
@KDRdev KDRdev force-pushed the 18.0-mig-website_sale_affiliate branch 4 times, most recently from a5795f7 to 69a9eac Compare June 12, 2026 06:38
@KDRdev KDRdev force-pushed the 18.0-mig-website_sale_affiliate branch from 1e2c380 to 7e7ae03 Compare June 12, 2026 09:10
@KDRdev

KDRdev commented Jun 12, 2026

Copy link
Copy Markdown

@pilarvargas-tecnativa I've made changes as per your suggestions, could you please have another look? Thanks!

@KDRdev

KDRdev commented Jun 24, 2026

Copy link
Copy Markdown

@pilarvargas-tecnativa just a friendly reminder for you. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:website_sale_affiliate Module website_sale_affiliate series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants