diff --git a/hr_expense_cancel/README.rst b/hr_expense_cancel/README.rst new file mode 100644 index 000000000..220f2fd2b --- /dev/null +++ b/hr_expense_cancel/README.rst @@ -0,0 +1,116 @@ +================= +Hr expense cancel +================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:659127f8c6e5f2db749db28e1d7681511ae898c25356a3293ea5094ba6c89b88 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--expense-lightgray.png?logo=github + :target: https://github.com/OCA/hr-expense/tree/18.0/hr_expense_cancel + :alt: OCA/hr-expense +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-expense-18-0/hr-expense-18-0-hr_expense_cancel + :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/hr-expense&target_branch=18.0 + :alt: Try me on Runboat + +|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: + +1. Go to *Expenses -> My Expenses -> Expenses to Submit* and create a + new *Expense* with *Employee (to reimburse)* checked on the field + *Payment By* +2. Click on *Submit to Manager* button +3. Click on *Approve* button +4. Click on *Post Journal Entries* button +5. Click on *Register Payment* button, fill in the data of the wizard + and click on *Validate* button +6. After that, the *Expense report* will have an associated journal + entry reconciled with a payment +7. Click on *Cancel* button +8. 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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Pedro M. Baeza + - Ernesto Tejeda + - Stefan Ungureanu + +- Danh Vo +- Saran Lim. +- Manuel Regidor +- Italo LOPES + +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-expense `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_expense_cancel/__init__.py b/hr_expense_cancel/__init__.py new file mode 100644 index 000000000..4b76c7b2d --- /dev/null +++ b/hr_expense_cancel/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/hr_expense_cancel/__manifest__.py b/hr_expense_cancel/__manifest__.py new file mode 100644 index 000000000..1cbee5e02 --- /dev/null +++ b/hr_expense_cancel/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Hr expense cancel", + "version": "18.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/hr-expense", + "license": "AGPL-3", + "category": "Human Resources", + # The module hr_expense_payment function is to link the generated payments + # with it's corresponding expense sheet. + # So when you want to cancel payments associated to a expense_sheet, + # you need to know which payments are related with your expense sheet. + # And that information is not available by inheriting hr_expense alone, + # we need the module + "depends": ["hr_expense_payment"], + "data": ["views/hr_expense_views.xml"], + "installable": True, +} diff --git a/hr_expense_cancel/i18n/es.po b/hr_expense_cancel/i18n/es.po new file mode 100644 index 000000000..96f30a04f --- /dev/null +++ b/hr_expense_cancel/i18n/es.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_cancel +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-06-02 07:12+0000\n" +"PO-Revision-Date: 2023-06-02 07:12+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \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_terms:ir.ui.view,arch_db:hr_expense_cancel.view_hr_expense_sheet_form +msgid "Cancel all related operations" +msgstr "Cancelar todas las operaciones relacionadas" + +#. module: hr_expense_cancel +#: model_terms:ir.ui.view,arch_db:hr_expense_cancel.view_hr_expense_sheet_form +msgid "Cancel journal entries, payments and reconciliations" +msgstr "Cancelar asientos, pagos y conciliaciones" + +#. module: hr_expense_cancel +#: model:ir.model,name:hr_expense_cancel.model_hr_expense_sheet +msgid "Expense Report" +msgstr "Informe de gastos" + +#. module: hr_expense_cancel +#: model:ir.model,name:hr_expense_cancel.model_account_payment +msgid "Payments" +msgstr "" diff --git a/hr_expense_cancel/i18n/hr_expense_cancel.pot b/hr_expense_cancel/i18n/hr_expense_cancel.pot new file mode 100644 index 000000000..0f8dcd84e --- /dev/null +++ b/hr_expense_cancel/i18n/hr_expense_cancel.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_cancel +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \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_terms:ir.ui.view,arch_db:hr_expense_cancel.view_hr_expense_sheet_form +msgid "Cancel all related operations" +msgstr "" + +#. module: hr_expense_cancel +#: model_terms:ir.ui.view,arch_db:hr_expense_cancel.view_hr_expense_sheet_form +msgid "Cancel journal entries, payments and reconciliations" +msgstr "" + +#. module: hr_expense_cancel +#: model:ir.model,name:hr_expense_cancel.model_hr_expense_sheet +msgid "Expense Report" +msgstr "" + +#. module: hr_expense_cancel +#: model:ir.model,name:hr_expense_cancel.model_account_payment +msgid "Payments" +msgstr "" diff --git a/hr_expense_cancel/i18n/it.po b/hr_expense_cancel/i18n/it.po new file mode 100644 index 000000000..899d314d2 --- /dev/null +++ b/hr_expense_cancel/i18n/it.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_cancel +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-07-31 08:58+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: hr_expense_cancel +#: model_terms:ir.ui.view,arch_db:hr_expense_cancel.view_hr_expense_sheet_form +msgid "Cancel all related operations" +msgstr "Annulla tutte le operazioni relative" + +#. module: hr_expense_cancel +#: model_terms:ir.ui.view,arch_db:hr_expense_cancel.view_hr_expense_sheet_form +msgid "Cancel journal entries, payments and reconciliations" +msgstr "Annulla registrazioni contabili, pagamenti e riconciliazioni" + +#. module: hr_expense_cancel +#: model:ir.model,name:hr_expense_cancel.model_hr_expense_sheet +msgid "Expense Report" +msgstr "Nota spese" + +#. module: hr_expense_cancel +#: model:ir.model,name:hr_expense_cancel.model_account_payment +msgid "Payments" +msgstr "Pagamenti" diff --git a/hr_expense_cancel/models/__init__.py b/hr_expense_cancel/models/__init__.py new file mode 100644 index 000000000..88a0abd92 --- /dev/null +++ b/hr_expense_cancel/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import account_payment +from . import hr_expense diff --git a/hr_expense_cancel/models/account_payment.py b/hr_expense_cancel/models/account_payment.py new file mode 100644 index 000000000..51c607273 --- /dev/null +++ b/hr_expense_cancel/models/account_payment.py @@ -0,0 +1,12 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AccountPayment(models.Model): + _inherit = "account.payment" + + def action_draft_cancel(self): + for payment in self: + payment.action_draft() + payment.action_cancel() diff --git a/hr_expense_cancel/models/hr_expense.py b/hr_expense_cancel/models/hr_expense.py new file mode 100644 index 000000000..c36f5a33f --- /dev/null +++ b/hr_expense_cancel/models/hr_expense.py @@ -0,0 +1,66 @@ +# Copyright 2019 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class HrExpenseSheet(models.Model): + _inherit = "hr.expense.sheet" + + def action_cancel(self): + for sheet in self: + account_moves = sheet.account_move_ids + sheet.account_move_ids = False + payments = sheet.payment_ids.filtered(lambda line: line.state != "cancel") + # case : cancel invoice from hr_expense + self._remove_reconcile_hr_invoice(account_moves) + # If the sheet is paid then remove payments + if sheet.state in ("done", "approve"): + if sheet.expense_line_ids[:1].payment_mode == "own_account": + self._remove_move_reconcile(payments, account_moves) + payments.action_draft_cancel() + # 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_moves.exists(): + moves_to_cancel = account_moves.filtered( + lambda move: move.state != "draft" + ) + if moves_to_cancel: + moves_to_cancel.button_cancel() + account_moves.with_context(force_delete=True).unlink() + sheet.state = "submit" + + def _remove_reconcile_hr_invoice(self, account_moves): + """Cancel invoice made by hr_expense_invoice module automatically""" + exp_move_lines = self.env["account.move.line"].search( + [ + ( + "full_reconcile_id", + "in", + account_moves.line_ids.full_reconcile_id.ids, + ), + ("move_id", "not in", account_moves.ids), + ] + ) + # set state to cancel + if exp_move_lines: + moves = exp_move_lines.move_id + moves.button_draft() + moves.button_cancel() + + def _remove_move_reconcile(self, payments, account_moves): + """Delete only reconciliations made with the payments generated + by hr_expense module automatically""" + to_unreconcile_move_lines = self.env["account.move.line"].search( + [ + ( + "full_reconcile_id", + "in", + account_moves.line_ids.full_reconcile_id.ids, + ), + ("move_id", "in", payments.move_id.ids), + ] + ) + if to_unreconcile_move_lines: + to_unreconcile_move_lines.remove_move_reconcile() diff --git a/hr_expense_cancel/pyproject.toml b/hr_expense_cancel/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/hr_expense_cancel/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_expense_cancel/readme/CONTRIBUTORS.md b/hr_expense_cancel/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..2099fcf69 --- /dev/null +++ b/hr_expense_cancel/readme/CONTRIBUTORS.md @@ -0,0 +1,8 @@ +- [Tecnativa](https://www.tecnativa.com): + - Pedro M. Baeza + - Ernesto Tejeda + - Stefan Ungureanu +- Danh Vo \<\> +- Saran Lim. \<\> +- Manuel Regidor \<\> +- Italo LOPES \<\> diff --git a/hr_expense_cancel/readme/DESCRIPTION.md b/hr_expense_cancel/readme/DESCRIPTION.md new file mode 100644 index 000000000..0f5c96f38 --- /dev/null +++ b/hr_expense_cancel/readme/DESCRIPTION.md @@ -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. diff --git a/hr_expense_cancel/readme/INSTALL.md b/hr_expense_cancel/readme/INSTALL.md new file mode 100644 index 000000000..efb8c28cb --- /dev/null +++ b/hr_expense_cancel/readme/INSTALL.md @@ -0,0 +1,6 @@ +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. diff --git a/hr_expense_cancel/readme/USAGE.md b/hr_expense_cancel/readme/USAGE.md new file mode 100644 index 000000000..8f276c153 --- /dev/null +++ b/hr_expense_cancel/readme/USAGE.md @@ -0,0 +1,15 @@ +To use this module, you need to: + +1. Go to *Expenses -\> My Expenses -\> Expenses to Submit* and create a + new *Expense* with *Employee (to reimburse)* checked on the field + *Payment By* +2. Click on *Submit to Manager* button +3. Click on *Approve* button +4. Click on *Post Journal Entries* button +5. Click on *Register Payment* button, fill in the data of the wizard + and click on *Validate* button +6. After that, the *Expense report* will have an associated journal + entry reconciled with a payment +7. Click on *Cancel* button +8. The *Expense report* will be set to *Submitted* state; the journal + entry and the payment will be deleted diff --git a/hr_expense_cancel/static/description/icon.png b/hr_expense_cancel/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/hr_expense_cancel/static/description/icon.png differ diff --git a/hr_expense_cancel/static/description/index.html b/hr_expense_cancel/static/description/index.html new file mode 100644 index 000000000..ea5faae00 --- /dev/null +++ b/hr_expense_cancel/static/description/index.html @@ -0,0 +1,464 @@ + + + + + +Hr expense cancel + + + +
+

