mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[FIX] hr_expense_change,hr_expense_change_analytic: fix failing tests
H4954
This commit is contained in:
@@ -1,20 +1,56 @@
|
|||||||
from odoo.addons.hr_expense.tests.test_expenses import TestAccountEntry
|
from odoo import fields
|
||||||
|
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
|
||||||
|
|
||||||
|
|
||||||
class TestAccountEntry(TestAccountEntry):
|
class TestExpenseChange(TestExpenseCommon):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestExpenseChange, self).setUp()
|
||||||
|
|
||||||
|
self.setUpAdditionalAccounts()
|
||||||
|
|
||||||
|
self.product_expense = self.env['product.product'].create({
|
||||||
|
'name': "Delivered at cost",
|
||||||
|
'standard_price': 700,
|
||||||
|
'list_price': 700,
|
||||||
|
'type': 'consu',
|
||||||
|
'supplier_taxes_id': [(6, 0, [self.tax.id])],
|
||||||
|
'default_code': 'CONSU-DELI-COST',
|
||||||
|
'taxes_id': False,
|
||||||
|
'property_account_expense_id': self.account_expense.id,
|
||||||
|
})
|
||||||
|
|
||||||
def test_expense_change_basic(self):
|
def test_expense_change_basic(self):
|
||||||
# posts expense and gets move ready at self.expense.account_move_id.id
|
# post expense and get move ready at expense.account_move_id.id
|
||||||
self.test_account_entry()
|
expense = self.env['hr.expense.sheet'].create({
|
||||||
self.assertEqual(self.expense.expense_line_ids.date, self.expense.account_move_id.date)
|
'name': 'Expense for John Smith',
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
})
|
||||||
|
expense_line = self.env['hr.expense'].create({
|
||||||
|
'name': 'Car Travel Expenses',
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'product_id': self.product_expense.id,
|
||||||
|
'unit_amount': 700.00,
|
||||||
|
'tax_ids': [(6, 0, [self.tax.id])],
|
||||||
|
'sheet_id': expense.id,
|
||||||
|
'analytic_account_id': self.analytic_account.id,
|
||||||
|
})
|
||||||
|
expense_line._onchange_product_id()
|
||||||
|
# Submitted to Manager
|
||||||
|
expense.action_submit_sheet()
|
||||||
|
# Approve
|
||||||
|
expense.approve_expense_sheets()
|
||||||
|
# Create Expense Entries
|
||||||
|
expense.action_sheet_move_create()
|
||||||
|
self.assertEquals(expense.state, 'post', 'Expense is not in Waiting Payment state')
|
||||||
|
|
||||||
ctx = {'active_model': 'hr.expense', 'active_ids': self.expense.expense_line_ids.ids}
|
ctx = {'active_model': 'hr.expense', 'active_ids': expense.expense_line_ids.ids}
|
||||||
change = self.env['hr.expense.change'].with_context(ctx).create({})
|
change = self.env['hr.expense.change'].with_context(ctx).create({})
|
||||||
self.assertEqual(change.date, self.expense.expense_line_ids.date)
|
self.assertEqual(change.date, expense.expense_line_ids.date)
|
||||||
|
|
||||||
change_date = '2018-01-01'
|
change_date = '2018-01-01'
|
||||||
change.write({'date': change_date})
|
change.write({'date': change_date})
|
||||||
|
|
||||||
change.affect_change()
|
change.affect_change()
|
||||||
self.assertEqual(change_date, self.expense.expense_line_ids.date)
|
self.assertEqual(change_date, fields.Date.to_string(expense.expense_line_ids.date))
|
||||||
self.assertEqual(change_date, self.expense.account_move_id.date)
|
self.assertEqual(change_date, fields.Date.to_string(expense.account_move_id.date))
|
||||||
|
|||||||
@@ -1,33 +1,79 @@
|
|||||||
from odoo.addons.hr_expense_change.tests.test_expense_change import TestAccountEntry
|
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
|
||||||
|
|
||||||
|
|
||||||
class TestWizard(TestAccountEntry):
|
class TestWizard(TestExpenseCommon):
|
||||||
def test_expense_change_basic(self):
|
def setUp(self):
|
||||||
self.analytic_account = self.env['account.analytic.account'].create({
|
super(TestWizard, self).setUp()
|
||||||
|
|
||||||
|
self.setUpAdditionalAccounts()
|
||||||
|
|
||||||
|
self.product_expense = self.env['product.product'].create({
|
||||||
|
'name': "Delivered at cost",
|
||||||
|
'standard_price': 700,
|
||||||
|
'list_price': 700,
|
||||||
|
'type': 'consu',
|
||||||
|
'supplier_taxes_id': [(6, 0, [self.tax.id])],
|
||||||
|
'default_code': 'CONSU-DELI-COST',
|
||||||
|
'taxes_id': False,
|
||||||
|
'property_account_expense_id': self.account_expense.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
def test_expense_change_analytic(self):
|
||||||
|
analytic_account = self.env['account.analytic.account'].create({
|
||||||
'name': 'test account',
|
'name': 'test account',
|
||||||
})
|
})
|
||||||
self.analytic_account2 = self.env['account.analytic.account'].create({
|
analytic_account2 = self.env['account.analytic.account'].create({
|
||||||
'name': 'test account2',
|
'name': 'test account2',
|
||||||
})
|
})
|
||||||
|
|
||||||
self.expense.expense_line_ids.write({'analytic_account_id': False})
|
# post expense and get move ready at expense.account_move_id.id
|
||||||
|
expense = self.env['hr.expense.sheet'].create({
|
||||||
super(TestWizard, self).test_expense_change_basic()
|
'name': 'Expense for John Smith',
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'expense_line_ids': [
|
||||||
|
(0, 0, {
|
||||||
|
'name': 'Coffee Expenses',
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'product_id': self.product_expense.id,
|
||||||
|
'unit_amount': 10.00,
|
||||||
|
'tax_ids': [(6, 0, [self.tax.id])],
|
||||||
|
'analytic_account_id': False,
|
||||||
|
}),
|
||||||
|
(0, 0, {
|
||||||
|
'name': 'Car Travel Expenses',
|
||||||
|
'employee_id': self.employee.id,
|
||||||
|
'product_id': self.product_expense.id,
|
||||||
|
'unit_amount': 700.00,
|
||||||
|
'tax_ids': [(6, 0, [self.tax.id])],
|
||||||
|
'analytic_account_id': False,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
# expense_line = self.env['hr.expense'].create()
|
||||||
|
for expense_line in expense.expense_line_ids:
|
||||||
|
expense_line._onchange_product_id()
|
||||||
|
# Submitted to Manager
|
||||||
|
expense.action_submit_sheet()
|
||||||
|
# Approve
|
||||||
|
expense.approve_expense_sheets()
|
||||||
|
# Create Expense Entries
|
||||||
|
expense.action_sheet_move_create()
|
||||||
|
self.assertEquals(expense.state, 'post', 'Expense is not in Waiting Payment state')
|
||||||
|
|
||||||
# Tests Adding an Analytic Account
|
# Tests Adding an Analytic Account
|
||||||
self.assertFalse(self.expense.expense_line_ids.analytic_account_id)
|
self.assertFalse(expense.expense_line_ids.analytic_account_id)
|
||||||
ctx = {'active_model': 'hr.expense', 'active_ids': self.expense.expense_line_ids.ids}
|
ctx = {'active_model': 'hr.expense', 'active_ids': [expense.expense_line_ids[0].id]}
|
||||||
change = self.env['hr.expense.change'].with_context(ctx).create({})
|
change = self.env['hr.expense.change'].with_context(ctx).create({})
|
||||||
change.analytic_account_id = self.analytic_account
|
change.analytic_account_id = analytic_account
|
||||||
change.affect_change()
|
change.affect_change()
|
||||||
self.assertEqual(self.expense.expense_line_ids.analytic_account_id, self.analytic_account)
|
self.assertEqual(expense.expense_line_ids.analytic_account_id, analytic_account)
|
||||||
|
|
||||||
# Tests Changing
|
# Tests Changing
|
||||||
change.analytic_account_id = self.analytic_account2
|
change.analytic_account_id = analytic_account2
|
||||||
change.affect_change()
|
change.affect_change()
|
||||||
self.assertEqual(self.expense.expense_line_ids.analytic_account_id, self.analytic_account2)
|
self.assertEqual(expense.expense_line_ids.analytic_account_id, analytic_account2)
|
||||||
|
|
||||||
# Tests Removing
|
# Tests Removing
|
||||||
change.analytic_account_id = False
|
change.analytic_account_id = False
|
||||||
change.affect_change()
|
change.affect_change()
|
||||||
self.assertFalse(self.expense.expense_line_ids.analytic_account_id)
|
self.assertFalse(expense.expense_line_ids.analytic_account_id)
|
||||||
|
|||||||
@@ -47,9 +47,12 @@ class ExpenseChangeWizard(models.TransientModel):
|
|||||||
def _affect_analytic_change(self, old_analytic_id):
|
def _affect_analytic_change(self, old_analytic_id):
|
||||||
expenses_to_affect = self._find_expenses_to_write_analytic(old_analytic_id)
|
expenses_to_affect = self._find_expenses_to_write_analytic(old_analytic_id)
|
||||||
if expenses_to_affect:
|
if expenses_to_affect:
|
||||||
|
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})
|
expenses_to_affect.write({'analytic_account_id': self.analytic_account_id.id})
|
||||||
|
|
||||||
lines_to_affect = self.expense_id.sheet_id.account_move_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)
|
.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.write({'analytic_account_id': self.analytic_account_id.id})
|
||||||
lines_to_affect.create_analytic_lines()
|
lines_to_affect.create_analytic_lines()
|
||||||
|
self.expense_id.sheet_id.write({'state': prev_state})
|
||||||
|
|||||||
Reference in New Issue
Block a user