Skip to content

Commit 3a60094

Browse files
committed
[ADD] hr_expense_cash_basis
1 parent 243cd17 commit 3a60094

File tree

8 files changed

+164
-0
lines changed

8 files changed

+164
-0
lines changed

hr_expense_cash_basis/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from . import models

hr_expense_cash_basis/__manifest__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "HR Expense - Cash Basis",
6+
"version": "15.0.1.0.0",
7+
"license": "AGPL-3",
8+
"category": "Tools",
9+
"website": "https://github.com/ecosoft-odoo/ecosoft-addons",
10+
"author": "Ecosoft, Odoo Community Association (OCA)",
11+
"depends": ["hr_expense"],
12+
"data": [],
13+
"installable": True,
14+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from . import account_partial_reconcile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
from odoo import _, models
2+
from odoo.exceptions import UserError
3+
4+
5+
class AccountPartialReconcile(models.Model):
6+
_inherit = "account.partial.reconcile"
7+
8+
def _collect_tax_cash_basis_values(self):
9+
"""OVERWRITE core function odoo to support cash basis from expense
10+
Core Odoo
11+
Expense Sheet:
12+
EX1 20.0 Undue Vat7%
13+
EX2 30.0 Undue Vat7%
14+
EX3 40.0
15+
When register payment, it will create cash basis
16+
following lines of expense sheet and allocated with percent.
17+
Fix module:
18+
When register payment, it will create cash basis
19+
following lines of undue vat expense sheet
20+
"""
21+
tax_cash_basis_values_per_move = {}
22+
23+
if not self:
24+
return {}
25+
26+
total_cash_basis = 0.0
27+
for partial in self:
28+
if partial.credit_move_id.expense_id and any(
29+
x.tax_exigibility == "on_payment"
30+
for x in partial.credit_move_id.expense_id.tax_ids
31+
):
32+
total_cash_basis += partial.amount
33+
34+
for partial in self:
35+
if partial.credit_move_id.expense_id and not any(
36+
x.tax_exigibility == "on_payment"
37+
for x in partial.credit_move_id.expense_id.tax_ids
38+
):
39+
continue
40+
41+
for move in {partial.debit_move_id.move_id, partial.credit_move_id.move_id}:
42+
43+
# Collect data about cash basis.
44+
if move.id not in tax_cash_basis_values_per_move:
45+
tax_cash_basis_values_per_move[
46+
move.id
47+
] = move._collect_tax_cash_basis_values()
48+
49+
# Nothing to process on the move.
50+
if not tax_cash_basis_values_per_move.get(move.id):
51+
continue
52+
move_values = tax_cash_basis_values_per_move[move.id]
53+
54+
# Check the cash basis configuration only when at least one cash basis tax entry need to be created.
55+
journal = partial.company_id.tax_cash_basis_journal_id
56+
57+
if not journal:
58+
raise UserError(
59+
_(
60+
"There is no tax cash basis journal defined for the '%s' company.\n"
61+
"Configure it in Accounting/Configuration/Settings"
62+
)
63+
% partial.company_id.display_name
64+
)
65+
66+
partial_amount = 0.0
67+
partial_amount_currency = 0.0
68+
rate_amount = 0.0
69+
rate_amount_currency = 0.0
70+
71+
if partial.debit_move_id.move_id == move:
72+
partial_amount += partial.amount
73+
partial_amount_currency += partial.debit_amount_currency
74+
rate_amount -= partial.credit_move_id.balance
75+
rate_amount_currency -= partial.credit_move_id.amount_currency
76+
source_line = partial.debit_move_id
77+
counterpart_line = partial.credit_move_id
78+
79+
if partial.credit_move_id.move_id == move:
80+
partial_amount += partial.amount
81+
partial_amount_currency += partial.credit_amount_currency
82+
rate_amount += partial.debit_move_id.balance
83+
rate_amount_currency += partial.debit_move_id.amount_currency
84+
source_line = partial.credit_move_id
85+
counterpart_line = partial.debit_move_id
86+
87+
if partial.debit_move_id.move_id.is_invoice(
88+
include_receipts=True
89+
) and partial.credit_move_id.move_id.is_invoice(include_receipts=True):
90+
# Will match when reconciling a refund with an invoice.
91+
# In this case, we want to use the rate of each businness document to compute its cash basis entry,
92+
# not the rate of what it's reconciled with.
93+
rate_amount = source_line.balance
94+
rate_amount_currency = source_line.amount_currency
95+
payment_date = move.date
96+
else:
97+
payment_date = counterpart_line.date
98+
99+
if move_values["currency"] == move.company_id.currency_id:
100+
if not total_cash_basis:
101+
total_cash_basis = 1
102+
# Percentage made on company's currency.
103+
percentage = partial_amount / total_cash_basis
104+
else:
105+
# Percentage made on foreign currency.
106+
percentage = (
107+
partial_amount_currency / move_values["total_amount_currency"]
108+
)
109+
110+
if source_line.currency_id != counterpart_line.currency_id:
111+
# When the invoice and the payment are not sharing the same foreign currency, the rate is computed
112+
# on-the-fly using the payment date.
113+
payment_rate = self.env["res.currency"]._get_conversion_rate(
114+
counterpart_line.company_currency_id,
115+
source_line.currency_id,
116+
counterpart_line.company_id,
117+
payment_date,
118+
)
119+
elif rate_amount:
120+
payment_rate = rate_amount_currency / rate_amount
121+
else:
122+
payment_rate = 0.0
123+
124+
partial_vals = {
125+
"partial": partial,
126+
"percentage": percentage,
127+
"payment_rate": payment_rate,
128+
}
129+
130+
# Add partials.
131+
move_values.setdefault("partials", [])
132+
move_values["partials"].append(partial_vals)
133+
134+
# Clean-up moves having nothing to process.
135+
return {k: v for k, v in tax_cash_basis_values_per_move.items() if v}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Saran Lim. <[email protected]>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module fixed cash basis on expense
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../hr_expense_cash_basis

setup/hr_expense_cash_basis/setup.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)