Skip to content

Commit

Permalink
Merge PR OCA#169 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Apr 20, 2023
2 parents a6f8607 + 731db50 commit e4c796f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions hr_expense_invoice/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def action_expense_create_invoice(self):
}
]
)
attachments = self.env["ir.attachment"].search(
[("res_model", "=", self._name), ("res_id", "in", self.ids)]
)
for attachment in attachments:
attachment.copy({"res_model": invoice._name, "res_id": invoice.id})
self.write(
{
"invoice_id": invoice.id,
Expand Down
24 changes: 23 additions & 1 deletion hr_expense_invoice/tests/test_hr_expense_invoice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2021 Tecnativa - Pedro M. Baeza
# Copyright 2021 Tecnativa - Víctor Martínez
# Copyright 2021-2023 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import base64

from odoo import fields
from odoo.exceptions import UserError, ValidationError
Expand Down Expand Up @@ -100,8 +101,11 @@ def setUpClass(cls):
"unit_amount": 50.0,
}
)
cls._create_attachment(cls, cls.expense._name, cls.expense.id)
cls.expense2 = cls.expense.copy()
cls._create_attachment(cls, cls.expense2._name, cls.expense2.id)
cls.expense3 = cls.expense.copy()
cls._create_attachment(cls, cls.expense3._name, cls.expense3.id)

def _register_payment(self, sheet):
action = sheet.action_register_payment()
Expand All @@ -117,6 +121,21 @@ def _register_payment(self, sheet):
self.assertEqual(len(payment), 1)
self.assertEqual(sheet.state, "done")

def _create_attachment(self, res_model, res_id):
return self.env["ir.attachment"].create(
{
"name": "Test attachment %s (%s)" % (res_id, res_model),
"res_model": res_model,
"res_id": res_id,
"datas": base64.b64encode(b"\xff data"),
}
)

def test_0_hr_tests_misc(self):
self.assertEqual(self.expense.attachment_number, 1)
self.assertEqual(self.expense2.attachment_number, 1)
self.assertEqual(self.expense3.attachment_number, 1)

def test_0_hr_test_no_invoice(self):
# There is not expense lines in sheet
self.assertEqual(len(self.sheet.expense_line_ids), 0)
Expand Down Expand Up @@ -271,10 +290,12 @@ def test_3_hr_test_expense_create_invoice(self):
self.assertEqual(len(self.sheet.expense_line_ids), 2)
self.expense.action_expense_create_invoice()
self.assertTrue(self.expense.invoice_id)
self.assertAlmostEqual(self.expense.invoice_id.message_attachment_count, 1)
self.assertEqual(self.sheet.invoice_count, 1)
self.sheet.invalidate_cache()
self.expense2.action_expense_create_invoice()
self.assertTrue(self.expense2.invoice_id)
self.assertAlmostEqual(self.expense2.invoice_id.message_attachment_count, 1)
self.assertEqual(self.sheet.invoice_count, 2)
# Only change invoice not assigned to expense yet
with self.assertRaises(ValidationError):
Expand Down Expand Up @@ -327,6 +348,7 @@ def test_5_hr_test_multi_invoice(self):
self.sheet.expense_line_ids = [(6, 0, [self.expense.id, self.expense2.id])]
# We add invoice to expense
self.expense2.action_expense_create_invoice()
self.assertAlmostEqual(self.expense2.invoice_id.message_attachment_count, 1)
self.expense2.invoice_id.partner_id = self.partner
self.expense2.invoice_id.action_post()
# We approve sheet
Expand Down

0 comments on commit e4c796f

Please sign in to comment.