diff --git a/hr_expense_cancel/tests/test_hr_expense_cancel.py b/hr_expense_cancel/tests/test_hr_expense_cancel.py index 748e51e2a..2ad37e699 100644 --- a/hr_expense_cancel/tests/test_hr_expense_cancel.py +++ b/hr_expense_cancel/tests/test_hr_expense_cancel.py @@ -98,13 +98,8 @@ def test_action_cancel_no_update_posted(self): def test_action_cancel_company_account(self): self.expense.payment_mode = "company_account" self.expense_sheet.action_sheet_move_create() - - self.assertEqual(len(self.expense_sheet.payment_ids), 1) self.assertTrue(self.expense_sheet.account_move_id) - self.expense_sheet.action_cancel() - payment = self.expense_sheet.payment_ids.filtered(lambda l: l.state != "cancel") - self.assertFalse(payment) self.assertFalse(self.expense_sheet.account_move_id) def test_action_cancel_own_account(self): diff --git a/hr_expense_payment/models/__init__.py b/hr_expense_payment/models/__init__.py index e9fa1d92d..d8c87fafa 100644 --- a/hr_expense_payment/models/__init__.py +++ b/hr_expense_payment/models/__init__.py @@ -1,5 +1,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import account_payment -from . import hr_expense from . import hr_expense_sheet diff --git a/hr_expense_payment/models/hr_expense.py b/hr_expense_payment/models/hr_expense.py deleted file mode 100644 index 32dcac98d..000000000 --- a/hr_expense_payment/models/hr_expense.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2019 Tecnativa - Ernesto Tejeda -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from odoo import models - - -class HrExpense(models.Model): - _inherit = "hr.expense" - - def _prepare_payment_expense_company( - self, - payment_methods, - journal, - different_currency, - journal_currency, - total_amount_currency, - ): - self.ensure_one() - commercial_partner_id = ( - self.employee_id.sudo().address_home_id.commercial_partner_id - ) - payment_dict = { - "date": self.date, - "amount": total_amount_currency, - "payment_type": "outbound", - "partner_type": "supplier", - "ref": self.name, - "journal_id": journal.id, - "currency_id": self.currency_id.id - if different_currency - else journal_currency.id, - "partner_id": commercial_partner_id.id, - "payment_method_id": payment_methods and payment_methods[0].id or False, - "expense_sheet_ids": self.sheet_id.ids, - } - return payment_dict - - def action_move_create(self): - move_group_by_sheet = super().action_move_create() - payment_list = [] - # you can skip create payment from expense paid by company_account - if self.env.context.get("skip_create_payment_company_account", False): - return move_group_by_sheet - for expense in self: - if expense.payment_mode == "company_account": - total_amount_currency = expense.total_amount - different_currency = ( - expense.currency_id != expense.company_id.currency_id - ) - journal = expense.sheet_id.bank_journal_id - journal_currency = journal.currency_id or journal.company_id.currency_id - payment_methods = journal.outbound_payment_method_line_ids.mapped( - "payment_method_id" - ) - # prepare payment dict value for case paid by company - payment_dict = expense._prepare_payment_expense_company( - payment_methods, - journal, - different_currency, - journal_currency, - total_amount_currency, - ) - payment_list.append(payment_dict) - # create payment and auto post from expense paid by company - if payment_list: - payment = self.env["account.payment"].create(payment_list) - payment.action_post() - return move_group_by_sheet diff --git a/hr_expense_payment/tests/test_hr_expense_payment.py b/hr_expense_payment/tests/test_hr_expense_payment.py index 0b13ecb80..f89ee6214 100644 --- a/hr_expense_payment/tests/test_hr_expense_payment.py +++ b/hr_expense_payment/tests/test_hr_expense_payment.py @@ -83,18 +83,3 @@ def test_get_payment_vals(self): self.assertFalse(self.expense_sheet.payment_ids) payment_wizard.action_create_payments() self.assertEqual(len(self.expense_sheet.payment_ids), 1) - - def test_action_sheet_move_create(self): - self.expense.payment_mode = "company_account" - self.assertFalse(self.expense_sheet.payment_ids) - self.expense_sheet.action_sheet_move_create() - self.assertEqual(len(self.expense_sheet.payment_ids), 1) - - def test_action_sheet_move_create_skip_payment(self): - self.expense.payment_mode = "company_account" - self.assertFalse(self.expense_sheet.payment_ids) - self.expense_sheet.with_context( - skip_create_payment_company_account=True - ).action_sheet_move_create() - self.assertFalse(self.expense_sheet.payment_ids) - self.assertEqual(self.expense_sheet.state, "done")