mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'fix/14.0/hr_expense_change_analytic__write_multiple_expense_lines' into '14.0'
fix/14.0/hr_expense_change_analytic__write_multiple_expense_lines into 14.0 See merge request hibou-io/hibou-odoo/suite!924
This commit is contained in:
@@ -1,36 +1,57 @@
|
||||
from odoo.addons.hr_expense_change.tests import test_expense_change
|
||||
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
|
||||
from odoo.tests import tagged
|
||||
from odoo import fields
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestWizard(test_expense_change.TestAccountEntry):
|
||||
class TestWizard(TestExpenseCommon):
|
||||
|
||||
def test_expense_change_basic(self):
|
||||
super(TestWizard, self).test_expense_values()
|
||||
def test_expense_change_analytic(self):
|
||||
expense_sheet = self.env['hr.expense.sheet'].create({
|
||||
'name': 'First Expense for employee',
|
||||
'employee_id': self.expense_employee.id,
|
||||
'journal_id': self.company_data['default_journal_purchase'].id,
|
||||
'accounting_date': '2017-01-01',
|
||||
'expense_line_ids': [
|
||||
(0, 0, {
|
||||
'name': 'expense_1',
|
||||
'date': '2016-01-01',
|
||||
'product_id': self.product_a.id,
|
||||
'unit_amount': 1000.0,
|
||||
'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)],
|
||||
'analytic_account_id': False,
|
||||
'employee_id': self.expense_employee.id,
|
||||
}),
|
||||
(0, 0, {
|
||||
'name': 'expense_2',
|
||||
'date': '2016-01-01',
|
||||
'product_id': self.product_a.id,
|
||||
'unit_amount': 500.0,
|
||||
'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)],
|
||||
'analytic_account_id': False,
|
||||
'employee_id': self.expense_employee.id,
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
expense_sheet.action_submit_sheet()
|
||||
expense_sheet.approve_expense_sheets()
|
||||
expense_sheet.action_sheet_move_create()
|
||||
|
||||
# Tests Adding an Analytic Account
|
||||
|
||||
self.analytic_account = self.env['account.analytic.account'].create({
|
||||
'name': 'test account',
|
||||
})
|
||||
self.analytic_account2 = self.env['account.analytic.account'].create({
|
||||
'name': 'test account2',
|
||||
})
|
||||
|
||||
self.assertNotEqual(self.expense.analytic_account_id, self.analytic_account)
|
||||
ctx = {'active_model': 'hr.expense', 'active_ids': self.expense.ids}
|
||||
self.assertFalse(any(expense_sheet.expense_line_ids.mapped('analytic_account_id')))
|
||||
ctx = {'active_model': 'hr.expense', 'active_ids': [expense_sheet.expense_line_ids[0].id]}
|
||||
change = self.env['hr.expense.change'].sudo().with_context(ctx).create({})
|
||||
change.analytic_account_id = self.analytic_account
|
||||
change.analytic_account_id = self.analytic_account_1
|
||||
change.affect_change()
|
||||
self.assertEqual(self.expense.analytic_account_id, self.analytic_account)
|
||||
self.assertEqual(expense_sheet.expense_line_ids.mapped('analytic_account_id'), self.analytic_account_1)
|
||||
|
||||
# Tests Changing
|
||||
change.analytic_account_id = self.analytic_account2
|
||||
change.analytic_account_id = self.analytic_account_2
|
||||
change.affect_change()
|
||||
self.assertEqual(self.expense.analytic_account_id, self.analytic_account2)
|
||||
self.assertEqual(expense_sheet.expense_line_ids.mapped('analytic_account_id'), self.analytic_account_2)
|
||||
|
||||
# Tests Removing
|
||||
change.analytic_account_id = False
|
||||
change.affect_change()
|
||||
self.assertFalse(self.expense.analytic_account_id)
|
||||
self.assertFalse(any(expense_sheet.expense_line_ids.mapped('analytic_account_id')))
|
||||
|
||||
@@ -47,12 +47,12 @@ class ExpenseChangeWizard(models.TransientModel):
|
||||
def _affect_analytic_change(self, old_analytic_id):
|
||||
expenses_to_affect = self._find_expenses_to_write_analytic(old_analytic_id)
|
||||
if expenses_to_affect:
|
||||
prev_state = expenses_to_affect.state
|
||||
expenses_to_affect.state = "draft"
|
||||
prev_state = self.expense_id.sheet_id.state
|
||||
self.expense_id.sheet_id.write({'state': 'draft'})
|
||||
expenses_to_affect.write({'analytic_account_id': self.analytic_account_id.id})
|
||||
|
||||
lines_to_affect = self.expense_id.sheet_id.account_move_id \
|
||||
.line_ids.filtered(lambda l: l.analytic_account_id.id == old_analytic_id and l.debit)
|
||||
lines_to_affect.write({'analytic_account_id': self.analytic_account_id.id})
|
||||
lines_to_affect.create_analytic_lines()
|
||||
expenses_to_affect.state = prev_state
|
||||
self.expense_id.sheet_id.write({'state': prev_state})
|
||||
|
||||
Reference in New Issue
Block a user