-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] account_cutoff_base: auto reverse
Allow to automatically reverse generated moves
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Copyright 2013-2021 Akretion (http://www.akretion.com/) | ||
# @author: Alexis de Lattre <[email protected]> | ||
# Copyright 2013 Alexis de Lattre (Akretion) <alexis.delattre@akretion.com> | ||
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import json | ||
|
@@ -109,6 +109,17 @@ def _default_cutoff_account_id(self): | |
copy=False, | ||
check_company=True, | ||
) | ||
auto_reverse = fields.Boolean( | ||
help="Automatically reverse created move on following day. Use this " | ||
"if you accrue a value end of period that you want to reverse " | ||
"begin of next period", | ||
) | ||
move_reversal_id = fields.Many2one( | ||
"account.move", | ||
string="Cut-off Journal Entry Reversal", | ||
readonly=True, | ||
copy=False, | ||
) | ||
move_ref = fields.Char( | ||
string="Reference of the Cut-off Journal Entry", | ||
states={"done": [("readonly", True)]}, | ||
|
@@ -191,6 +202,10 @@ def name_get(self): | |
|
||
def back2draft(self): | ||
self.ensure_one() | ||
if self.move_reversal_id: | ||
self.move_reversal_id.line_ids.remove_move_reconcile() | ||
self.move_reversal_id.unlink() | ||
self.move_id.line_ids.remove_move_reconcile() | ||
if self.move_id: | ||
self.move_id.unlink() | ||
self.write({"state": "draft"}) | ||
|
@@ -325,7 +340,18 @@ def create_move(self): | |
move = move_obj.create(vals) | ||
if self.company_id.post_cutoff_move: | ||
move._post(soft=False) | ||
self.write({"move_id": move.id, "state": "done"}) | ||
|
||
data = {"move_id": move.id, "state": "done"} | ||
|
||
if self.auto_reverse: | ||
next_day = fields.Date.from_string(self.cutoff_date) + relativedelta(days=1) | ||
rev_move = move._reverse_move(next_day, move.journal_id) | ||
rev_move.ref = _("reversal of: ") + move.ref | ||
data["move_reversal_id"] = rev_move.id | ||
if self.company_id.post_cutoff_move: | ||
rev_move._post(soft=False) | ||
|
||
self.write(data) | ||
self.message_post(body=_("Journal entry generated")) | ||
|
||
action = self.env.ref("account.action_move_journal_line").sudo().read()[0] | ||
|
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
* Jim Hoefnagels <[email protected]> | ||
* `Trobz <https://trobz.com>`_: | ||
* Dzung Tran <[email protected]> | ||
* Jacques-Etienne Baudoux (BCIM) <[email protected]> |