Skip to content

Commit 113e0fa

Browse files
committed
[MIG] hr_expense_advance_clearing: Migration to 18.0
1 parent 8fdce63 commit 113e0fa

File tree

6 files changed

+58
-109
lines changed

6 files changed

+58
-109
lines changed

hr_expense_advance_clearing/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "Employee Advance and Clearing",
6-
"version": "17.0.1.0.0",
6+
"version": "18.0.1.0.0",
77
"category": "Human Resources",
88
"author": "Ecosoft, Odoo Community Association (OCA)",
99
"license": "AGPL-3",

hr_expense_advance_clearing/models/account_move.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ def _reverse_moves(self, default_values_list=None, cancel=False):
3838
)
3939

4040
@api.depends(
41-
"line_ids.matched_debit_ids.debit_move_id.move_id.payment_id.is_matched",
42-
"line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual",
43-
"line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual_currency",
44-
"line_ids.matched_credit_ids.credit_move_id.move_id.payment_id.is_matched",
45-
"line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual",
46-
"line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual_currency",
47-
"line_ids.balance",
48-
"line_ids.currency_id",
49-
"line_ids.amount_currency",
50-
"line_ids.amount_residual",
51-
"line_ids.amount_residual_currency",
52-
"line_ids.payment_id.state",
53-
"line_ids.full_reconcile_id",
54-
"state",
41+
'line_ids.matched_debit_ids.debit_move_id.move_id.origin_payment_id.is_matched',
42+
'line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual',
43+
'line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual_currency',
44+
'line_ids.matched_credit_ids.credit_move_id.move_id.origin_payment_id.is_matched',
45+
'line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual',
46+
'line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual_currency',
47+
'line_ids.balance',
48+
'line_ids.currency_id',
49+
'line_ids.amount_currency',
50+
'line_ids.amount_residual',
51+
'line_ids.amount_residual_currency',
52+
'line_ids.payment_id.state',
53+
'line_ids.full_reconcile_id',
54+
'state'
5555
)
5656
def _compute_amount(self):
5757
"""Compute amount residual for advance clearing case."""

hr_expense_advance_clearing/models/hr_expense_sheet.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _compute_clearing_residual(self):
8585
property_account_expense_id = emp_advance.with_company(
8686
sheet.company_id
8787
).property_account_expense_id
88-
for line in sheet.sudo().account_move_id.line_ids:
88+
for line in sheet.sudo().account_move_ids.line_ids:
8989
if line.account_id == property_account_expense_id:
9090
residual_company += line.amount_residual
9191
sheet.clearing_residual = residual_company
@@ -101,8 +101,9 @@ def _compute_clearing_count(self):
101101
for sheet in self:
102102
sheet.clearing_count = len(sheet.clearing_sheet_ids)
103103

104-
def action_sheet_move_create(self):
105-
res = super().action_sheet_move_create()
104+
def action_sheet_move_post(self):
105+
"""Post journal entries with clearing document"""
106+
res = super().action_sheet_move_post()
106107
for sheet in self:
107108
if not sheet.advance_sheet_id:
108109
continue
@@ -301,7 +302,7 @@ def action_open_clearings(self):
301302
"name": _("Clearing Sheets"),
302303
"type": "ir.actions.act_window",
303304
"res_model": "hr.expense.sheet",
304-
"view_mode": "tree,form",
305+
"view_mode": "list,form",
305306
"domain": [("id", "in", self.clearing_sheet_ids.ids)],
306307
}
307308

hr_expense_advance_clearing/tests/test_hr_expense_advance_clearing.py

+13-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from odoo import fields
66
from odoo.exceptions import UserError, ValidationError
7-
from odoo.tests.common import Form, tagged
7+
from odoo.tests import Form, tagged
88
from odoo.tools import mute_logger
99