Hr expense cancel

+ + +

Beta License: AGPL-3 OCA/hr-expense Translate me on Weblate Try me on Runboat

+

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

+ +
+

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:

+
    +
  1. Go to Expenses -> My Expenses -> Expenses to Submit and create a +new Expense with Employee (to reimburse) checked on the field +Payment By
  2. +
  3. Click on Submit to Manager button
  4. +
  5. Click on Approve button
  6. +
  7. Click on Post Journal Entries button
  8. +
  9. Click on Register Payment button, fill in the data of the wizard +and click on Validate button
  10. +
  11. After that, the Expense report will have an associated journal +entry reconciled with a payment
  12. +
  13. Click on Cancel button
  14. +
  15. The Expense report will be set to Submitted state; the journal +entry and the payment will be deleted
  16. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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-expense project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_expense_cancel/tests/__init__.py b/hr_expense_cancel/tests/__init__.py new file mode 100644 index 000000000..b568b9d88 --- /dev/null +++ b/hr_expense_cancel/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import test_hr_expense_cancel diff --git a/hr_expense_cancel/tests/test_hr_expense_cancel.py b/hr_expense_cancel/tests/test_hr_expense_cancel.py new file mode 100644 index 000000000..79f36e0b2 --- /dev/null +++ b/hr_expense_cancel/tests/test_hr_expense_cancel.py @@ -0,0 +1,65 @@ +# Copyright 2019 Tecnativa - Ernesto Tejeda +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +from odoo.tests import Form, tagged + +from odoo.addons.hr_expense.tests.common import TestExpenseCommon + + +@tagged("-at_install", "post_install") +class TestHrExpenseCancel(TestExpenseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Create expense + sheet + approve + cls.expense = cls.create_expense(cls) + res = cls.expense.action_submit_expenses() + cls.expense_sheet = cls.env[res["res_model"]].browse(res["res_id"]) + cls.expense_sheet.action_submit_sheet() + cls.expense_sheet.action_approve_expense_sheets() + + def _get_payment_wizard(self): + res = self.expense_sheet.action_register_payment() + register_form = Form(self.env[res["res_model"]].with_context(**res["context"])) + register_form.journal_id = self.company_data["default_journal_bank"] + register_form.amount = self.expense_sheet.total_amount + return register_form.save() + + def test_action_cancel_posted(self): + self.expense_sheet.action_sheet_move_post() + self.assertFalse(len(self.expense_sheet.payment_ids), 1) + self.assertTrue(self.expense_sheet.account_move_ids) + + self.expense_sheet.action_cancel() + self.assertFalse(self.expense_sheet.payment_ids) + self.assertFalse(self.expense_sheet.account_move_ids) + + def test_action_cancel_no_update_posted(self): + journals = ( + self.company_data["default_journal_bank"] + | self.company_data["default_journal_purchase"] + ) + journals.write({"restrict_mode_hash_table": True}) + # with self.assertRaises(UserError): + # self.test_action_cancel_company_account() + with self.assertRaises(UserError): + self.test_action_cancel_own_account() + self.test_action_cancel_company_account() + + def test_action_cancel_company_account(self): + self.expense.payment_mode = "company_account" + self.expense_sheet.journal_id = self.company_data["default_journal_bank"] + self.expense_sheet.action_sheet_move_post() + self.assertTrue(self.expense_sheet.account_move_ids) + self.expense_sheet.action_cancel() + self.assertFalse(self.expense_sheet.account_move_ids) + + def test_action_cancel_own_account(self): + self.expense_sheet.action_sheet_move_post() + payment_wizard = self._get_payment_wizard() + payment_wizard.action_create_payments() + self.assertTrue(self.expense_sheet.payment_ids) + self.expense_sheet.action_cancel() # assertFalse(payment.exist) + self.assertFalse(self.expense_sheet.payment_ids.state != "canceled") diff --git a/hr_expense_cancel/views/hr_expense_views.xml b/hr_expense_cancel/views/hr_expense_views.xml new file mode 100644 index 000000000..82dc0f63b --- /dev/null +++ b/hr_expense_cancel/views/hr_expense_views.xml @@ -0,0 +1,22 @@ + + + + + hr.expense.sheet.form.inherit + hr.expense.sheet + + + +