forked from OCA/hr-expense
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
794 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,82 @@ | ||
================== | ||
HR Expense Payment | ||
================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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--expense-lightgray.png?logo=github | ||
:target: https://github.com/OCA/hr-expense/tree/14.0/hr_expense_payment | ||
: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_payment | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/289/14.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allow payment link to expense. | ||
After you register payment on expense sheet, it will link between expense sheet and payment. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
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 smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/hr-expense/issues/new?body=module:%20hr_expense_payment%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 | ||
~~~~~~~ | ||
|
||
* Ecosoft | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* 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-Saran440| image:: https://github.com/Saran440.png?size=40px | ||
:target: https://github.com/Saran440 | ||
:alt: Saran440 | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-Saran440| | ||
|
||
This module is part of the `OCA/hr-expense <https://github.com/OCA/hr-expense/tree/14.0/hr_expense_payment>`_ 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). | ||
|
||
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,16 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "HR Expense Payment", | ||
"version": "14.0.1.0.0", | ||
"category": "Human Resources", | ||
"author": "Tecnativa, Ecosoft, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/hr-expense", | ||
"depends": ["hr_expense"], | ||
"data": [], | ||
"installable": True, | ||
"post_init_hook": "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,19 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import SUPERUSER_ID, api | ||
|
||
|
||
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, {}) | ||
sheets = env["hr.expense.sheet"].search([("payment_mode", "=", "own_account")]) | ||
for sheet in sheets: | ||
amls = sheet.account_move_id.mapped("line_ids") | ||
reconcile = amls.mapped("full_reconcile_id") | ||
aml_payment = reconcile.mapped("reconciled_line_ids").filtered( | ||
lambda r: r not in amls | ||
) | ||
payment = aml_payment.mapped("payment_id") | ||
payment.write({"expense_sheet_ids": sheet.ids}) |
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). | ||
|
||
from . import account_payment | ||
from . import hr_expense | ||
from . import hr_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,19 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class AccountPayment(models.Model): | ||
_inherit = "account.payment" | ||
|
||
expense_sheet_ids = fields.Many2many( | ||
comodel_name="hr.expense.sheet", | ||
relation="payment_expense_sheet_rel", | ||
column1="payment_id", | ||
column2="sheet_id", | ||
string="Expense sheet", | ||
readonly=True, | ||
copy=False, | ||
) |
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 (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import models | ||
|
||
|
||
class HrExpense(models.Model): | ||
_inherit = "hr.expense" | ||
|
||
def _prepare_payment_expense_company( | ||
self, | ||
payment_methods, | ||
journal, | ||
different_currency, | ||
journal_currency, | ||
total_amount_currency, | ||
): | ||
self.ensure_one() | ||
commercial_partner_id = ( | ||
self.employee_id.sudo().address_home_id.commercial_partner_id | ||
) | ||
payment_dict = { | ||
"date": self.date, | ||
"amount": total_amount_currency, | ||
"payment_type": "outbound", | ||
"partner_type": "supplier", | ||
"ref": self.name, | ||
"journal_id": journal.id, | ||
"currency_id": self.currency_id.id | ||
if different_currency | ||
else journal_currency.id, | ||
"partner_id": commercial_partner_id.id, | ||
"payment_method_id": payment_methods and payment_methods[0].id or False, | ||
"expense_sheet_ids": self.sheet_id.ids, | ||
} | ||
return payment_dict | ||
|
||
def action_move_create(self): | ||
move_group_by_sheet = super().action_move_create() | ||
payment_list = [] | ||
for expense in self: | ||
if expense.payment_mode == "company_account": | ||
total_amount_currency = expense.total_amount | ||
different_currency = ( | ||
expense.currency_id != expense.company_id.currency_id | ||
) | ||
journal = expense.sheet_id.bank_journal_id | ||
journal_currency = journal.currency_id or journal.company_id.currency_id | ||
payment_methods = journal.outbound_payment_method_ids | ||
# prepare payment dict value for case paid by company | ||
payment_dict = expense._prepare_payment_expense_company( | ||
payment_methods, | ||
journal, | ||
different_currency, | ||
journal_currency, | ||
total_amount_currency, | ||
) | ||
payment_list.append(payment_dict) | ||
# create payment and auto post from expense paid by company | ||
if payment_list: | ||
payment = self.env["account.payment"].create(payment_list) | ||
payment.action_post() | ||
return move_group_by_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,26 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class HrExpenseSheet(models.Model): | ||
_inherit = "hr.expense.sheet" | ||
|
||
payment_ids = fields.Many2many( | ||
comodel_name="account.payment", | ||
relation="payment_expense_sheet_rel", | ||
column1="sheet_id", | ||
column2="payment_id", | ||
string="Payment", | ||
readonly=True, | ||
copy=False, | ||
) | ||
|
||
def action_register_payment(self): | ||
""" Send context when you register payment from expense sheet """ | ||
action = super().action_register_payment() | ||
if self._name == "hr.expense.sheet": | ||
action["context"].update({"expense_sheet_ids": self.ids}) | ||
return action |
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 @@ | ||
* Saran Lim. <[email protected]> |
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,2 @@ | ||
This module allow payment link to expense. | ||
After you register payment on expense sheet, it will link between expense sheet and payment. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.