-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
[16.0][IMP] stock_move_line_lock_qty_done: prevent test cases from other modules from failing #1760
base: 16.0
Are you sure you want to change the base?
[16.0][IMP] stock_move_line_lock_qty_done: prevent test cases from other modules from failing #1760
Conversation
I assume the test cases failed from |
check_qty_done_change_allowed = ( | ||
config["test_enable"] | ||
and self.env.context.get("test_stock_move_line_lock_qty_done") | ||
) or not config["test_enable"] | ||
if not check_qty_done_change_allowed: | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this suffice?
check_qty_done_change_allowed = ( | |
config["test_enable"] | |
and self.env.context.get("test_stock_move_line_lock_qty_done") | |
) or not config["test_enable"] | |
if not check_qty_done_change_allowed: | |
return True | |
if config["test_enable"] and not self.env.context.get("test_stock_move_line_lock_qty_done"): | |
return True |
a356ecc
to
f863bd7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
|
||
|
||
class StockMoveLine(models.Model): | ||
|
||
_inherit = "stock.move.line" | ||
|
||
def _check_qty_done_change_allowed(self, vals): | ||
if config["test_enable"] and not self.env.context.get( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is an easy workaround that flourishes everywhere but it's not a good practice.
Introduce a configuration setting that allows to enable or disable the feature instead.
Thanks !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rousseldenis I thought you might say so. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
f863bd7
to
e857eb4
Compare
@sbejaoui Can you please review? |
ae8134b
to
d399ae0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
<record id="param_move_line_lock_qty_done_enable" model="ir.config_parameter"> | ||
<field | ||
name="key" | ||
>stock_move_line_lock_qty_done.move_line_lock_qty_done_enable</field> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking. Just thought the key could be shortened.
>stock_move_line_lock_qty_done.move_line_lock_qty_done_enable</field> | |
>stock_move_line_lock_qty_done.lock_qty_done</field> |
d399ae0
to
321184f
Compare
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
lock_qty_done = fields.Boolean( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer a related on a company field.
That will allow you to avoid get/set_values
calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are related on a company field instead of system parameter and enable this feature by default, do you want to set lock_qty_done
to false
at the end of the test cases of the module to prevent this feature from other test cases? May be I don't get your intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
From a functional point of view, enabling or disabling the feature per company is a good practice.
From a technical point of view (that's a matter of taste), I don't like such writings. Moreover, in v16, you have the field attribute config_parameter
that allows to avoid such get/set
.
321184f
to
285bcfa
Compare
285bcfa
to
d4f4cd6
Compare
<record id="base.main_company" model="res.company"> | ||
<field name="lock_qty_done">False</field> | ||
</record> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To disable the feature for all companies.
<record id="base.main_company" model="res.company"> | |
<field name="lock_qty_done">False</field> | |
</record> | |
<function model="res.company" name="write"> | |
<value model="res.company" search="[]" /> | |
<value eval="{'lock_qty_done': False}" /> | |
</function> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code.
if not self.company_id.lock_qty_done: | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not self.company_id.lock_qty_done: | |
return True |
self
is a recordset. Apply the check inside the for
loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code.
_inherit = "res.company" | ||
|
||
lock_qty_done = fields.Boolean( | ||
default=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But last question, why enabling it by default?
IMHO, that should be done on your project side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought is that users install this module because they want to use its features. So, requiring them to change the settings after installing the module feels a bit strange to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has been always a debate. But that changes Odoo standard behavior. Which is not always wanted. That's why enabling the feature on deployment is better.
And you avoid disabling it in demo data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code.
d4f4cd6
to
ba4bd44
Compare
ba4bd44
to
101a2bf
Compare
@yostashiro Please review the PR with the latest changes. |
101a2bf
to
dff0632
Compare
To configure this module, you need to add the users allowed to edit the done quntity | ||
for done moves to the group "Can edit done quantity for done stock moves" | ||
|
||
Enable the 'Limit Updates to Done Quantity After Validation' option under 'Inventory > Settings' to enable the restriction of modifying the done quantity for validated stock moves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To configure this module, you need to add the users allowed to edit the done quntity | |
for done moves to the group "Can edit done quantity for done stock moves" | |
Enable the 'Limit Updates to Done Quantity After Validation' option under 'Inventory > Settings' to enable the restriction of modifying the done quantity for validated stock moves. | |
Update the following settings: | |
* Go to *Inventory > Settings* and select 'Limit Updates to Done Quantity After Validation' option to enable the restriction. This should be done for each company. | |
* Add users allowed to edit the done quantity for done moves to the group 'Can edit done quantity for done stock moves'. |
dff0632
to
f47aa80
Compare
…dules from failing
f47aa80
to
3f0e04b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Before this PR, if we had other test cases that updated the done quantity after the transfer was done in our module, they would be blocked by
stock_move_line_lock_qty_done
. This PR addresses that issue.@qrtl QT4650