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

[ADD] stock_account_move_show_draft_button #1946

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_account_move_show_draft_button/setup.py
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,
)
105 changes: 105 additions & 0 deletions stock_account_move_show_draft_button/README.rst
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.
1 change: 1 addition & 0 deletions stock_account_move_show_draft_button/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions stock_account_move_show_draft_button/__manifest__.py
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",
],
}
1 change: 1 addition & 0 deletions stock_account_move_show_draft_button/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_move
61 changes: 61 additions & 0 deletions stock_account_move_show_draft_button/models/account_move.py
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()
Copy link
Contributor

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.

Suggested change
self.button_draft()
self.button_draft()
for item in self.sudo().filtered(
lambda x: x.is_inbound
and any(line.stock_valuation_layer_ids for line in x.line_ids)
):
for line in item.line_ids.filtered("stock_valuation_layer_ids"):
svls = line.stock_valuation_layer_ids
value = sum(svls.mapped("value"))
if not float_is_zero(
value, precision_rounding=line.currency_id.rounding
):
svls[0].copy({"value": -value})

Inspired on: OCA/account-invoicing#1813

Copy link
Author

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.

Copy link
Contributor

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

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)
6 changes: 6 additions & 0 deletions stock_account_move_show_draft_button/readme/CONFIGURE.md
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)
8 changes: 8 additions & 0 deletions stock_account_move_show_draft_button/readme/CONTEXT.md
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Denis Roussel <[email protected]>
4 changes: 4 additions & 0 deletions stock_account_move_show_draft_button/readme/DESCRIPTION.md
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 stock_account_move_show_draft_button/security/security.xml
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>
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.
Loading
Loading