-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hr_expense_cancel: lets to cancel and correct expenses
This module lets to cancel and correct expenses. It adds a cancel button on the expense sheet that undo reconciliations and delete payments and journal entries.
- Loading branch information
1 parent
cb6d7a2
commit ec2bb89
Showing
18 changed files
with
946 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
================= | ||
Hr expense cancel | ||
================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Fhr-lightgray.png?logo=github | ||
:target: https://github.com/OCA/hr/tree/11.0/hr_expense_cancel | ||
:alt: OCA/hr | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/hr-11-0/hr-11-0-hr_expense_cancel | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/116/11.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows you to cancel and correct expenses. It adds a cancel button | ||
on the expense sheet that undo reconciliations and delete payments and journal | ||
entries. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Installation | ||
============ | ||
|
||
It's assumed that for each expense sheet, the *payments* that are reconciled | ||
with their *journal entry* were created and reconciled by the *Expense Tracker* | ||
module automatically. Therefore, when this module is installed, these payments | ||
will automatically be associated with said expense sheet so that they can be | ||
deleted in case the expense sheet is canceled. | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Go to *Expenses -> My Expenses -> Expenses to Submit* and create a new | ||
*Expense* with *Employee (to reimburse)* checked on the field *Payment By* | ||
#. Click on *Submit to Manager* button | ||
#. Click on *Approve* button | ||
#. Click on *Post Journal Entries* button | ||
#. Click on *Register Payment* button, fill in the data of the wizard and | ||
click on *Validate* button | ||
#. After that, the *Expense report* will have an associated journal entry | ||
reconciled with a payment | ||
#. Click on *Cancel* button | ||
#. The *Expense report* will be set to *Submitted* state; the journal entry and | ||
the payment will be deleted | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_expense_cancel%0Aversion:%2011.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 | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Pedro M. Baeza | ||
* Ernesto Tejeda | ||
|
||
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/hr <https://github.com/OCA/hr/tree/11.0/hr_expense_cancel>`_ 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,5 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models | ||
from . import wizard | ||
from .hooks import post_init_hook |
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,21 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Hr expense cancel", | ||
"version": "11.0.1.0.0", | ||
"author": "Tecnativa, " | ||
"Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/hr", | ||
"license": "AGPL-3", | ||
"category": "Human Resources", | ||
"depends": [ | ||
'hr_expense', | ||
'account_cancel', | ||
], | ||
'data': [ | ||
"views/hr_expense_views.xml", | ||
], | ||
"post_init_hook": "post_init_hook", | ||
"installable": 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,20 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, SUPERUSER_ID | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
""" Trying to fill the source expense sheet in payments """ | ||
with api.Environment.manage(): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
|
||
for sheet in env['hr.expense.sheet'].search([]): | ||
expense_lines = sheet.expense_line_ids | ||
if any(exp.payment_mode == 'own_account' for exp in expense_lines): | ||
amls = sheet.account_move_id.mapped('line_ids') | ||
reconcile = amls.mapped('full_reconcile_id') | ||
aml_payment = reconcile.reconciled_line_ids.filtered( | ||
lambda r: r not in amls) | ||
payment = aml_payment.mapped('payment_id') | ||
payment.write({'expense_sheet_id': sheet.id}) |
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,42 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * hr_expense_cancel | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2019-02-15 06:58+0000\n" | ||
"PO-Revision-Date: 2019-02-15 06:58+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: hr_expense_cancel | ||
#: model:ir.ui.view,arch_db:hr_expense_cancel.view_hr_expense_sheet_form | ||
msgid "Cancel" | ||
msgstr "Cancelar" | ||
|
||
#. module: hr_expense_cancel | ||
#: model:ir.model,name:hr_expense_cancel.model_hr_expense_sheet | ||
msgid "Expense Report" | ||
msgstr "Nota de gastos" | ||
|
||
#. module: hr_expense_cancel | ||
#: model:ir.model,name:hr_expense_cancel.model_hr_expense_sheet_register_payment_wizard | ||
msgid "Expense Report Register Payment wizard" | ||
msgstr "Asistente registro pago de nota de gastos" | ||
|
||
#. module: hr_expense_cancel | ||
#: model:ir.model.fields,field_description:hr_expense_cancel.field_account_payment_expense_sheet_id | ||
msgid "Expense sheet" | ||
msgstr "Nota de gastos" | ||
|
||
#. module: hr_expense_cancel | ||
#: model:ir.model,name:hr_expense_cancel.model_account_payment | ||
msgid "Payments" | ||
msgstr "Pagos" | ||
|
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 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import hr_expense | ||
from . import account_payment |
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 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import models, fields | ||
|
||
|
||
class AccountPayment(models.Model): | ||
_inherit = "account.payment" | ||
|
||
expense_sheet_id = fields.Many2one( | ||
comodel_name="hr.expense.sheet", | ||
string="Expense sheet", | ||
) |
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,63 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class HrExpenseSheet(models.Model): | ||
_inherit = "hr.expense.sheet" | ||
|
||
@api.multi | ||
def action_cancel(self): | ||
for sheet in self: | ||
account_move = sheet.account_move_id | ||
sheet.account_move_id = False | ||
# If the sheet is paid then remove payments | ||
if sheet.state == 'done': | ||
payments = self.env['account.payment'].search([ | ||
('expense_sheet_id', '=', sheet.id), | ||
('state', '!=', 'cancelled'), | ||
]) | ||
if sheet.expense_line_ids[:1].payment_mode == 'own_account': | ||
self._remove_move_reconcile(payments, account_move) | ||
self._cancel_payments(payments) | ||
else: | ||
# In this case, during the cancellation the journal entry | ||
# will be deleted | ||
self._cancel_payments(payments) | ||
payments.unlink() | ||
# Deleting the Journal entry if in the previous steps | ||
# (if the expense sheet is paid and payment_mode == 'own_account') | ||
# it has not been deleted | ||
if account_move.exists(): | ||
if account_move.state != 'draft': | ||
account_move.button_cancel() | ||
account_move.unlink() | ||
sheet.state = 'submit' | ||
|
||
@api.multi | ||
def action_sheet_move_create(self): | ||
res = super(HrExpenseSheet, self).action_sheet_move_create() | ||
if self.expense_line_ids[0].payment_mode == 'company_account': | ||
self.account_move_id.mapped('line_ids.payment_id').write({ | ||
'expense_sheet_id': self.id, | ||
}) | ||
return res | ||
|
||
def _remove_move_reconcile(self, payments, account_move): | ||
"""Delete only reconciliations made with the payments generated | ||
by hr_expense module automatically""" | ||
reconcile = account_move.mapped('line_ids.full_reconcile_id') | ||
|
||
payments_aml = payments.mapped('move_line_ids') | ||
aml_unreconcile = payments_aml.filtered( | ||
lambda r: r.full_reconcile_id in reconcile) | ||
|
||
aml_unreconcile.remove_move_reconcile() | ||
|
||
def _cancel_payments(self, payments): | ||
for rec in payments: | ||
for move in rec.move_line_ids.mapped('move_id'): | ||
move.button_cancel() | ||
move.unlink() | ||
rec.state = 'cancelled' |
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 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Pedro M. Baeza | ||
* Ernesto Tejeda |
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,3 @@ | ||
This module allows you to cancel and correct expenses. It adds a cancel button | ||
on the expense sheet that undo reconciliations and delete payments and journal | ||
entries. |
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,5 @@ | ||
It's assumed that for each expense sheet, the *payments* that are reconciled | ||
with their *journal entry* were created and reconciled by the *Expense Tracker* | ||
module automatically. Therefore, when this module is installed, these payments | ||
will automatically be associated with said expense sheet so that they can be | ||
deleted in case the expense sheet is canceled. |
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,14 @@ | ||
To use this module, you need to: | ||
|
||
#. Go to *Expenses -> My Expenses -> Expenses to Submit* and create a new | ||
*Expense* with *Employee (to reimburse)* checked on the field *Payment By* | ||
#. Click on *Submit to Manager* button | ||
#. Click on *Approve* button | ||
#. Click on *Post Journal Entries* button | ||
#. Click on *Register Payment* button, fill in the data of the wizard and | ||
click on *Validate* button | ||
#. After that, the *Expense report* will have an associated journal entry | ||
reconciled with a payment | ||
#. Click on *Cancel* button | ||
#. The *Expense report* will be set to *Submitted* state; the journal entry and | ||
the payment will be deleted |
Oops, something went wrong.