-
-
Notifications
You must be signed in to change notification settings - Fork 761
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
[ADD] stock_account_move_show_draft_button #1946
Open
rousseldenis
wants to merge
1
commit into
OCA:16.0
Choose a base branch
from
acsone:16.0-add-account-move-draft-dro
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/stock_account_move_show_draft_button/odoo/addons/stock_account_move_show_draft_button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_account_move_show_draft_button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
==================================== | ||
Stock Account Move Show Draft Button | ||
==================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:36828e6a8c9918a10daf2a99f8abc13630d74db46a50933cb51c31ed60e9d32f | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-financial-tools/tree/16.0/stock_account_move_show_draft_button | ||
:alt: OCA/account-financial-tools | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-stock_account_move_show_draft_button | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module will allow to bypass the protection on draft mode button | ||
visibility on account moves. | ||
|
||
This will not show the draft button in case of hash integrity | ||
restriction. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Use Cases / Context | ||
=================== | ||
|
||
In some situations, people needs to change non critical information that | ||
are not editable if the account move is not draft. | ||
|
||
If stock_account module is installed and stock valuation layers have | ||
been generated, Odoo does not allow to come back to draft. | ||
|
||
The solution provided here would allow to get back to draft mode, log | ||
the information and warn the user about the implications. | ||
|
||
Configuration | ||
============= | ||
|
||
- In Settings > Users & Companies > Users | ||
- Choose a user | ||
- In Access Rights > Technical | ||
- Check the 'Account Moves - Show Draft Button' box in 'Access Rights' | ||
|
||
|Access Rights| | ||
|
||
.. |Access Rights| image:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/stock_account_move_show_draft_button/static/description/access_right.png | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20stock_account_move_show_draft_button%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* ACSONE SA/NV | ||
* ADHOC SA | ||
|
||
Contributors | ||
------------ | ||
|
||
- Denis Roussel [email protected] | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/16.0/stock_account_move_show_draft_button>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# Copyright 2024 ADHOC SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Stock Account Move Show Draft Button", | ||
"summary": """ | ||
This module allows to reset an account move to draft even if there are valuation | ||
lines""", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "ACSONE SA/NV,ADHOC SA,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/account-financial-tools", | ||
"depends": ["stock_account"], | ||
"data": [ | ||
"security/security.xml", | ||
"views/account_move.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_move |
61 changes: 61 additions & 0 deletions
61
stock_account_move_show_draft_button/models/account_move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class AccountMove(models.Model): | ||
|
||
_inherit = "account.move" | ||
|
||
reset_to_draft_bypassed = fields.Boolean( | ||
readonly=True, | ||
help="If this is checked, this record has been reset to draft by bypassing the " | ||
"warning about stock valuations.", | ||
) | ||
allow_draft_button_bypass = fields.Boolean( | ||
compute="_compute_allow_draft_button_bypass", | ||
help="This is a technical field in order to show the reset to draft button if user" | ||
"has the right to.", | ||
) | ||
|
||
@api.depends("show_reset_to_draft_button", "restrict_mode_hash_table", "state") | ||
def _compute_allow_draft_button_bypass(self): | ||
user_has_access = self.env.user.has_group( | ||
"stock_account_move_show_draft_button.can_bypass_draft_button" | ||
) | ||
for move in self: | ||
if ( | ||
user_has_access | ||
and not move.show_reset_to_draft_button | ||
and not move.restrict_mode_hash_table | ||
and move.state in ("posted", "cancel") | ||
): | ||
move.allow_draft_button_bypass = True | ||
else: | ||
move.allow_draft_button_bypass = False | ||
|
||
def action_button_draft_bypass(self): | ||
self.ensure_one() | ||
if not self.allow_draft_button_bypass: | ||
raise UserError( | ||
_( | ||
"You don't have the right to bypass the draft state restriction! " | ||
"Please ask your administrator." | ||
) | ||
) | ||
self.button_draft() | ||
self.write({"reset_to_draft_bypassed": True}) | ||
self._log_to_draft_bypass() | ||
|
||
def _log_to_draft_bypass(self): | ||
""" | ||
Post a message on account move that the user had bypassed the | ||
warning about resetting to draft. | ||
""" | ||
self.ensure_one() | ||
body = _( | ||
"The move was reset to draft by bypassing the warning about stock valuations." | ||
) | ||
self.message_post(body=body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- In Settings > Users & Companies > Users | ||
- Choose a user | ||
- In Access Rights > Technical | ||
- Check the 'Account Moves - Show Draft Button' box in 'Access Rights' | ||
|
||
![Access Rights](../static/description/access_right.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
In some situations, people needs to change non critical information that are | ||
not editable if the account move is not draft. | ||
|
||
If stock_account module is installed and stock valuation layers have been generated, | ||
Odoo does not allow to come back to draft. | ||
|
||
The solution provided here would allow to get back to draft mode, log the information | ||
and warn the user about the implications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Denis Roussel <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This module will allow to bypass the protection on draft mode button visibility on | ||
account moves. | ||
|
||
This will not show the draft button in case of hash integrity restriction. |
13 changes: 13 additions & 0 deletions
13
stock_account_move_show_draft_button/security/security.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2024 ACSONE SA/NV | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="can_bypass_draft_button" model="res.groups"> | ||
<field name="name">Account Moves - Show Draft Button</field> | ||
<field name="category_id" ref="base.module_category_hidden" /> | ||
<field name="users" eval="[(4, ref('base.user_root'))]" /> | ||
<field | ||
name="comment" | ||
>This group should be given to users that have the right to bypass the draft button visibility.</field> | ||
</record> | ||
</odoo> |
Binary file added
BIN
+109 KB
stock_account_move_show_draft_button/static/description/access_right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this development finally stays we should look at including this code and perhaps simplifying it after this change.
Inspired on: OCA/account-invoicing#1813
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 don't like having both modules. I will test yours and give feedback today.
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.
Of course, I don't want both modules either...
I've put this up because I don't care which one stays, what matters to me is that this is the way forward for a good solution. 😉