1010
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
@@ -13,9 +13,9 @@
1313
@tagged("-at_install", "post_install")
1414
class TestHrExpenseAdvanceClearing(TestExpenseCommon):
1515
@classmethod
16-
def setUpClass(cls, chart_template_ref=None):
17-
super().setUpClass(chart_template_ref=chart_template_ref)
18-
advance_account = cls.company_data["default_account_assets"]
16+
def setUpClass(cls):
17+
super().setUpClass()
18+
advance_account = cls.company_data["default_account_deferred_expense"]
1919
advance_account.reconcile = True
2020
cls.emp_advance = cls.env.ref("hr_expense_advance_clearing.product_emp_advance")
2121
cls.emp_advance.property_account_expense_id = advance_account
@@ -171,7 +171,7 @@ def test_1_clear_equal_advance(self):
171171
# ------------------ Advance --------------------------
172172
self.advance.action_submit_sheet()
173173
self.advance.action_approve_expense_sheets()
174-
self.advance.action_sheet_move_create()
174+
self.advance.action_sheet_move_post()
175175
self.assertEqual(self.advance.clearing_residual, 1000.0)
176176
self._register_payment(self.advance.account_move_ids, 1000.0)
177177
self.assertEqual(self.advance.state, "done")
@@ -184,16 +184,16 @@ def test_1_clear_equal_advance(self):
184184
self.assertEqual(self.clearing_equal.advance_sheet_residual, 1000.0)
185185
self.clearing_equal.action_submit_sheet()
186186
self.clearing_equal.action_approve_expense_sheets()
187-
self.clearing_equal.action_sheet_move_create()
187+
self.clearing_equal.action_sheet_move_post()
188188
# Equal amount, state change to Paid and advance is cleared
189189
self.assertEqual(self.clearing_equal.state, "done")
190190
self.assertEqual(self.clearing_equal.advance_sheet_residual, 0.0)
191191
# Clear this with previous advance is done
192192
self.clearing_more.advance_sheet_id = self.advance
193193
self.clearing_more.action_submit_sheet()
194-
self.clearing_more.action_approve_expense_sheets()
194+
# Can't approved clearing, because advance residual is 0.0
195195
with self.assertRaises(ValidationError):
196-
self.clearing_more.action_sheet_move_create()
196+
self.clearing_more.action_approve_expense_sheets()
197197
# There are 2 clearing in advance
198198
self.assertEqual(self.advance.clearing_count, 2)
199199
# Check link clearing in advance must be equal clearing count
@@ -221,7 +221,7 @@ def test_2_clear_more_than_advance(self):
221221
# ------------------ Advance --------------------------
222222
self.advance.action_submit_sheet()
223223
self.advance.action_approve_expense_sheets()
224-
self.advance.action_sheet_move_create()
224+
self.advance.action_sheet_move_post()
225225
self.assertEqual(self.advance.clearing_residual, 1000.0)
226226
self._register_payment(self.advance.account_move_ids, 1000.0)
227227
self.assertEqual(self.advance.state, "done")
@@ -231,7 +231,7 @@ def test_2_clear_more_than_advance(self):
231231
self.assertEqual(self.clearing_more.advance_sheet_residual, 1000.0)
232232
self.clearing_more.action_submit_sheet()
233233
self.clearing_more.action_approve_expense_sheets()
234-
self.clearing_more.action_sheet_move_create()
234+
self.clearing_more.action_sheet_move_post()
235235
# More amount, state not changed to paid, and has to pay 200 more
236236
self.assertEqual(self.clearing_more.state, "post")
237237
self.assertEqual(self.clearing_more.amount_payable, 200.0)
@@ -244,13 +244,7 @@ def test_3_clear_less_than_advance(self):
244244
# ------------------ Advance --------------------------
245245
self.advance.action_submit_sheet()
246246
self.advance.action_approve_expense_sheets()
247-
self.advance.action_sheet_move_create()
248-
# Test return advance register payment with move state draft
249-
with self.assertRaises(UserError):
250-
self.advance.account_move_ids.button_draft()
251-
self._register_payment(
252-
self.advance.account_move_ids, 200.0, hr_return_advance=True
253-
)
247+
self.advance.action_sheet_move_post()
254248
self.assertEqual(self.advance.clearing_residual, 1000.0)
255249
self._register_payment(self.advance.account_move_ids, 1000.0)
256250
self.assertEqual(self.advance.state, "done")
@@ -276,7 +270,7 @@ def test_3_clear_less_than_advance(self):
276270
ctx=register_payment["context"],
277271
hr_return_advance=True,
278272
)
279-
self.clearing_less.action_sheet_move_create()
273+
self.clearing_less.action_sheet_move_post()
280274
# Less amount, state set to done. Still remain 200 to be returned
281275
self.assertEqual(self.clearing_less.state, "done")
282276
self.assertEqual(self.clearing_less.advance_sheet_residual, 200.0)
@@ -301,7 +295,7 @@ def test_4_clearing_product_advance(self):
301295
self.advance.expense_line_ids.clearing_product_id = self.product_a
302296
self.advance.action_submit_sheet()
303297
self.advance.action_approve_expense_sheets()
304-
self.advance.action_sheet_move_create()
298+
self.advance.action_sheet_move_post()
305299
self.assertEqual(self.advance.clearing_residual, 1000.0)
306300
self._register_payment(self.advance.account_move_ids, 1000.0)
307301
self.assertEqual(self.advance.state, "done")

