Skip to content

Commit

Permalink
[MIG] hr_expense_invoice: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cav-adhoc committed Dec 13, 2024
1 parent e890a97 commit e66eb45
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion hr_expense_invoice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Supplier invoices on HR expenses",
"version": "17.0.1.0.2",
"version": "18.0.1.0.0",
"category": "Human Resources",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
8 changes: 4 additions & 4 deletions hr_expense_invoice/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def _do_create_moves(self):
(ap_lines + transfer_line).reconcile()
return res

def action_sheet_move_create(self):
def action_sheet_move_post(self):
"""Perform extra checks and set proper payment state according linked
invoices.
"""
self._validate_expense_invoice()
res = super().action_sheet_move_create()
res = super().action_sheet_move_post()
# The payment state is set in a fixed way in super, but it depends on the
# payment state of the invoices when there are some of them linked
self.filtered(
Expand All @@ -64,7 +64,7 @@ def set_to_paid(self):

def _compute_invoice_count(self):
Invoice = self.env["account.move"]
can_read = Invoice.check_access_rights("read", raise_exception=False)
can_read = Invoice.has_access("read")
for sheet in self:
sheet.invoice_count = (
can_read and len(sheet.expense_line_ids.mapped("invoice_id")) or 0
Expand Down Expand Up @@ -141,7 +141,7 @@ def action_view_invoices(self):
action["view_mode"] = "form"
action["views"] = [(view.id, "form")]
else:
action["view_mode"] = "tree,form"
action["view_mode"] = "list,form"
action["domain"] = [("id", "in", invoice_ids)]

Check warning on line 145 in hr_expense_invoice/models/hr_expense_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_invoice/models/hr_expense_sheet.py#L144-L145

Added lines #L144 - L145 were not covered by tests
return action

Expand Down
41 changes: 15 additions & 26 deletions hr_expense_invoice/tests/test_hr_expense_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from odoo import fields
from odoo.exceptions import UserError, ValidationError
from odoo.tests import tagged
from odoo.tests.common import Form
from odoo.tests import Form, tagged

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
Expand All @@ -16,8 +15,8 @@
@tagged("post_install", "-at_install")
class TestHrExpenseInvoice(TestExpenseCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.account_payment_register = cls.env["account.payment.register"]
cls.payment_obj = cls.env["account.payment"]
Expand Down Expand Up @@ -98,12 +97,12 @@ def test_0_hr_test_no_invoice(self):
self.assertAlmostEqual(
self.expense.total_amount_currency, self.product_a.standard_price
)
# We approve sheet, no invoice
# We approve sheet
sheet.action_submit_sheet()
sheet.action_approve_expense_sheets()
self.assertEqual(sheet.state, "approve")
self.assertFalse(sheet.account_move_ids)
# We post journal entries
sheet.action_sheet_move_create()
sheet.action_sheet_move_post()
self.assertEqual(sheet.state, "post")
self.assertTrue(sheet.account_move_ids)
# We make payment on expense sheet
Expand All @@ -119,18 +118,11 @@ def test_1_hr_test_invoice(self):
with Form(self.expense) as f:
f.invoice_id = self.invoice
# We approve sheet
sheet.action_submit_sheet()
sheet.action_approve_expense_sheets()
self.assertEqual(sheet.state, "approve")
self.assertFalse(sheet.account_move_ids)
self.assertEqual(self.invoice.state, "posted")
# Test state not posted
self.invoice.button_draft()
with self.assertRaises(UserError):
sheet.action_sheet_move_create()
self.invoice.action_post()
# We post journal entries
sheet.action_sheet_move_create()
# If sheet has an associated invoice state changes to post
self.assertEqual(sheet.state, "post")
self.assertEqual(self.invoice.state, "posted")
self.assertEqual(self.invoice.payment_state, "paid")
self.assertEqual(sheet.payment_state, "not_paid")
self.assertEqual(self.expense.amount_residual, 100)
Expand Down Expand Up @@ -158,12 +150,12 @@ def test_1_hr_test_invoice_paid_by_company(self):
self.invoice.action_post() # residual = 100.0
self.expense.invoice_id = self.invoice
# We approve sheet
sheet.action_submit_sheet()
sheet.action_approve_expense_sheets()
self.assertEqual(sheet.state, "approve")
self.assertFalse(sheet.account_move_ids)
self.assertEqual(self.invoice.state, "posted")
# We post journal entries
sheet.action_sheet_move_create()
sheet.action_sheet_move_post()
self.assertEqual(sheet.state, "done")
self.assertEqual(self.invoice.payment_state, "not_paid")
# Click on View Invoice button link to the correct invoice
Expand All @@ -186,13 +178,11 @@ def test_2_hr_test_multi_invoices(self):
self.assertAlmostEqual(self.expense.total_amount_currency, 100)
self.assertAlmostEqual(self.expense2.total_amount_currency, 100)
# We approve sheet
sheet.action_submit_sheet()
sheet.action_approve_expense_sheets()
self.assertEqual(sheet.state, "approve")
self.assertFalse(sheet.account_move_ids)
self.assertEqual(self.invoice.state, "posted")
# We post journal entries
sheet.action_sheet_move_create()
# If sheet has an associated invoice state changes to post
self.assertEqual(sheet.state, "post")
self.assertEqual(self.invoice.state, "posted")
self.assertEqual(self.invoice.payment_state, "paid")
self.assertEqual(self.invoice2.payment_state, "paid")

Expand Down Expand Up @@ -229,9 +219,8 @@ def test_3_hr_test_expense_create_invoice(self):
self.expense2.invoice_id.partner_id = self.partner_a
self.expense2.invoice_id.action_post()
# We approve sheet
sheet.action_submit_sheet()
sheet.action_approve_expense_sheets()
# We post journal entries
sheet.action_sheet_move_create()

def test_4_hr_expense_constraint(self):
# Only invoice with status open is allowed
Expand Down
4 changes: 2 additions & 2 deletions hr_expense_invoice/views/hr_expense_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='expense_line_ids']/tree/field[@name='name']"
expr="//field[@name='expense_line_ids']/list/field[@name='name']"
position="after"
>
<field name="invoice_id" groups="account.group_account_invoice" />
<field name="quantity" invisible="1" />
</xpath>
<xpath
expr="//field[@name='expense_line_ids']/tree/field[@name='total_amount_currency']"
expr="//field[@name='expense_line_ids']/list/field[@name='total_amount_currency']"
position="after"
>
<field name="sheet_id_state" invisible="1" />
Expand Down

0 comments on commit e66eb45

Please sign in to comment.