Skip to content

Commit 9e088d2

Browse files
committed
[MIG] hr_expense_advance_clearing: Migration to 17.0
1 parent 3740cca commit 9e088d2

10 files changed

+91
-150
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": "16.0.1.0.3",
6+
"version": "17.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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def _check_hr_advance_move_reconciled(self):
1313
av_moves = self.filtered("line_ids.expense_id.sheet_id.advance")
1414
emp_advance = self.env.ref("hr_expense_advance_clearing.product_emp_advance")
1515
reconciled_av_move_lines = av_moves.mapped("line_ids").filtered(
16-
lambda l: l.product_id == emp_advance and l.matching_number
16+
lambda line: line.product_id == emp_advance and line.matching_number
1717
)
1818
if reconciled_av_move_lines:
1919
raise UserError(

hr_expense_advance_clearing/models/account_payment.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2022 Ecosoft Co., Ltd. (https://ecosoft.co.th)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33

4-
from odoo import fields, models
4+
from odoo import api, fields, models
55

66

77
class AccountPayment(models.Model):
@@ -20,3 +20,10 @@ def _synchronize_from_moves(self, changed_fields):
2020
else self
2121
)
2222
return super()._synchronize_from_moves(changed_fields)
23+
24+
@api.model
25+
def _get_valid_payment_account_types(self):
26+
account_types = super()._get_valid_payment_account_types()
27+
if self.env.context.get("hr_return_advance"):
28+
account_types.append("asset_current")
29+
return account_types

hr_expense_advance_clearing/models/hr_expense.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ def onchange_advance(self):
5959

6060
def _get_move_line_src(self, move_line_name, partner_id):
6161
self.ensure_one()
62-
unit_amount = self.unit_amount or self.total_amount
63-
quantity = self.quantity if self.unit_amount else 1
62+
price_unit = self.price_unit or self.total_amount
63+
quantity = self.quantity if self.price_unit else 1
6464
taxes = self.tax_ids.with_context(round=True).compute_all(
65-
unit_amount, self.currency_id, quantity, self.product_id
65+
price_unit, self.currency_id, quantity, self.product_id
6666
)
67-
amount_currency = self.total_amount - self.amount_tax
68-
balance = self.total_amount_company - self.amount_tax_company
67+
amount_currency = self.total_amount_currency - self.tax_amount_currency
68+
balance = self.total_amount - self.tax_amount
6969
ml_src_dict = {
7070
"name": move_line_name,
7171
"quantity": quantity,

hr_expense_advance_clearing/models/hr_expense_sheet.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ class HrExpenseSheet(models.Model):
1818
string="Clear Advance",
1919
domain="[('advance', '=', True), ('employee_id', '=', employee_id),"
2020
" ('clearing_residual', '>', 0.0)]",
21-
readonly=True,
22-
states={
23-
"draft": [("readonly", False)],
24-
"submit": [("readonly", False)],
25-
"approve": [("readonly", False)],
26-
},
2721
help="Show remaining advance of this employee",
2822
)
2923
clearing_sheet_ids = fields.One2many(
@@ -64,16 +58,16 @@ def _check_advance_expense(self):
6458
if advance_lines and len(advance_lines) != len(self.expense_line_ids):
6559
raise ValidationError(_("Advance must contain only advance expense line"))
6660

67-
@api.depends("account_move_id.payment_state")
68-
def _compute_payment_state(self):
61+
@api.depends("account_move_ids.payment_state", "account_move_ids.amount_residual")
62+
def _compute_from_account_move_ids(self):
6963
"""After clear advance.
7064
if amount residual is zero, payment state will change to 'paid'
7165
"""
72-
res = super()._compute_payment_state()
66+
res = super()._compute_from_account_move_ids()
7367
for sheet in self:
7468
if (
7569
sheet.advance_sheet_id
76-
and sheet.account_move_id.state == "posted"
70+
and sheet.account_move_ids.state == "posted"
7771
and not sheet.amount_residual
7872
):
7973
sheet.payment_state = "paid"
@@ -82,7 +76,7 @@ def _compute_payment_state(self):
8276
def _get_product_advance(self):
8377
return self.env.ref("hr_expense_advance_clearing.product_emp_advance", False)
8478

85-
@api.depends("account_move_id.line_ids.amount_residual")
79+
@api.depends("account_move_ids.line_ids.amount_residual")
8680
def _compute_clearing_residual(self):
8781
for sheet in self:
8882
emp_advance = sheet._get_product_advance()
@@ -98,7 +92,7 @@ def _compute_clearing_residual(self):
9892

9993
def _compute_amount_payable(self):
10094
for sheet in self:
101-
rec_lines = sheet.account_move_id.line_ids.filtered(
95+
rec_lines = sheet.account_move_ids.line_ids.filtered(
10296
lambda x: x.credit and x.account_id.reconcile and not x.reconciled
10397
)
10498
sheet.amount_payable = -sum(rec_lines.mapped("amount_residual"))
@@ -119,8 +113,8 @@ def action_sheet_move_create(self):
119113
precision_rounding=sheet.currency_id.rounding,
120114
)
121115
move_lines = (
122-
sheet.account_move_id.line_ids
123-
| sheet.advance_sheet_id.account_move_id.line_ids
116+
sheet.account_move_ids.line_ids
117+
| sheet.advance_sheet_id.account_move_ids.line_ids
124118
)
125119
emp_advance = sheet._get_product_advance()
126120
account_id = emp_advance.property_account_expense_id.id
@@ -167,14 +161,12 @@ def _get_move_line_vals(self):
167161
)
168162
total_amount = 0.0
169163
total_amount_currency = 0.0
170-
partner_id = (
171-
expense.employee_id.sudo().address_home_id.commercial_partner_id.id
172-
)
164+
partner_id = expense.employee_id.sudo().work_contact_id.id
173165
# source move line
174166
move_line_src = expense._get_move_line_src(move_line_name, partner_id)
175167
move_line_values = [move_line_src]
176-
total_amount -= expense.total_amount_company
177-
total_amount_currency -= expense.total_amount
168+
total_amount -= expense.total_amount
169+
total_amount_currency -= expense.total_amount_currency
178170

179171
# destination move line
180172
move_line_dst = expense._get_move_line_dst(
@@ -208,7 +200,7 @@ def _get_move_line_vals(self):
208200
payable_move_line["amount_currency"] = -remain_payable
209201
payable_move_line[
210202
"account_id"
211-
] = expense._get_expense_account_destination()
203+
] = expense.sheet_id._get_expense_account_destination()
212204
else:
213205
advance_to_clear -= credit
214206
# Add destination first (if credit is not zero)
@@ -219,10 +211,10 @@ def _get_move_line_vals(self):
219211
move_line_vals.extend(move_line_values)
220212
return move_line_vals
221213

222-
def _prepare_bill_vals(self):
214+
def _prepare_bills_vals(self):
223215
"""create journal entry instead of bills when clearing document"""
224216
self.ensure_one()
225-
res = super()._prepare_bill_vals()
217+
res = super()._prepare_bills_vals()
226218
if self.advance_sheet_id and self.payment_mode == "own_account":
227219
if (
228220
self.advance_sheet_residual <= 0.0

hr_expense_advance_clearing/tests/test_hr_expense_advance_clearing.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _create_expense(
5858
expense.employee_id = employee
5959
if not advance:
6060
expense.product_id = product
61-
expense.total_amount = amount
61+
expense.total_amount_currency = amount
6262
expense.payment_mode = payment_mode
6363
expense = expense.save()
6464
expense.tax_ids = False # Test no vat
@@ -170,10 +170,10 @@ def test_1_clear_equal_advance(self):
170170
"""When clear equal advance, all set"""
171171
# ------------------ Advance --------------------------
172172
self.advance.action_submit_sheet()
173-
self.advance.approve_expense_sheets()
173+
self.advance.action_approve_expense_sheets()
174174
self.advance.action_sheet_move_create()
175175
self.assertEqual(self.advance.clearing_residual, 1000.0)
176-
self._register_payment(self.advance.account_move_id, 1000.0)
176+
self._register_payment(self.advance.account_move_ids, 1000.0)
177177
self.assertEqual(self.advance.state, "done")
178178
# ------------------ Clearing --------------------------
179179
# Clear this with previous advance
@@ -183,15 +183,15 @@ def test_1_clear_equal_advance(self):
183183
self.clearing_equal.advance_sheet_id = self.advance
184184
self.assertEqual(self.clearing_equal.advance_sheet_residual, 1000.0)
185185
self.clearing_equal.action_submit_sheet()
186-
self.clearing_equal.approve_expense_sheets()
186+
self.clearing_equal.action_approve_expense_sheets()
187187
self.clearing_equal.action_sheet_move_create()
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.approve_expense_sheets()
194+
self.clearing_more.action_approve_expense_sheets()
195195
with self.assertRaises(ValidationError):
196196
self.clearing_more.action_sheet_move_create()
197197
# There are 2 clearing in advance
@@ -209,57 +209,57 @@ def test_1_clear_equal_advance(self):
209209
)
210210
# Check back state move in advance after create clearing
211211
with self.assertRaises(UserError):
212-
self.advance.account_move_id.button_draft()
212+
self.advance.account_move_ids.button_draft()
213213
with self.assertRaises(UserError):
214-
self.advance.account_move_id.button_cancel()
214+
self.advance.account_move_ids.button_cancel()
215215
with self.assertRaises(UserError):
216-
self.advance.account_move_id._reverse_moves()
216+
self.advance.account_move_ids._reverse_moves()
217217

218218
@mute_logger("odoo.models.unlink")
219219
def test_2_clear_more_than_advance(self):
220220
"""When clear more than advance, do pay more"""
221221
# ------------------ Advance --------------------------
222222
self.advance.action_submit_sheet()
223-
self.advance.approve_expense_sheets()
223+
self.advance.action_approve_expense_sheets()
224224
self.advance.action_sheet_move_create()
225225
self.assertEqual(self.advance.clearing_residual, 1000.0)
226-
self._register_payment(self.advance.account_move_id, 1000.0)
226+
self._register_payment(self.advance.account_move_ids, 1000.0)
227227
self.assertEqual(self.advance.state, "done")
228228
# ------------------ Clearing --------------------------
229229
# Clear this with previous advance
230230
self.clearing_more.advance_sheet_id = self.advance
231231
self.assertEqual(self.clearing_more.advance_sheet_residual, 1000.0)
232232
self.clearing_more.action_submit_sheet()
233-
self.clearing_more.approve_expense_sheets()
233+
self.clearing_more.action_approve_expense_sheets()
234234
self.clearing_more.action_sheet_move_create()
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)
238-
self._register_payment(self.clearing_more.account_move_id, 200.0)
238+
self._register_payment(self.clearing_more.account_move_ids, 200.0)
239239
self.assertEqual(self.clearing_more.state, "done")
240240

241241
@mute_logger("odoo.models.unlink")
242242
def test_3_clear_less_than_advance(self):
243243
"""When clear less than advance, do return advance"""
244244
# ------------------ Advance --------------------------
245245
self.advance.action_submit_sheet()
246-
self.advance.approve_expense_sheets()
246+
self.advance.action_approve_expense_sheets()
247247
self.advance.action_sheet_move_create()
248248
# Test return advance register payment with move state draft
249249
with self.assertRaises(UserError):
250-
self.advance.account_move_id.button_draft()
250+
self.advance.account_move_ids.button_draft()
251251
self._register_payment(
252-
self.advance.account_move_id, 200.0, hr_return_advance=True
252+
self.advance.account_move_ids, 200.0, hr_return_advance=True
253253
)
254254
self.assertEqual(self.advance.clearing_residual, 1000.0)
255-
self._register_payment(self.advance.account_move_id, 1000.0)
255+
self._register_payment(self.advance.account_move_ids, 1000.0)
256256
self.assertEqual(self.advance.state, "done")
257257
# ------------------ Clearing, Return Advance --------------------------
258258
# Clear this with previous advance
259259
self.clearing_less.advance_sheet_id = self.advance
260260
self.assertEqual(self.clearing_less.advance_sheet_residual, 1000.0)
261261
self.clearing_less.action_submit_sheet()
262-
self.clearing_less.approve_expense_sheets()
262+
self.clearing_less.action_approve_expense_sheets()
263263
register_payment = self.advance.with_context(
264264
hr_return_advance=True
265265
).action_register_payment()
@@ -271,7 +271,7 @@ def test_3_clear_less_than_advance(self):
271271
# Test return advance over residual
272272
with self.assertRaises(UserError):
273273
self._register_payment(
274-
self.advance.account_move_id,
274+
self.advance.account_move_ids,
275275
300.0,
276276
ctx=register_payment["context"],
277277
hr_return_advance=True,
@@ -282,7 +282,7 @@ def test_3_clear_less_than_advance(self):
282282
self.assertEqual(self.clearing_less.advance_sheet_residual, 200.0)
283283
# Back to advance and do return advance, clearing residual become 0.0
284284
self._register_payment(
285-
self.advance.account_move_id,
285+
self.advance.account_move_ids,
286286
200.0,
287287
ctx=register_payment["context"],
288288
hr_return_advance=True,
@@ -300,10 +300,10 @@ def test_4_clearing_product_advance(self):
300300
# ------------------ Advance --------------------------
301301
self.advance.expense_line_ids.clearing_product_id = self.product_a
302302
self.advance.action_submit_sheet()
303-
self.advance.approve_expense_sheets()
303+
self.advance.action_approve_expense_sheets()
304304
self.advance.action_sheet_move_create()
305305
self.assertEqual(self.advance.clearing_residual, 1000.0)
306-
self._register_payment(self.advance.account_move_id, 1000.0)
306+
self._register_payment(self.advance.account_move_ids, 1000.0)
307307
self.assertEqual(self.advance.state, "done")
308308
# ------------------ Clearing --------------------------
309309
with Form(self.env["hr.expense.sheet"]) as sheet:
@@ -314,10 +314,10 @@ def test_4_clearing_product_advance(self):
314314
self.assertEqual(len(ex_sheet.expense_line_ids), 0)
315315
ex_sheet._onchange_advance_sheet_id()
316316
self.assertEqual(len(ex_sheet.expense_line_ids), 1)
317-
reverse_move = self.advance.account_move_id._reverse_moves(
317+
reverse_move = self.advance.account_move_ids._reverse_moves(
318318
default_values_list=[
319-
{"invoice_date": self.advance.account_move_id.date, "ref": False}
319+
{"invoice_date": self.advance.account_move_ids.date, "ref": False}
320320
],
321321
cancel=True,
322322
)
323-
self.assertNotEqual(reverse_move, self.advance.account_move_id)
323+
self.assertNotEqual(reverse_move, self.advance.account_move_ids)

hr_expense_advance_clearing/views/account_payment_view.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
<field name="inherit_id" ref="account.view_account_payment_form" />
2323
<field name="arch" type="xml">
2424
<xpath expr="//sheet//group[@name='group2']" position="inside">
25-
<field
26-
name="advance_id"
27-
attrs="{'invisible': [('payment_type', '!=', 'inbound')]}"
28-
/>
25+
<field name="advance_id" invisible="payment_type != 'inbound'" />
2926
</xpath>
3027
</field>
3128
</record>

hr_expense_advance_clearing/views/hr_employee_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
name="action_open_advance_clearing"
1111
type="object"
1212
icon="fa-bars"
13-
attrs="{'invisible': [('advance_count', '=', 0)]}"
13+
invisible="advance_count == 0"
1414
>
1515
<field name="advance_count" string="Advance" widget="statinfo" />
1616
</button>

0 commit comments

Comments
 (0)