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

[16.0][IMP] stock_move_line_lock_qty_done: prevent test cases from other modules from failing #1760

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

AungKoKoLin1997
Copy link
Contributor

@AungKoKoLin1997 AungKoKoLin1997 commented Nov 8, 2024

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

@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as draft November 8, 2024 10:39
@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as ready for review November 8, 2024 10:43
@AungKoKoLin1997
Copy link
Contributor Author

I assume the test cases failed from stock_move_line_auto_fill in this PR is not related with the changes because I see the other PR is facing the same issue.

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
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this suffice?

Suggested change
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

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-imp-stock_move_line_lock_qty_done branch from a356ecc to f863bd7 Compare November 12, 2024 02:28
Copy link
Member

@yostashiro yostashiro left a 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(
Copy link
Contributor

@rousseldenis rousseldenis Nov 15, 2024

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 !

Copy link
Member

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

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.

See comment

@rousseldenis
Copy link
Contributor

@sbejaoui

@AungKoKoLin1997
Copy link
Contributor Author

@sbejaoui Can you please review?

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-imp-stock_move_line_lock_qty_done branch 2 times, most recently from ae8134b to d399ae0 Compare November 16, 2024 03:39
Copy link
Member

@yostashiro yostashiro left a 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>
Copy link
Member

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.

Suggested change
>stock_move_line_lock_qty_done.move_line_lock_qty_done_enable</field>
>stock_move_line_lock_qty_done.lock_qty_done</field>

class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

lock_qty_done = fields.Boolean(
Copy link
Contributor

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.

Copy link
Contributor Author

@AungKoKoLin1997 AungKoKoLin1997 Nov 18, 2024

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.

Copy link
Contributor

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_parameterthat allows to avoid such get/set.

Comment on lines 3 to 5
<record id="base.main_company" model="res.company">
<field name="lock_qty_done">False</field>
</record>
Copy link
Member

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.

Suggested change
<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>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code.

Comment on lines 13 to 14
if not self.company_id.lock_qty_done:
return True
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if not self.company_id.lock_qty_done:
return True

self is a recordset. Apply the check inside the for loop.

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@rousseldenis rousseldenis Nov 25, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code.

@AungKoKoLin1997
Copy link
Contributor Author

@yostashiro Please review the PR with the latest changes.

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-imp-stock_move_line_lock_qty_done branch from 101a2bf to dff0632 Compare November 25, 2024 09:43
Comment on lines 1 to 4
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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'.

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-imp-stock_move_line_lock_qty_done branch from f47aa80 to 3f0e04b Compare November 25, 2024 10:10
Copy link
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

4 participants