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

[MIG] sale_exception: Migration to 16.0 #2266

Merged
merged 53 commits into from
Feb 9, 2023

Conversation

matiasperalta1
Copy link
Contributor

No description provided.

atchuthan and others added 30 commits November 16, 2022 16:34
Rule should only count available stock from selected warehouse from sale order.
Without warehouse in context, it currently sums all stock available in all warehouses.
The previous parent menu has an action attached, and with these modules,
it can't be clicked.
* [FIX] sale_exception confirm wizard
* [FIX] add test of test_all_draft_orders & flake8 & readme.rst
* [FIX] improve codecov test
* [FIX] delete odl translation
* [FIX] add Camptocamp to author
* [FIX] readme.rst
Raise SingletonError when you have a recordset with multiple sale order.
This restore the capability to write on multiple sale.order
Currently, it's located at the root menu because. It's a migration bug because the old menu was removed from 11.0.
The method called by 'sale_check_exception' has a side effect, it writes
on 'exception.rule' + on the Many2many relation between it and
sale.order(.line). When decorated by @api.constrains, any error during
the method will be caught and re-raised as "ValidationError".
This part of code is very prone to concurrent updates as 2 sales having
the same exception will both write on the same 'exception.rule'.
A concurrent update (OperationalError) is re-raised as ValidationError,
and then is not retried properly.

Calling the same method in create/write has the same effect than
@api.constrains without shadowing the exception type.

Full explanation:
OCA/server-tools#1642
* [IMP] sale_exception: show menu only to Exception Rule Managers
* [IMP] Reindent lines to 4 spaces
* [IMP] Improve information messages that display exceptions
* [REM] Remove exception_ids fields from the sale order view, because it's no longer necessary and it allowed users to accidentaly deactivate a Sale Exception Rule using the active widget.
* [IMP] Rename exception_ids_formatted to exceptions_summary
Disable for now as the solution is not obvious.

Partially fixes OCA#972
Other ways it provokes linter fail
TestSaleOrder was useless and making sale order tests run twice.
@matiasperalta1 matiasperalta1 force-pushed the 16.0-mig-sale_exception branch from b98ab73 to 0c33215 Compare November 17, 2022 14:22
@matiasperalta1 matiasperalta1 mentioned this pull request Nov 17, 2022
100 tasks
if check_exceptions:
self.sale_check_exception()

@api.model
Copy link

Choose a reason for hiding this comment

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

Suggested change
@api.model
@api.model_create_multi

Keep in mind that you should also adapt the method _check_sale_check_exception. It will receive a list of dict from the create method and only an dict from the write method.

@jjscarafia jjscarafia force-pushed the 16.0-mig-sale_exception branch from 0c33215 to 4be9ab6 Compare December 16, 2022 11:54
Copy link
Contributor

@aliciagaarzo aliciagaarzo left a comment

Choose a reason for hiding this comment

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

After testing the migrated module, I’ve found some improvements:

  • Description field is noy properly displayed; user needs to scroll to the right to see it.
  • Allow to ignore exceptions even if the “is blocking” option is checked

@@ -53,11 +53,12 @@ def _check_sale_check_exception(self, vals):
if check_exceptions:
self.sale_check_exception()

@api.model
Copy link
Member

Choose a reason for hiding this comment

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

Hi thanks for the migration.

It's not related to your change but after think twice
I think that the check on create is useless !

Indeed if you look at the method sale_check_exception, it explicitly skip all sale order that are not in the state "sale", when we create a sale order the state is always "draft".

So indeed of adding some extra complexity to the code, maybe it's a good opportunity to simplify it and just to remove the inherit on "def create".

I should have seen it before but I miss to review this PR : #916

@simahawk @rousseldenis @sbejaoui what do you think ?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree the create override can be removed as it seems useless.

@sebastienbeau
Copy link
Member

also, can you rebase as base_exception have been merged ?

@sebastienbeau
Copy link
Member

Note: I also realize that the migration in V9 have drop the commit historic (it was correct in 8 see here: https://github.com/OCA/sale-workflow/commits/8.0?after=605d0ae2da6d37e9acd8466eb77d2cc023d2f289+69&branch=8.0&path%5B%5D=sale_exceptions&qualified_name=refs%2Fheads%2F8.0)

When this PR will be really, I will, before merging the PR, restore the commit history, so please ping me when it's ready, do not waist your time with this point, I will do it.

@rousseldenis
Copy link
Contributor

Note: I also realize that the migration in V9 have drop the commit historic (it was correct in 8 see here: https://github.com/OCA/sale-workflow/commits/8.0?after=605d0ae2da6d37e9acd8466eb77d2cc023d2f289+69&branch=8.0&path%5B%5D=sale_exceptions&qualified_name=refs%2Fheads%2F8.0)

@sebastienbeau That's normal as module has been renamed at that time.

@rousseldenis
Copy link
Contributor

/ocabot migration sale_exception

@OCA-git-bot OCA-git-bot added this to the 16.0 milestone Jan 2, 2023
Copy link
Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

LGTM. Minor change

from odoo import api, fields, models


class ExceptionRule(models.Model):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put models in separate files

@@ -0,0 +1,125 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import mock
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import mock
from unittest import mock

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.

LGTM once the requested changes will be implemented

@rousseldenis
Copy link
Contributor

@matiasperalta1

@lmignon
Copy link
Contributor

lmignon commented Jan 17, 2023

@matiasperalta1 Do you plan to work on this PR soon or do you prefer we finalize your work? We need to move forward with this one....

@sbejaoui
Copy link
Contributor

I pushed a new PR (#2344) to finalize this one because we need it for one of our projects.

@rousseldenis
Copy link
Contributor

@matiasperalta1 Could you close this in favor of #2344 ?

@rousseldenis rousseldenis added duplicate stale PR/Issue without recent activity, it'll be soon closed automatically. and removed needs review labels Jan 25, 2023
@OCA-git-bot OCA-git-bot merged commit 4be9ab6 into OCA:16.0 Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate migration stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.