hr_expense_advance_clearing/views/hr_expense_views.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<record id="action_my_hr_advance_sheet" model="ir.actions.act_window">
66
<field name="name">Advances</field>
77
<field name="res_model">hr.expense.sheet</field>
8-
<field name="view_mode">tree,kanban,form,pivot,graph,activity</field>
8+
<field name="view_mode">list,kanban,form,pivot,graph,activity</field>
99
<field name="search_view_id" ref="hr_expense.hr_expense_sheet_view_search" />
1010
<field name="domain">[('state', '!=', 'cancel'), ('advance', '=', True)]</field>
1111
<field
@@ -23,7 +23,7 @@
2323
<record id="action_my_hr_expense_sheet" model="ir.actions.act_window">
2424
<field name="name">Expenses</field>
2525
<field name="res_model">hr.expense.sheet</field>
26-
<field name="view_mode">tree,kanban,form,pivot,graph,activity</field>
26+
<field name="view_mode">list,kanban,form,pivot,graph,activity</field>
2727
<field name="search_view_id" ref="hr_expense.hr_expense_sheet_view_search" />
2828
<field
2929
name="domain"
@@ -145,8 +145,8 @@
145145
</field>
146146
</field>
147147
</record>
148-
<record id="view_hr_expense_sheet_tree" model="ir.ui.view">
149-
<field name="name">hr.expense.sheet.tree</field>
148+
<record id="view_hr_expense_sheet_list" model="ir.ui.view">
149+
<field name="name">hr.expense.sheet.list</field>
150150
<field name="model">hr.expense.sheet</field>
151151
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_tree" />
152152
<field name="arch" type="xml">
@@ -206,7 +206,7 @@
206206
</group>
207207
</xpath>
208208
<xpath
209-
expr="//field[@name='expense_line_ids']/tree/field[@name='name']"
209+
expr="//field[@name='expense_line_ids']/list/field[@name='name']"
210210
position="after"
211211
>
212212
<field name="employee_id" invisible="1" />
@@ -231,7 +231,7 @@
231231
<attribute name="force_save">True</attribute>
232232
</xpath>
233233
<xpath
234-
expr="//field[@name='expense_line_ids']/tree/field[@name='price_unit']"
234+
expr="//field[@name='expense_line_ids']/list/field[@name='price_unit']"
235235
position="attributes"
236236
>
237237
<attribute name="force_save">True</attribute>

hr_expense_advance_clearing/wizard/account_payment_register.py

+19-65
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
class AccountPaymentRegister(models.TransientModel):
1212
_inherit = "account.payment.register"
1313

