diff --git a/hr_expense_invoice/__manifest__.py b/hr_expense_invoice/__manifest__.py
index b7ce10c0c..a81422225 100644
--- a/hr_expense_invoice/__manifest__.py
+++ b/hr_expense_invoice/__manifest__.py
@@ -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",
diff --git a/hr_expense_invoice/models/hr_expense_sheet.py b/hr_expense_invoice/models/hr_expense_sheet.py
index a74840d37..45cbb0a4d 100644
--- a/hr_expense_invoice/models/hr_expense_sheet.py
+++ b/hr_expense_invoice/models/hr_expense_sheet.py
@@ -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(
@@ -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
@@ -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)]
return action
diff --git a/hr_expense_invoice/tests/test_hr_expense_invoice.py b/hr_expense_invoice/tests/test_hr_expense_invoice.py
index 6ab27fb10..8eaa87f90 100644
--- a/hr_expense_invoice/tests/test_hr_expense_invoice.py
+++ b/hr_expense_invoice/tests/test_hr_expense_invoice.py
@@ -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
@@ -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"]
@@ -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
@@ -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)
@@ -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
@@ -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")
@@ -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
diff --git a/hr_expense_invoice/views/hr_expense_views.xml b/hr_expense_invoice/views/hr_expense_views.xml
index 61320cab3..0731a44bd 100644
--- a/hr_expense_invoice/views/hr_expense_views.xml
+++ b/hr_expense_invoice/views/hr_expense_views.xml
@@ -88,14 +88,14 @@