mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MIG]account_lock_to_date to v13
This commit is contained in:
committed by
AaronHForgeFlow
parent
eada258ab8
commit
98d033b32c
@@ -5,7 +5,7 @@
|
||||
"name": "Account Lock To Date",
|
||||
"summary": """
|
||||
Allows to set an account lock date in the future.""",
|
||||
"version": "12.0.1.0.0",
|
||||
"version": "13.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/account-financial-tools",
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
# Copyright 2019 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import _, api, models
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
@api.multi
|
||||
def _check_lock_date(self):
|
||||
res = super()._check_lock_date()
|
||||
def _check_lock_to_dates(self):
|
||||
for move in self:
|
||||
lock_to_date = (
|
||||
min(
|
||||
@@ -34,4 +32,15 @@ class AccountMove(models.Model):
|
||||
"with the 'Adviser' role"
|
||||
) % (lock_to_date)
|
||||
raise UserError(message)
|
||||
return res
|
||||
|
||||
def action_post(self):
|
||||
self._check_lock_to_dates()
|
||||
return super().action_post()
|
||||
|
||||
def button_cancel(self):
|
||||
self._check_lock_to_dates()
|
||||
return super().button_cancel()
|
||||
|
||||
def button_draft(self):
|
||||
self._check_lock_to_dates()
|
||||
return super().button_draft()
|
||||
|
||||
@@ -7,7 +7,7 @@ from time import mktime
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import SUPERUSER_ID, _, api, fields, models
|
||||
from odoo import SUPERUSER_ID, _, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools.misc import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
@@ -28,14 +28,12 @@ class ResCompany(models.Model):
|
||||
"this date. Use it for fiscal year locking for example.",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
# fiscalyear_lock_date can't be set to a prior date
|
||||
if "fiscalyear_lock_to_date" in vals or "period_lock_to_date" in vals:
|
||||
self._check_lock_to_dates(vals)
|
||||
return super(ResCompany, self).write(vals)
|
||||
|
||||
@api.multi
|
||||
def _check_lock_to_dates(self, vals):
|
||||
"""Check the lock to dates for the current companies.
|
||||
|
||||
@@ -118,7 +116,6 @@ class ResCompany(models.Model):
|
||||
)
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _validate_fiscalyear_lock(self, values):
|
||||
res = super()._validate_fiscalyear_lock(values)
|
||||
if values.get("fiscalyear_lock_to_date"):
|
||||
|
||||
@@ -14,9 +14,9 @@ class TestAccountLockToDateUpdate(TransactionCase):
|
||||
self.company = self.env.ref("base.main_company")
|
||||
self.demo_user = self.env.ref("base.user_demo")
|
||||
self.adviser_group = self.env.ref("account.group_account_manager")
|
||||
self.UpdateLockToDateUpdateObj = self.env["account.update.lock_to_date"].sudo(
|
||||
self.demo_user
|
||||
)
|
||||
self.UpdateLockToDateUpdateObj = self.env[
|
||||
"account.update.lock_to_date"
|
||||
].with_user(self.demo_user)
|
||||
self.AccountObj = self.env["account.account"]
|
||||
self.AccountJournalObj = self.env["account.journal"]
|
||||
self.AccountMoveObj = self.env["account.move"]
|
||||
@@ -89,7 +89,7 @@ class TestAccountLockToDateUpdate(TransactionCase):
|
||||
)
|
||||
self.demo_user.write({"groups_id": [(3, self.adviser_group.id)]})
|
||||
with self.assertRaises(UserError):
|
||||
wizard.sudo(self.demo_user.id).execute()
|
||||
wizard.with_user(self.demo_user.id).execute()
|
||||
|
||||
def test_02_update_with_access(self):
|
||||
wizard = self.create_account_lock_date_update()
|
||||
@@ -100,7 +100,7 @@ class TestAccountLockToDateUpdate(TransactionCase):
|
||||
}
|
||||
)
|
||||
self.demo_user.write({"groups_id": [(4, self.adviser_group.id)]})
|
||||
wizard.sudo(self.demo_user.id).execute()
|
||||
wizard.with_user(self.demo_user.id).execute()
|
||||
self.assertEqual(
|
||||
self.company.period_lock_to_date,
|
||||
datetime.strptime("2900-01-01", DEFAULT_SERVER_DATE_FORMAT).date(),
|
||||
@@ -117,7 +117,7 @@ class TestAccountLockToDateUpdate(TransactionCase):
|
||||
self.company.fiscalyear_lock_to_date = "2900-02-01"
|
||||
move = self.create_account_move("2900-01-01")
|
||||
with self.assertRaises(UserError):
|
||||
move.sudo(self.demo_user.id).post()
|
||||
move.with_user(self.demo_user.id).action_post()
|
||||
|
||||
def test_04_create_move_inside_period(self):
|
||||
"""We test that we can successfully create a journal entry
|
||||
@@ -125,7 +125,7 @@ class TestAccountLockToDateUpdate(TransactionCase):
|
||||
self.company.period_lock_to_date = "2900-01-01"
|
||||
self.company.fiscalyear_lock_to_date = "2900-02-01"
|
||||
move = self.create_account_move("2800-01-01")
|
||||
move.sudo(self.demo_user.id).post()
|
||||
move.with_user(self.demo_user.id).action_post()
|
||||
self.assertEqual(move.state, "posted")
|
||||
|
||||
def test_05_lock_period_with_draft_moves(self):
|
||||
|
||||
@@ -41,14 +41,12 @@ class AccountUpdateLockToDate(models.TransientModel):
|
||||
)
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def _check_execute_allowed(self):
|
||||
self.ensure_one()
|
||||
has_adviser_group = self.env.user.has_group("account.group_account_manager")
|
||||
if not (has_adviser_group or self.env.uid == SUPERUSER_ID):
|
||||
raise UserError(_("You are not allowed to execute this action."))
|
||||
|
||||
@api.multi
|
||||
def execute(self):
|
||||
self.ensure_one()
|
||||
self._check_execute_allowed()
|
||||
|
||||
@@ -1,44 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- # Copyright 2019 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).-->
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="account_update_lock_to_date_form_view">
|
||||
<field name="name">account.update.lock_to_date.form</field>
|
||||
<field name="model">account.update.lock_to_date</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header/>
|
||||
<header />
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="company_id" options="{'no_create': True}"
|
||||
groups="base.group_multi_company"/>
|
||||
<field name="period_lock_to_date"/>
|
||||
<field name="fiscalyear_lock_to_date"/>
|
||||
<field
|
||||
name="company_id"
|
||||
options="{'no_create': True}"
|
||||
groups="base.group_multi_company"
|
||||
/>
|
||||
<field name="period_lock_to_date" />
|
||||
<field name="fiscalyear_lock_to_date" />
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button string="Update" name="execute" type="object" class="btn-primary"/>
|
||||
<button string="Cancel" class="btn-default" special="cancel"/>
|
||||
<button
|
||||
string="Update"
|
||||
name="execute"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
/>
|
||||
<button string="Cancel" class="btn-default" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="ir.actions.act_window" id="account_update_lock_to_date_act_window">
|
||||
<field name="name">Update accounting lock to dates</field>
|
||||
<field name="res_model">account.update.lock_to_date</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.menu" id="account_update_lock_to_date_menu">
|
||||
<field name="name">Update accounting lock to dates</field>
|
||||
<field name="parent_id" ref="account.menu_finance_entries_actions"/>
|
||||
<field name="action" ref="account_update_lock_to_date_act_window"/>
|
||||
<field name="groups_id" eval="[(6, 0, [ref('account.group_account_manager')])]"/>
|
||||
<field name="sequence" eval="70"/>
|
||||
<field name="parent_id" ref="account.menu_finance_entries_actions" />
|
||||
<field name="action" ref="account_update_lock_to_date_act_window" />
|
||||
<field
|
||||
name="groups_id"
|
||||
eval="[(6, 0, [ref('account.group_account_manager')])]"
|
||||
/>
|
||||
<field name="sequence" eval="70" />
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user