mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-23 11:32:05 +02:00
19.0 vanilla
This commit is contained in:
parent
a1137a1456
commit
e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions
|
|
@ -1,7 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from datetime import datetime
|
||||
|
||||
from odoo import Command
|
||||
from freezegun import freeze_time
|
||||
|
||||
from odoo import Command, fields
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
from odoo.addons.mail.tests.common import mail_new_test_user
|
||||
|
|
@ -10,8 +12,11 @@ from odoo.addons.mail.tests.common import mail_new_test_user
|
|||
class TestExpenseCommon(AccountTestInvoicingCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref=None):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
cls.company_data_2 = cls.setup_other_company()
|
||||
cls.other_currency = cls.setup_other_currency('HRK')
|
||||
|
||||
group_expense_manager = cls.env.ref('hr_expense.group_hr_expense_manager')
|
||||
|
||||
|
|
@ -22,7 +27,7 @@ class TestExpenseCommon(AccountTestInvoicingCommon):
|
|||
email='expense_user_employee@example.com',
|
||||
notification_type='email',
|
||||
groups='base.group_user',
|
||||
company_ids=[(6, 0, cls.env.companies.ids)],
|
||||
company_ids=[Command.set(cls.env.companies.ids)],
|
||||
)
|
||||
cls.expense_user_manager = mail_new_test_user(
|
||||
cls.env,
|
||||
|
|
@ -31,38 +36,39 @@ class TestExpenseCommon(AccountTestInvoicingCommon):
|
|||
email='expense_manager_1@example.com',
|
||||
notification_type='email',
|
||||
groups='base.group_user,hr_expense.group_hr_expense_manager',
|
||||
company_ids=[(6, 0, cls.env.companies.ids)],
|
||||
)
|
||||
cls.accountant_user = mail_new_test_user(
|
||||
cls.env,
|
||||
name='Accountant',
|
||||
login='accountant_1',
|
||||
email='accountant_1@example.com',
|
||||
notification_type='email',
|
||||
groups='account.group_account_user',
|
||||
company_ids=[(6, 0, cls.env.companies.ids)],
|
||||
company_ids=[Command.set(cls.env.companies.ids)],
|
||||
)
|
||||
|
||||
cls.expense_employee = cls.env['hr.employee'].create({
|
||||
cls.expense_user_manager_2 = mail_new_test_user(
|
||||
cls.env,
|
||||
name='Expense manager',
|
||||
login='expense_manager_2',
|
||||
email='expense_manager_2@example.com',
|
||||
notification_type='email',
|
||||
groups='base.group_user,hr_expense.group_hr_expense_manager',
|
||||
company_ids=[Command.set(cls.env.companies.ids)],
|
||||
)
|
||||
|
||||
cls.expense_employee = cls.env['hr.employee'].sudo().create({
|
||||
'name': 'expense_employee',
|
||||
'user_id': cls.expense_user_employee.id,
|
||||
'address_home_id': cls.expense_user_employee.partner_id.id,
|
||||
'address_id': cls.expense_user_employee.partner_id.id,
|
||||
})
|
||||
|
||||
cls.product_zero_cost = cls.env['product.product'].create({
|
||||
'name': 'General',
|
||||
'default_code': 'EXP_GEN',
|
||||
'standard_price': 0.0,
|
||||
'can_be_expensed': True,
|
||||
})
|
||||
'expense_manager_id': cls.expense_user_manager.id,
|
||||
'work_contact_id': cls.expense_user_employee.partner_id.id,
|
||||
'bank_account_ids': [
|
||||
Command.create({
|
||||
'acc_number': 'BE68539007547034',
|
||||
'allow_out_payment': True,
|
||||
'partner_id': cls.expense_user_employee.partner_id.id,
|
||||
})]
|
||||
}).sudo(False)
|
||||
|
||||
cls.expense_employee.user_partner_id.parent_id = cls.env.company.partner_id
|
||||
|
||||
# Allow the current accounting user to access the expenses.
|
||||
cls.env.user.groups_id |= group_expense_manager
|
||||
cls.env.user.group_ids |= group_expense_manager
|
||||
|
||||
# Create analytic account
|
||||
cls.analytic_plan = cls.env['account.analytic.plan'].create({'name': 'Plan Test', 'company_id': False})
|
||||
cls.analytic_plan = cls.env['account.analytic.plan'].create({'name': 'Expense Plan Test'})
|
||||
cls.analytic_account_1 = cls.env['account.analytic.account'].create({
|
||||
'name': 'analytic_account_1',
|
||||
'plan_id': cls.analytic_plan.id,
|
||||
|
|
@ -72,6 +78,7 @@ class TestExpenseCommon(AccountTestInvoicingCommon):
|
|||
'plan_id': cls.analytic_plan.id,
|
||||
})
|
||||
|
||||
# Create product without cost
|
||||
cls.product_c = cls.env['product.product'].create({
|
||||
'name': 'product_c with no cost',
|
||||
'uom_id': cls.env.ref('uom.product_uom_dozen').id,
|
||||
|
|
@ -81,7 +88,64 @@ class TestExpenseCommon(AccountTestInvoicingCommon):
|
|||
'taxes_id': [Command.set((cls.tax_sale_a + cls.tax_sale_b).ids)],
|
||||
'supplier_taxes_id': [Command.set((cls.tax_purchase_a + cls.tax_purchase_b).ids)],
|
||||
'can_be_expensed': True,
|
||||
'default_code': 'product_c',
|
||||
})
|
||||
|
||||
# Ensure products can be expensed.
|
||||
# Ensure Invoicing tests products can be expensed and their code is properly set.
|
||||
(cls.product_a + cls.product_b).write({'can_be_expensed': True})
|
||||
cls.product_a.default_code = 'product_a'
|
||||
cls.product_b.default_code = 'product_b'
|
||||
|
||||
cls.frozen_today = datetime(year=2022, month=1, day=25, hour=0, minute=0, second=0)
|
||||
|
||||
# create expense account
|
||||
cls.expense_account = cls.env['account.account'].create({
|
||||
'code': '610010',
|
||||
'name': 'Expense Account 1'
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def create_expenses(cls, values=None):
|
||||
if values is None or isinstance(values, dict):
|
||||
values = [values or {}]
|
||||
|
||||
default_values = {
|
||||
'employee_id': cls.expense_employee.id,
|
||||
'date': cls.frozen_today.isoformat(),
|
||||
'company_id': cls.company_data['company'].id,
|
||||
'currency_id': cls.company_data['currency'].id,
|
||||
}
|
||||
|
||||
default_product_values = {
|
||||
'product_id': cls.product_c.id,
|
||||
'total_amount_currency': 1000.00,
|
||||
}
|
||||
create_values = []
|
||||
for value_dict in values:
|
||||
if 'product_id' not in value_dict:
|
||||
default_values.update(default_product_values)
|
||||
value_dict = {**default_values, **(value_dict or {})}
|
||||
create_values.append(value_dict)
|
||||
return cls.env['hr.expense'].create(create_values).sorted()
|
||||
|
||||
@classmethod
|
||||
def post_expenses_with_wizard(cls, expenses, journal=None, date=None):
|
||||
action = expenses.action_post()
|
||||
if action:
|
||||
wizard = expenses.env['hr.expense.post.wizard'].with_context(action['context']).browse(action['res_id'])
|
||||
if journal:
|
||||
wizard.employee_journal_id = journal.id
|
||||
wizard.accounting_date = date or fields.Date.context_today(expenses)
|
||||
wizard.action_post_entry()
|
||||
|
||||
def get_new_payment(self, expenses, amount):
|
||||
""" Helper to create payments """
|
||||
ctx = {'active_model': 'account.move', 'active_ids': expenses.account_move_id.ids}
|
||||
with freeze_time(self.frozen_today):
|
||||
payment_register = self.env['account.payment.register'].with_context(**ctx).create({
|
||||
'amount': amount,
|
||||
'journal_id': self.company_data['default_journal_bank'].id,
|
||||
'payment_method_line_id': self.inbound_payment_method_line.id,
|
||||
})
|
||||
self.assertEqual(payment_register.partner_bank_id.partner_id, expenses.employee_id.work_contact_id)
|
||||
return payment_register._create_payments()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue