Skip to content

Commit

Permalink
Merge PR #262 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Sep 4, 2024
2 parents 66db007 + c7f7d5d commit fca7902
Show file tree
Hide file tree
Showing 16 changed files with 747 additions and 0 deletions.
84 changes: 84 additions & 0 deletions hr_expense_due_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
===================
HR Expense Due Date
===================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:93dbbc28eb90d1c10a426eb00d2efffd225c7c5eac900e82b0d184efee6cba8c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/14.0/hr_expense_due_date
: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-14-0/hr-expense-14-0-hr_expense_due_date
: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=14.0
:alt: Try me on Runboat

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

This module enhances the Expense Sheet model by allowing flexible due date definitions through payment terms or fixed dates.

**Table of contents**

.. contents::
:local:

Usage
=====

On the Expense Sheet, you can define the due date on the "Other Info" page. You can either specify a fixed date or use a payment term to set the due date.

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_due_date%0Aversion:%2014.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
~~~~~~~

* Escodoo

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

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <[email protected]>
* Kaynnan Lemes <[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.

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions hr_expense_due_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions hr_expense_due_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "HR Expense Due Date",
"summary": """
Dedicated due date used for HR Expense Sheet""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-expense",
"depends": [
"hr_expense",
],
"data": [
"views/hr_expense_sheet.xml",
],
}
2 changes: 2 additions & 0 deletions hr_expense_due_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_expense
from . import hr_expense_sheet
57 changes: 57 additions & 0 deletions hr_expense_due_date/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

def _get_account_move_line_values(self):
move_line_values_by_expense = super()._get_account_move_line_values()

for expense_id, move_line_values in move_line_values_by_expense.items():
expense = self.browse(expense_id)
if expense.sheet_id.payment_term_id:
self._apply_payment_terms(expense, move_line_values)
else:
self._apply_due_date(expense, move_line_values)

return move_line_values_by_expense

def _apply_payment_terms(self, expense, move_line_values):
# Locate and remove the original payable line
payable_line = next(
(line for line in move_line_values if line.get("date_maturity")), None
)
if payable_line:
move_line_values.remove(payable_line)

# Generate new lines based on payment terms
payment_terms = self._prepare_payment_terms(expense, move_line_values)

term_index = 0
for due_date, amount in payment_terms:
new_line = payable_line.copy()
new_line["date_maturity"] = due_date
new_line["debit"] = 0.0
new_line["credit"] = amount
move_line_values.append(new_line)
term_index += 1

def _prepare_payment_terms(self, expense, move_line_values):
total_amount = sum(line["debit"] - line["credit"] for line in move_line_values)
payment_terms = expense.sheet_id.payment_term_id.compute(
value=total_amount,
date_ref=expense.sheet_id.accounting_date
or fields.Date.context_today(expense),
currency=self.company_id.currency_id or self.env.company.currency_id,
)
return payment_terms

def _apply_due_date(self, expense, move_line_values):
for move_line in move_line_values:
if move_line.get("date_maturity"):
move_line["date_maturity"] = (
expense.sheet_id.due_date or move_line["date_maturity"]
)
21 changes: 21 additions & 0 deletions hr_expense_due_date/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo import fields, models

_logger = logging.getLogger(__name__)


class HrExpenseSheet(models.Model):

_inherit = "hr.expense.sheet"

payment_term_id = fields.Many2one(
"account.payment.term",
company_dependent=True,
string="Payment Terms",
domain="[('company_id', 'in', [current_company_id, False])]",
)
due_date = fields.Date(string="Due Date")
4 changes: 4 additions & 0 deletions hr_expense_due_date/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <[email protected]>
* Kaynnan Lemes <[email protected]>
1 change: 1 addition & 0 deletions hr_expense_due_date/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module enhances the Expense Sheet model by allowing flexible due date definitions through payment terms or fixed dates.
1 change: 1 addition & 0 deletions hr_expense_due_date/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On the Expense Sheet, you can define the due date on the "Other Info" page. You can either specify a fixed date or use a payment term to set the due date.
Binary file added hr_expense_due_date/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

0 comments on commit fca7902

Please sign in to comment.