Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] hr_expense_tax_adjust #253

Open
wants to merge 11 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions hr_expense_tax_adjust/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
======================
Expense Tax Adjustment
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a785a390676dac18532d6f1ca10c9d570c7b48536f299fa053dc7358a1961c01
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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/16.0/hr_expense_tax_adjust
: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-16-0/hr-expense-16-0-hr_expense_tax_adjust
: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=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows users to edit taxes on the Expense to ensure accurate accounting entries in case of rounding differences.
Users must have the "Show Accounting Features - Readonly" access rights to edit the necessary fields for tax adjustment.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you can follow these steps:

#. Go to *Expenses > My Expenses > My Expenses > Create*.
#. Choose a product from the list and add applicable taxes.
#. If the calculated price tax is incorrect, edit the value by check "Adj." to reflect the correct amount.
#. Follow the normal process for submitting and posting the journal entry.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-expense/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 <https://github.com/OCA/hr-expense/issues/new?body=module:%20hr_expense_tax_adjust%0Aversion:%2016.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
~~~~~~~

* Ecosoft

Contributors
~~~~~~~~~~~~

* `Ecosoft <http://ecosoft.co.th>`__:

* Pimolnat Suntian <[email protected]>
* Saran Lim. <[email protected]>

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-ps-tubtim| image:: https://github.com/ps-tubtim.png?size=40px
:target: https://github.com/ps-tubtim
:alt: ps-tubtim

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ps-tubtim|

