diff --git a/hr_expense_pay_to_vendor/README.rst b/hr_expense_pay_to_vendor/README.rst new file mode 100644 index 000000000..0e8f0827c --- /dev/null +++ b/hr_expense_pay_to_vendor/README.rst @@ -0,0 +1,112 @@ +========================== +HR Expense - Pay To Vendor +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:35b4d6a5e7979037d4a3fa64fbf7222c10e47e8d7fcdcdf22246874df1f2f8f3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/17.0/hr_expense_pay_to_vendor + :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-17-0/hr-expense-17-0-hr_expense_pay_to_vendor + :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=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allow expense "Pay to Vendor" as option when user select, +Paid By Company. + +**Pay to Vendor** is suitable for cases when user wanted to buy +something, i.e., Plane Ticket, but do not want to pay money him/herself +and use expense as the way to make payment order to accounting +department. + +When expense has posted journal entry, the AR will be set to Vendor (and +not the Employee). Then, register the payment will be clearing the AR to +Bank. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Go to *Expenses -> My Expenses -> Expenses to Submit* and create a + new *Expense* with *Company* as Paid By, and a Vendor as Pay to + Vendor +2. Click on *Submit to Manager* button +3. Click on *Approve* button +4. Click on *Post Journal Entries* button, the Receivable will be on + Vendor +5. Click on *Register Payment* button, fill in the data of the wizard + and click on *Validate* button + +You can now check that the partner in journal entries are on Vendor, and +not on Employee. + +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 +------- + +* Ecosoft + +Contributors +------------ + +- Kitti U. + +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. + +.. |maintainer-kittiu| image:: https://github.com/kittiu.png?size=40px + :target: https://github.com/kittiu + :alt: kittiu + +Current `maintainer `__: + +|maintainer-kittiu| + +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_pay_to_vendor/__init__.py b/hr_expense_pay_to_vendor/__init__.py new file mode 100644 index 000000000..4b76c7b2d --- /dev/null +++ b/hr_expense_pay_to_vendor/__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_pay_to_vendor/__manifest__.py b/hr_expense_pay_to_vendor/__manifest__.py new file mode 100644 index 000000000..492887f9b --- /dev/null +++ b/hr_expense_pay_to_vendor/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Ecosoft +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "HR Expense - Pay To Vendor", + "version": "17.0.1.0.0", + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/hr-expense", + "license": "AGPL-3", + "category": "Human Resources", + "depends": ["hr_expense"], + "data": ["views/hr_expense_views.xml"], + "installable": True, + "maintainers": ["kittiu"], +} diff --git a/hr_expense_pay_to_vendor/i18n/hr_expense_pay_to_vendor.pot b/hr_expense_pay_to_vendor/i18n/hr_expense_pay_to_vendor.pot new file mode 100644 index 000000000..228b5730e --- /dev/null +++ b/hr_expense_pay_to_vendor/i18n/hr_expense_pay_to_vendor.pot @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_pay_to_vendor +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_pay_to_vendor +#: model:ir.model,name:hr_expense_pay_to_vendor.model_hr_expense +msgid "Expense" +msgstr "" + +#. module: hr_expense_pay_to_vendor +#: model:ir.model,name:hr_expense_pay_to_vendor.model_hr_expense_sheet +msgid "Expense Report" +msgstr "" + +#. module: hr_expense_pay_to_vendor +#. odoo-python +#: code:addons/hr_expense_pay_to_vendor/models/hr_expense.py:0 +#, python-format +msgid "Expenses must be paying to the same vendor." +msgstr "" + +#. module: hr_expense_pay_to_vendor +#: model:ir.model.fields,help:hr_expense_pay_to_vendor.field_hr_expense__vendor_id +#: model:ir.model.fields,help:hr_expense_pay_to_vendor.field_hr_expense_sheet__vendor_id +msgid "Paid by company direct to this vendor" +msgstr "" + +#. module: hr_expense_pay_to_vendor +#: model:ir.model.fields,field_description:hr_expense_pay_to_vendor.field_hr_expense__vendor_id +#: model:ir.model.fields,field_description:hr_expense_pay_to_vendor.field_hr_expense_sheet__vendor_id +msgid "To Vendor" +msgstr "" diff --git a/hr_expense_pay_to_vendor/i18n/it.po b/hr_expense_pay_to_vendor/i18n/it.po new file mode 100644 index 000000000..51348cb6f --- /dev/null +++ b/hr_expense_pay_to_vendor/i18n/it.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_pay_to_vendor +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-29 13:08+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 4.17\n" + +#. module: hr_expense_pay_to_vendor +#: model:ir.model,name:hr_expense_pay_to_vendor.model_hr_expense +msgid "Expense" +msgstr "Spesa" + +#. module: hr_expense_pay_to_vendor +#: model:ir.model,name:hr_expense_pay_to_vendor.model_hr_expense_sheet +msgid "Expense Report" +msgstr "Nota spese" + +#. module: hr_expense_pay_to_vendor +#. odoo-python +#: code:addons/hr_expense_pay_to_vendor/models/hr_expense.py:0 +#, python-format +msgid "Expenses must be paying to the same vendor." +msgstr "La spesa deve essere pagata allo stesso fornitore." + +#. module: hr_expense_pay_to_vendor +#: model:ir.model.fields,help:hr_expense_pay_to_vendor.field_hr_expense__vendor_id +#: model:ir.model.fields,help:hr_expense_pay_to_vendor.field_hr_expense_sheet__vendor_id +msgid "Paid by company direct to this vendor" +msgstr "Pagato direttamente al fornitore dall'azienda" + +#. module: hr_expense_pay_to_vendor +#: model:ir.model.fields,field_description:hr_expense_pay_to_vendor.field_hr_expense__vendor_id +#: model:ir.model.fields,field_description:hr_expense_pay_to_vendor.field_hr_expense_sheet__vendor_id +msgid "To Vendor" +msgstr "Al fornitore" diff --git a/hr_expense_pay_to_vendor/models/__init__.py b/hr_expense_pay_to_vendor/models/__init__.py new file mode 100644 index 000000000..5faa7f9c8 --- /dev/null +++ b/hr_expense_pay_to_vendor/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import hr_expense diff --git a/hr_expense_pay_to_vendor/models/hr_expense.py b/hr_expense_pay_to_vendor/models/hr_expense.py new file mode 100644 index 000000000..965261995 --- /dev/null +++ b/hr_expense_pay_to_vendor/models/hr_expense.py @@ -0,0 +1,74 @@ +# Copyright 2021 Ecosoft +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class HrExpense(models.Model): + _inherit = "hr.expense" + + vendor_id = fields.Many2one( + comodel_name="res.partner", + string="To Vendor", + help="Paid by company direct to this vendor", + ) + + def _get_expense_account_destination(self): + self.ensure_one() + if not (self.payment_mode == "company_account" and self.vendor_id): + return super()._get_expense_account_destination() + # Use vendor's account + account_dest = ( + self.vendor_id.property_account_payable_id.id + or self.vendor_id.parent_id.property_account_payable_id.id + ) + return account_dest + + +class HrExpenseSheet(models.Model): + _inherit = "hr.expense.sheet" + + vendor_id = fields.Many2one( + comodel_name="res.partner", + related="expense_line_ids.vendor_id", + string="To Vendor", + readonly=True, + ) + + @api.constrains("expense_line_ids") + def _check_payment_mode(self): + res = super()._check_payment_mode() + for sheet in self: + expenses = sheet.expense_line_ids + payment_mode = expenses.mapped("payment_mode") + if payment_mode and payment_mode[0] == "company_account": + if expenses and any( + expense.vendor_id != expenses[0].vendor_id for expense in expenses + ): + raise ValidationError( + _("Expenses must be paying to the same vendor.") + ) + return res + + def action_sheet_move_create(self): + # For expense paid by copany to vendor, only set state to post + res = super().action_sheet_move_create() + to_post = self.filtered( + lambda l: l.payment_mode == "company_account" and l.vendor_id + ) + to_post.write({"state": "post"}) + return res + + def _prepare_payment_vals(self): + self.ensure_one() + payment_vals = super()._prepare_payment_vals() + if self.payment_mode == "company_account" and self.vendor_id: + for line in payment_vals["line_ids"]: + line[2]["partner_id"] = self.vendor_id.id + # Overwrite name without taxes + if line[2].get("tax_base_amount", False): + continue + expense_name = line[2]["name"].split(":")[1].strip() + line[2]["name"] = f"{self.vendor_id.name}: {expense_name}" + return payment_vals diff --git a/hr_expense_pay_to_vendor/pyproject.toml b/hr_expense_pay_to_vendor/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/hr_expense_pay_to_vendor/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_expense_pay_to_vendor/readme/CONTRIBUTORS.md b/hr_expense_pay_to_vendor/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..db1787028 --- /dev/null +++ b/hr_expense_pay_to_vendor/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Kitti U. \<\> diff --git a/hr_expense_pay_to_vendor/readme/DESCRIPTION.md b/hr_expense_pay_to_vendor/readme/DESCRIPTION.md new file mode 100644 index 000000000..8214d7043 --- /dev/null +++ b/hr_expense_pay_to_vendor/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +This module allow expense "Pay to Vendor" as option when user select, +Paid By Company. + +**Pay to Vendor** is suitable for cases when user wanted to buy +something, i.e., Plane Ticket, but do not want to pay money him/herself +and use expense as the way to make payment order to accounting +department. + +When expense has posted journal entry, the AR will be set to Vendor (and +not the Employee). Then, register the payment will be clearing the AR to +Bank. diff --git a/hr_expense_pay_to_vendor/readme/USAGE.md b/hr_expense_pay_to_vendor/readme/USAGE.md new file mode 100644 index 000000000..44fbb6b53 --- /dev/null +++ b/hr_expense_pay_to_vendor/readme/USAGE.md @@ -0,0 +1,14 @@ +To use this module, you need to: + +1. Go to *Expenses -\> My Expenses -\> Expenses to Submit* and create a + new *Expense* with *Company* as Paid By, and a Vendor as Pay to + Vendor +2. Click on *Submit to Manager* button +3. Click on *Approve* button +4. Click on *Post Journal Entries* button, the Receivable will be on + Vendor +5. Click on *Register Payment* button, fill in the data of the wizard + and click on *Validate* button + +You can now check that the partner in journal entries are on Vendor, and +not on Employee. diff --git a/hr_expense_pay_to_vendor/static/description/icon.png b/hr_expense_pay_to_vendor/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/hr_expense_pay_to_vendor/static/description/icon.png differ diff --git a/hr_expense_pay_to_vendor/static/description/index.html b/hr_expense_pay_to_vendor/static/description/index.html new file mode 100644 index 000000000..b6fccc797 --- /dev/null +++ b/hr_expense_pay_to_vendor/static/description/index.html @@ -0,0 +1,451 @@ + + + + + +HR Expense - Pay To Vendor + + + +
+

HR Expense - Pay To Vendor

+ + +

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

+

This module allow expense “Pay to Vendor” as option when user select, +Paid By Company.

+

Pay to Vendor is suitable for cases when user wanted to buy +something, i.e., Plane Ticket, but do not want to pay money him/herself +and use expense as the way to make payment order to accounting +department.

+

When expense has posted journal entry, the AR will be set to Vendor (and +not the Employee). Then, register the payment will be clearing the AR to +Bank.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Expenses -> My Expenses -> Expenses to Submit and create a +new Expense with Company as Paid By, and a Vendor as Pay to +Vendor
  2. +
  3. Click on Submit to Manager button
  4. +
  5. Click on Approve button
  6. +
  7. Click on Post Journal Entries button, the Receivable will be on +Vendor
  8. +
  9. Click on Register Payment button, fill in the data of the wizard +and click on Validate button
  10. +
+

You can now check that the partner in journal entries are on Vendor, and +not on Employee.

+
+
+

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

+
    +
  • Ecosoft
  • +
+
+ +
+

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.

+

Current maintainer:

+

kittiu

+

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_pay_to_vendor/tests/__init__.py b/hr_expense_pay_to_vendor/tests/__init__.py new file mode 100644 index 000000000..99cce1cfa --- /dev/null +++ b/hr_expense_pay_to_vendor/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_hr_expense_pay_to_vendor diff --git a/hr_expense_pay_to_vendor/tests/test_hr_expense_pay_to_vendor.py b/hr_expense_pay_to_vendor/tests/test_hr_expense_pay_to_vendor.py new file mode 100644 index 000000000..896cf1b82 --- /dev/null +++ b/hr_expense_pay_to_vendor/tests/test_hr_expense_pay_to_vendor.py @@ -0,0 +1,121 @@ +# Copyright 2021 Ecosoft +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +from odoo.tests.common import BaseCommon, Form + + +class TestHrExpensePayToVendor(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner_obj = cls.env["res.partner"] + cls.payment_obj = cls.env["account.payment"] + cls.journal_obj = cls.env["account.journal"] + cls.sheet_obj = cls.env["hr.expense.sheet"] + cls.expense_obj = cls.env["hr.expense"] + cls.account_payment_register_obj = cls.env["account.payment.register"] + + cls.main_company = company = cls.env.ref("base.main_company") + cls.employee_admin = cls.env.ref("hr.employee_admin") + cls.product_no_cost = cls.env.ref("hr_expense.product_product_no_cost") + + cls.vendor = cls.partner_obj.create({"name": "Test Vendor"}) + cls.vendor2 = cls.partner_obj.create({"name": "Test Vendor2"}) + cls.payment_journal = cls.journal_obj.search( + [("type", "in", ["cash", "bank"])], limit=1 + ) + + cls.expense_journal = cls.journal_obj.create( + { + "name": "Purchase Journal - Test", + "code": "HRTPJ", + "type": "purchase", + "company_id": company.id, + } + ) + + def _get_payment_wizard(self, expense_sheet): + action = expense_sheet.action_register_payment() + ctx = action.get("context") + with Form( + self.account_payment_register_obj.with_context(**ctx), + view="account.view_account_payment_register_form", + ) as f: + f.journal_id = self.payment_journal + f.amount = self.expense_sheet.total_amount + register_payment = f.save() + return register_payment + + def test_expense_pay_to_vendor(self): + """When expense is set to pay to vendor, I expect, + - After post journal entries, all journal items will use partner_id = vendor + - After make payment, all journal items will use partner_id = vendor + """ + self.expense_sheet = self.sheet_obj.create( + { + "employee_id": self.employee_admin.id, + "name": "Expense test", + "journal_id": self.expense_journal.id, + } + ) + self.expenses = self.expense_obj.create( + [ + { + "name": "Expense Line 1", + "employee_id": self.employee_admin.id, + "product_id": self.product_no_cost.id, + "total_amount": 10, + "sheet_id": self.expense_sheet.id, + "payment_mode": "company_account", + "vendor_id": self.vendor.id, + }, + { + "name": "Expense Line 1", + "employee_id": self.employee_admin.id, + "product_id": self.product_no_cost.id, + "total_amount": 20, + "sheet_id": self.expense_sheet.id, + "payment_mode": "company_account", + "vendor_id": self.vendor.id, + }, + ] + ) + self.assertEqual(self.expense_sheet.payment_mode, "company_account") + self.assertEqual( + list(set(self.expense_sheet.expense_line_ids.mapped("payment_mode"))), + ["company_account"], + ) + # Test create new expense diff vendor + with self.assertRaises(UserError): + self.expense_obj.create( + [ + { + "name": "Expense Line 1", + "employee_id": self.employee_admin.id, + "product_id": self.product_no_cost.id, + "unit_amount": 1, + "quantity": 10, + "sheet_id": self.expense_sheet.id, + "payment_mode": "company_account", + "vendor_id": self.vendor2.id, + }, + ] + ) + # Post Journl Entry + self.expense_sheet.action_submit_sheet() + self.expense_sheet.approve_expense_sheets() + self.expense_sheet.action_sheet_move_create() + expense_move = self.expense_sheet.account_move_id + vendor_name = expense_move.line_ids.mapped("partner_id.name")[0] + self.assertEqual(vendor_name, "Test Vendor") + # Make payment + payment_wizard = self._get_payment_wizard(self.expense_sheet) + payment_wizard.action_create_payments() + # Payment move, should also use partner_id = vendor + reconcile_moves = self.expense_sheet.account_move_id.line_ids.mapped( + "full_reconcile_id.reconciled_line_ids.move_id" + ) + payment_move = reconcile_moves - expense_move + vendor_name = payment_move.line_ids.mapped("partner_id.name")[0] + self.assertEqual(vendor_name, "Test Vendor") diff --git a/hr_expense_pay_to_vendor/views/hr_expense_views.xml b/hr_expense_pay_to_vendor/views/hr_expense_views.xml new file mode 100644 index 000000000..4ac4eeee1 --- /dev/null +++ b/hr_expense_pay_to_vendor/views/hr_expense_views.xml @@ -0,0 +1,35 @@ + + + hr.expense.sheet.form.inherit + hr.expense.sheet + + + + + + + + + + hr.expense.view.form + hr.expense + + + +
+
+
+
+
+