14-
def _get_product_advance(self):
15-
return self.env.ref("hr_expense_advance_clearing.product_emp_advance", False)
16-
1714
def _validate_over_return(self):
1815
"""Actual remaining = amount to clear - clear pending
1916
and it is not legit to return more than remaining"""
@@ -44,66 +41,23 @@ def _validate_over_return(self):
4441
}
4542
)
4643

47-
def action_create_payments(self):
48-
if self._context.get("hr_return_advance", False):
44+
def _init_payments(self, to_process, edit_mode=False):
45+
if self.env.context.get("hr_return_advance"):
4946
self._validate_over_return()
50-
self.expense_post_return_advance()
51-
return {"type": "ir.actions.act_window_close"}
52-
return super().action_create_payments()
53-
54-
def expense_post_return_advance(self):
55-
"""This is opposite operation of action_create_payments(),
56-
it return remaining advance from employee back to company
57-
"""
58-
self.ensure_one()
59-
ctx = self._context.copy()
60-
ctx.update({"skip_account_move_synchronization": True})
61-
62-
if self._context.get("active_model") == "account.move":
63-
lines = (
64-
self.env["account.move"]
65-
.browse(self._context.get("active_ids", []))
66-
.line_ids
67-
)
68-
elif self._context.get("active_model") == "account.move.line":
69-
lines = self.env["account.move.line"].browse(
70-
self._context.get("active_ids", [])
71-
)
72-
73-
expense_sheet = lines.expense_id.sheet_id
74-
emp_advance = self._get_product_advance()
75-
advance_account = emp_advance.property_account_expense_id
76-
# Create return advance and post it
77-
batches = self._get_batches()
78-
first_batch_result = batches[0]
79-
payment_vals = self._create_payment_vals_from_wizard(first_batch_result)
80-
# Set new payment_type and payment entry to be Dr Bank, Cr Advance
81-
payment_vals["advance_id"] = expense_sheet.id
82-
payment_vals["partner_type"] = "customer"
83-
payment_vals["destination_account_id"] = advance_account.id
84-
payment_vals_list = [payment_vals]
85-
payment = (
86-
self.env["account.payment"].with_context(**ctx).create(payment_vals_list)
87-
)
88-
payment.action_post()
89-
90-
# Log the return advance in the chatter
91-
body = _(
92-
"A remaining advance return of %(amount)s %(symbol)s with the reference "
93-
"%(ref)s related to your expense %(name)s has been made."
94-
) % {
95-
"amount": payment.amount,
96-
"symbol": payment.currency_id.symbol,
97-
"ref": payment._get_html_link(),
98-
"name": expense_sheet.name,
99-
}
100-
expense_sheet.message_post(body=Markup(body))
101-
102-
# Reconcile the return advance and the advance,
103-
# i.e. lookup on the advance account on move lines
104-
account_move_lines_to_reconcile = self.env["account.move.line"]
105-
for line in payment.move_id.line_ids + expense_sheet.account_move_ids.line_ids:
106-
if line.account_id == advance_account and not line.reconciled:
107-
account_move_lines_to_reconcile |= line
108-
res = account_move_lines_to_reconcile.with_context(**ctx).reconcile()
109-
return res
47+
active_ids = self.env.context.get("active_ids", [])
48+
if self.env.context.get("active_model") == "account.move":
49+
lines = (
50+
self.env["account.move"]
51+
.browse(active_ids)
52+
.line_ids
53+
)
54+
elif self.env.context.get("active_model") == "account.move.line":
55+
lines = self.env["account.move.line"].browse(active_ids)
56+
57+
expense_sheet = lines.expense_id.sheet_id
58+
for x in to_process:
59+
x["create_vals"]["partner_type"] = "customer"
60+
x["create_vals"]["advance_id"] = expense_sheet.id
61+
62+
payments = super()._init_payments(to_process, edit_mode)
63+
return payments

0 commit comments

Comments
 (0)