This module is part of the `OCA/hr-expense <https://github.com/OCA/hr-expense/tree/16.0/hr_expense_tax_adjust>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions hr_expense_tax_adjust/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
17 changes: 17 additions & 0 deletions hr_expense_tax_adjust/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Expense Tax Adjustment",
"version": "16.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"summary": "Allow to edit tax amount on expenses",
"website": "https://github.com/OCA/hr-expense",
"license": "AGPL-3",
"depends": ["hr_expense"],
"category": "Human Resources/Expenses",
"data": ["views/hr_expense_views.xml"],
"installable": True,
"maintainers": ["ps-tubtim"],
"development_status": "Alpha",
}
34 changes: 34 additions & 0 deletions hr_expense_tax_adjust/i18n/hr_expense_tax_adjust.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_expense_tax_adjust
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.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_tax_adjust
#: model:ir.model,name:hr_expense_tax_adjust.model_hr_expense
msgid "Expense"
msgstr ""

#. module: hr_expense_tax_adjust
#: model:ir.model.fields,field_description:hr_expense_tax_adjust.field_hr_expense__price_tax
msgid "Price Tax"
msgstr ""

#. module: hr_expense_tax_adjust
#: model:ir.model.fields,field_description:hr_expense_tax_adjust.field_hr_expense__tax_adjust
msgid "Tax Adjust"
msgstr ""

#. module: hr_expense_tax_adjust
#: model:ir.model.fields,help:hr_expense_tax_adjust.field_hr_expense__tax_adjust
msgid "trigger line with adjust tax"
msgstr ""
37 changes: 37 additions & 0 deletions hr_expense_tax_adjust/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_expense_tax_adjust
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-02-16 18:34+0000\n"
"Last-Translator: mymage <[email protected]>\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_tax_adjust
#: model:ir.model,name:hr_expense_tax_adjust.model_hr_expense
msgid "Expense"
msgstr "Spesa"

#. module: hr_expense_tax_adjust
#: model:ir.model.fields,field_description:hr_expense_tax_adjust.field_hr_expense__price_tax
msgid "Price Tax"
msgstr "Valorizzare imposta"

#. module: hr_expense_tax_adjust
#: model:ir.model.fields,field_description:hr_expense_tax_adjust.field_hr_expense__tax_adjust
msgid "Tax Adjust"
msgstr "Aggiustamento imposta"

#. module: hr_expense_tax_adjust
#: model:ir.model.fields,help:hr_expense_tax_adjust.field_hr_expense__tax_adjust
msgid "trigger line with adjust tax"
msgstr "attiva riga con imposta aggiustamento"
5 changes: 5 additions & 0 deletions hr_expense_tax_adjust/models/__init__.py
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).

from . import hr_expense
from . import account_move_line
from . import account_tax
23 changes: 23 additions & 0 deletions hr_expense_tax_adjust/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from odoo import api, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.depends("quantity", "discount", "price_unit", "tax_ids", "currency_id")
def _compute_totals(self):
"""Update amount untaxed for tax adjust expense"""
ml_expense = self.filtered(lambda l: l.expense_id.tax_adjust)
res = super()._compute_totals()
for line in ml_expense:
expense = line.expense_id
if line.tax_line_id:
line.tax_base_amount = (
expense.total_amount_company - expense.amount_tax_company
)
line.amount_currency = expense.amount_tax_company
else:
line.price_subtotal = (
expense.total_amount_company - expense.amount_tax_company
)
return res
20 changes: 20 additions & 0 deletions hr_expense_tax_adjust/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import api, models


class AccountTax(models.Model):
_inherit = "account.tax"

@api.model
def _prepare_tax_totals(self, base_lines, currency, tax_lines=None):
"""Update amount untaxed for tax adjust expense"""
res = super()._prepare_tax_totals(base_lines, currency, tax_lines)
amount_untaxed = 0.0
for base_line in base_lines:
expense = base_line["record"].expense_id
if expense.tax_adjust:
amount_untaxed += (

Check warning on line 15 in hr_expense_tax_adjust/models/account_tax.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_tax_adjust/models/account_tax.py#L15

Added line #L15 was not covered by tests
expense.total_amount_company - expense.amount_tax_company
)
if amount_untaxed:
res["amount_untaxed"] = amount_untaxed

Check warning on line 19 in hr_expense_tax_adjust/models/account_tax.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_tax_adjust/models/account_tax.py#L19

Added line #L19 was not covered by tests
return res
70 changes: 70 additions & 0 deletions hr_expense_tax_adjust/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class HrExpense(models.Model):
_inherit = "hr.expense"

tax_adjust = fields.Boolean(
copy=False,
help="trigger line with adjust tax",
)

@api.depends(
"currency_rate",
"total_amount",
"tax_ids",
"product_id",
"employee_id.user_id.partner_id",
"quantity",
"amount_tax_company",
)
def _compute_total_amount_company(self):
"""Update amount_tax when adjust tax"""
expense_tax_adjust = self.filtered(lambda l: l.tax_adjust)
res = super(
HrExpense, self - expense_tax_adjust
)._compute_total_amount_company()
for expense in expense_tax_adjust:
base_lines = [
expense._convert_to_tax_base_line_dict(
price_unit=expense.total_amount * expense.currency_rate,
currency=expense.company_currency_id,
)
]
taxes_totals = self.env["account.tax"]._compute_taxes(base_lines)["totals"][
expense.company_currency_id
]
expense.total_amount_company = (
taxes_totals["amount_untaxed"] + taxes_totals["amount_tax"]
)
# Use same as adjust tax
if expense.same_currency:
amount_tax_company = expense.amount_tax
# Convert amount_tax to company currency
else:
amount_tax_company = expense.currency_id._convert(
expense.amount_tax,
expense.company_id.currency_id,
expense.company_id,
expense.date,
)
expense.amount_tax_company = amount_tax_company
return res

@api.depends("total_amount", "tax_ids", "currency_id")
def _compute_amount_tax(self):
"""Do not update amount_tax when adjust tax"""
expense_tax_adjust = self.filtered(lambda l: l.tax_adjust)
res = super(HrExpense, self - expense_tax_adjust)._compute_amount_tax()
for expense in expense_tax_adjust:
base_lines = [
expense._convert_to_tax_base_line_dict(price_unit=expense.total_amount)
]
taxes_totals = self.env["account.tax"]._compute_taxes(base_lines)["totals"][
expense.currency_id
]
expense.untaxed_amount = taxes_totals["amount_untaxed"]
return res
4 changes: 4 additions & 0 deletions hr_expense_tax_adjust/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Ecosoft <http://ecosoft.co.th>`__:

* Pimolnat Suntian <[email protected]>
* Saran Lim. <[email protected]>
2 changes: 2 additions & 0 deletions hr_expense_tax_adjust/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows users to edit taxes on the Expense to ensure accurate accounting entries in case of rounding differences.
Users must have the "Show Accounting Features - Readonly" access rights to edit the necessary fields for tax adjustment.
6 changes: 6 additions & 0 deletions hr_expense_tax_adjust/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this module, you can follow these steps:

#. Go to *Expenses > My Expenses > My Expenses > Create*.
#. Choose a product from the list and add applicable taxes.
#. If the calculated price tax is incorrect, edit the value by check "Adj." to reflect the correct amount.
#. Follow the normal process for submitting and posting the journal entry.
Binary file added hr_expense_tax_adjust/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading