18.0-migrate-account_advanced_protection_features #25

Merged
mondot merged 3 commits from 18.0-migrate-account_advanced_protection_features into 18.0 2025-10-08 14:07:18 +00:00
9 changed files with 72 additions and 52 deletions
Showing only changes of commit e45ad867c0 - Show all commits

View File

@@ -49,12 +49,9 @@ repos:
$(git rev-parse --show-toplevel))"' $(git rev-parse --show-toplevel))"'
- id: oca-gen-addon-readme - id: oca-gen-addon-readme
entry: entry:
bash -c 'oca-gen-addon-readme bash -c 'oca-gen-addon-readme --addons-dir=. --branch=$(git symbolic-ref
--addons-dir=.
--branch=$(git symbolic-ref
refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@") refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")
--repo-name=$(basename $(git rev-parse --show-toplevel)) --repo-name=$(basename $(git rev-parse --show-toplevel)) --org-name="Elabore"
--org-name="Elabore"
--if-source-changed --keep-source-digest' --if-source-changed --keep-source-digest'
- repo: https://github.com/OCA/odoo-pre-commit-hooks - repo: https://github.com/OCA/odoo-pre-commit-hooks

View File

@@ -1,2 +1,2 @@
*.*~ *.*~
*pyc *pyc

View File

@@ -3,27 +3,21 @@
{ {
"name": "account_advanced_protection_features", "name": "account_advanced_protection_features",
"version": "16.0.1.0.0", "version": "18.0.1.0.0",
"author": "Elabore", "author": "Elabore",
"website": "https://elabore.coop", "website": "https://git.elabore.coop/elabore/account-tools",
"maintainer": "Quentin Mondot", "maintainer": "Quentin Mondot",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Tools", "category": "Tools",
"summary": "Add several protection features about accounting", "summary": "Add several protection features about accounting",
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
"depends": [ "depends": ["base", "account"],
"base",
"account"
],
"qweb": [], "qweb": [],
"external_dependencies": { "external_dependencies": {
"python": [], "python": [],
}, },
# always loaded # always loaded
"data": [ "data": ["security/res_groups.xml", "views/account_journal_views.xml"],
"security/res_groups.xml",
"views/account_journal_views.xml"
],
# only loaded in demonstration mode # only loaded in demonstration mode
"demo": [], "demo": [],
"js": [], "js": [],

View File

@@ -4,7 +4,7 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 16.0\n" "Project-Id-Version: Odoo Server 18.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-08-29 08:28+0000\n" "POT-Creation-Date: 2025-08-29 08:28+0000\n"
"PO-Revision-Date: 2025-08-29 08:28+0000\n" "PO-Revision-Date: 2025-08-29 08:28+0000\n"

View File

@@ -1,6 +1,7 @@
from odoo import models, _ from odoo import _, models
from odoo.exceptions import UserError from odoo.exceptions import UserError
class AccountBankStatement(models.Model): class AccountBankStatement(models.Model):
_inherit = "account.bank.statement" _inherit = "account.bank.statement"
@@ -8,12 +9,16 @@ class AccountBankStatement(models.Model):
for statement in self: for statement in self:
if not statement.journal_id.allow_bank_statement_deletion: if not statement.journal_id.allow_bank_statement_deletion:
raise UserError( raise UserError(
_("The deletion of bank statements is not allowed for the journal %s.") % statement.journal_id.display_name _(
"The deletion of bank statements is "
"not allowed for the journal %s."
)
% statement.journal_id.display_name
) )
# we delete all the statement lines before deleting the statement itself # we delete all the statement lines before deleting the statement itself
for line in statement.line_ids: for line in statement.line_ids:
line.unlink() line.unlink()
return super(AccountBankStatement, self).unlink() return super().unlink()
class AccountBankStatementLine(models.Model): class AccountBankStatementLine(models.Model):
@@ -23,6 +28,10 @@ class AccountBankStatementLine(models.Model):
for line in self: for line in self:
if not line.journal_id.allow_bank_statement_deletion: if not line.journal_id.allow_bank_statement_deletion:
raise UserError( raise UserError(
_("The deletion of bank statement lines is not allowed for the journal %s.") % line.journal_id.display_name _(
"The deletion of bank statement lines is "
"not allowed for the journal %s."
)
% line.journal_id.display_name
) )
return super(AccountBankStatementLine, self).unlink() return super().unlink()

View File

@@ -1,12 +1,18 @@
from odoo import models, fields from odoo import fields, models
class AccountJournal(models.Model): class AccountJournal(models.Model):
_inherit = "account.journal" _inherit = "account.journal"
prevent_reset_to_draft_sent_invoice = fields.Boolean("Prevent to reset to draft a sent invoice") prevent_reset_to_draft_sent_invoice = fields.Boolean(
prevent_deletion_of_posted_account_move = fields.Boolean("Prevent to delete an already posted account move") "Prevent to reset to draft a sent invoice"
)
prevent_deletion_of_posted_account_move = fields.Boolean(
"Prevent to delete an already posted account move"
)
allow_bank_statement_deletion = fields.Boolean( allow_bank_statement_deletion = fields.Boolean(
"Allow bank statements deletion", "Allow bank statements deletion",
help="Users with group Show Full Accounting Features (id: group_account_user) will be allowed to delete account bank statements " help="Users with group Show Full Accounting Features (id: group_account_user) "
"and bank statement lines." "will be allowed to delete account bank statements "
"and bank statement lines.",
) )

View File

@@ -1,23 +1,34 @@
from odoo import models, api, fields, _ from odoo import _, api, models
from odoo.exceptions import UserError from odoo.exceptions import UserError
class AccountMove(models.Model): class AccountMove(models.Model):
_inherit = 'account.move' _inherit = "account.move"
def button_draft(self): def button_draft(self):
if self.is_move_sent and self.journal_id.prevent_reset_to_draft_sent_invoice: if self.is_move_sent and self.journal_id.prevent_reset_to_draft_sent_invoice:
raise UserError(_( raise UserError(
"You cannot reset to draft this invoice because it has been sent by email." _(
)) "You cannot reset to draft this invoice because it "
return super(AccountMove, self).button_draft() "has been sent by email."
)
)
return super().button_draft()
@api.ondelete(at_uninstall=False) @api.ondelete(at_uninstall=False)
def _check_posted(self): def _check_posted(self):
""" Prevent deletion of an account move if it has already been posted and """
journal parameter prevent_deletion_of_posted_account_move is activated Prevent deletion of an account move if it has already been posted and journal
parameter prevent_deletion_of_posted_account_move is activated.
""" """
for rec in self: for rec in self:
if rec.posted_before and rec.journal_id.prevent_deletion_of_posted_account_move: if (
raise UserError(_( rec.posted_before
"You cannot delete this account move because it has already been posted." and rec.journal_id.prevent_deletion_of_posted_account_move
)) ):
raise UserError(
_(
"You cannot delete this account move because it "
"has already been posted."
)
)

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="group_account_protection_manager" model="res.groups"> <record id="group_account_protection_manager" model="res.groups">
<field name="name">Access to account advanced protection features</field> <field name="name">Access to account advanced protection features</field>
<field name="category_id" ref="base.module_category_hidden"/> <field name="category_id" ref="base.module_category_hidden" />
</record> </record>
</odoo> </odoo>

View File

@@ -1,24 +1,27 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="view_account_journal_form_inherit_prevent_reset_to_draft" model="ir.ui.view"> <record
id="view_account_journal_form_inherit_prevent_reset_to_draft"
model="ir.ui.view"
>
<field name="name">account.journal.form</field> <field name="name">account.journal.form</field>
<field name="model">account.journal</field> <field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/> <field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='restrict_mode_hash_table']" position="after"> <xpath expr="//field[@name='restrict_mode_hash_table']" position="after">
<field <field
name="prevent_deletion_of_posted_account_move" name="prevent_deletion_of_posted_account_move"
groups="account_advanced_protection_features.group_account_protection_manager" groups="account_advanced_protection_features.group_account_protection_manager"
/> />
<field <field
name="prevent_reset_to_draft_sent_invoice" name="prevent_reset_to_draft_sent_invoice"
groups="account_advanced_protection_features.group_account_protection_manager" groups="account_advanced_protection_features.group_account_protection_manager"
attrs="{'invisible': [('type', '!=', 'sale')]}" attrs="{'invisible': [('type', '!=', 'sale')]}"
/> />
<field <field
name="allow_bank_statement_deletion" name="allow_bank_statement_deletion"
groups="account_advanced_protection_features.group_account_protection_manager" groups="account_advanced_protection_features.group_account_protection_manager"
attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}" attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}"
/> />
</xpath> </xpath>
</field> </field>