Skip to content
Permalink
Browse files

[IMP] sale_timesheet: factorize common class tests to be reused

Impacted modules: sale_timesheet and sale_project_timesheet

All tests were moved from sale_timesheet to sale_project_timesheet to avoid
rewrite them all to remove the project dependency. However, some methods of
the common class tests (the ones generating test data) can be usefull for
other module.
This commit proposes a factorization of some part of those methods, in order
to be reuse in other modules (like timesheet_grid_sale).

Task-1923949
  • Loading branch information...
jem-odoo committed Jan 22, 2019
1 parent d20de4f commit 15034ebf233cfc74758f98d3115beed4b19825b2
@@ -1,33 +1,17 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.sale.tests.test_sale_common import TestCommonSaleNoChart
from odoo.addons.sale_timesheet.tests.common import TestCommonSaleTimesheetNoChart


class TestCommonSaleTimesheetNoChart(TestCommonSaleNoChart):

@classmethod
def setUpEmployees(cls):
# Create employees
cls.employee_user = cls.env['hr.employee'].create({
'name': 'Employee User',
'timesheet_cost': 15,
})
cls.employee_manager = cls.env['hr.employee'].create({
'name': 'Employee Manager',
'timesheet_cost': 45,
})
class TestCommonSaleProjectTimesheetNoChart(TestCommonSaleTimesheetNoChart):

@classmethod
def setUpServiceProducts(cls):
""" Create Service product for all kind, with each tracking policy. """
# Account and project
cls.account_sale = cls.env['account.account'].create({
'code': 'SERV-2020',
'name': 'Product Sales - (test)',
'reconcile': True,
'user_type_id': cls.env.ref('account.data_account_type_revenue').id,
})
super(TestCommonSaleProjectTimesheetNoChart, cls).setUpServiceProducts()

# analytic account
cls.analytic_account_sale = cls.env['account.analytic.account'].create({
'name': 'Project for selling timesheet - AA',
'code': 'AA-2030'
@@ -53,21 +37,7 @@ def setUpServiceProducts(cls):
uom_hour = cls.env.ref('uom.product_uom_hour')

# -- ordered quantities (ordered, timesheet)
cls.product_order_timesheet1 = cls.env['product.product'].create({
'name': "Service Ordered, create no task",
'standard_price': 11,
'list_price': 13,
'type': 'service',
'invoice_policy': 'order',
'uom_id': uom_hour.id,
'uom_po_id': uom_hour.id,
'default_code': 'SERV-ORDERED1',
'service_type': 'timesheet',
'service_tracking': 'no',
'project_id': False,
'taxes_id': False,
'property_account_income_id': cls.account_sale.id,
})
# Note: cls.product_order_timesheet1 is tracked by timesheet but without creating task
cls.product_order_timesheet2 = cls.env['product.product'].create({
'name': "Service Ordered, create task in global project",
'standard_price': 30,
@@ -131,21 +101,7 @@ def setUpServiceProducts(cls):
})

# -- timesheet on tasks (delivered, timesheet)
cls.product_delivery_timesheet1 = cls.env['product.product'].create({
'name': "Service delivered, create no task",
'standard_price': 11,
'list_price': 13,
'type': 'service',
'invoice_policy': 'delivery',
'uom_id': uom_hour.id,
'uom_po_id': uom_hour.id,
'default_code': 'SERV-DELI1',
'service_type': 'timesheet',
'service_tracking': 'no',
'project_id': False,
'taxes_id': False,
'property_account_income_id': cls.account_sale.id,
})
# Note: cls.product_delivery_timesheet1 is tracked by timesheet but without creating task
cls.product_delivery_timesheet2 = cls.env['product.product'].create({
'name': "Service delivered, create task in global project",
'standard_price': 30,
@@ -209,21 +165,7 @@ def setUpServiceProducts(cls):
})

# -- milestones (delivered, manual)
cls.product_delivery_manual1 = cls.env['product.product'].create({
'name': "Service delivered, create no task",
'standard_price': 11,
'list_price': 13,
'type': 'service',
'invoice_policy': 'delivery',
'uom_id': uom_hour.id,
'uom_po_id': uom_hour.id,
'default_code': 'SERV-DELI1',
'service_type': 'manual',
'service_tracking': 'no',
'project_id': False,
'taxes_id': False,
'property_account_income_id': cls.account_sale.id,
})
# Note: cls.product_delivery_manual1 is tracked manual does not create task nor project
cls.product_delivery_manual2 = cls.env['product.product'].create({
'name': "Service delivered, create task in global project",
'standard_price': 30,
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleTimesheetNoChart
from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleProjectTimesheetNoChart
from odoo.exceptions import UserError


class TestProjectBilling(TestCommonSaleTimesheetNoChart):
class TestProjectBilling(TestCommonSaleProjectTimesheetNoChart):
""" This test suite provide checks for miscellaneous small things. """

@classmethod
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleTimesheetNoChart
from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleProjectTimesheetNoChart


class TestReInvoice(TestCommonSaleTimesheetNoChart):
class TestReInvoice(TestCommonSaleProjectTimesheetNoChart):

@classmethod
def setUpClass(cls):
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tools import float_is_zero, float_compare
from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleTimesheetNoChart
from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleProjectTimesheetNoChart


class TestReporting(TestCommonSaleTimesheetNoChart):
class TestReporting(TestCommonSaleProjectTimesheetNoChart):

@classmethod
def setUpClass(cls):
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleTimesheetNoChart
from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleProjectTimesheetNoChart
from odoo.exceptions import UserError, ValidationError


class TestSaleService(TestCommonSaleTimesheetNoChart):
class TestSaleService(TestCommonSaleProjectTimesheetNoChart):
""" This test suite provide checks for miscellaneous small things. """

@classmethod
@@ -3,10 +3,10 @@
from odoo.tools import float_is_zero
from odoo.exceptions import UserError

from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleTimesheetNoChart
from odoo.addons.sale_project_timesheet.tests.common import TestCommonSaleProjectTimesheetNoChart


class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
class TestSaleTimesheet(TestCommonSaleProjectTimesheetNoChart):
""" This test suite provide tests for the 3 main flows of selling services:
- Selling services based on ordered quantities
- Selling timesheet based on delivered quantities
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import common
@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.sale.tests.test_sale_common import TestCommonSaleNoChart


class TestCommonSaleTimesheetNoChart(TestCommonSaleNoChart):

@classmethod
def setUpEmployees(cls):
# Create employees
cls.employee_user = cls.env['hr.employee'].create({
'name': 'Employee User',
'timesheet_cost': 15,
})
cls.employee_manager = cls.env['hr.employee'].create({
'name': 'Employee Manager',
'timesheet_cost': 45,
})

@classmethod
def setUpServiceProducts(cls):
""" Create Service product for all kind, with each tracking policy. """
# Account and project
cls.account_sale = cls.env['account.account'].create({
'code': 'SERV-2020',
'name': 'Product Sales - (test)',
'reconcile': True,
'user_type_id': cls.env.ref('account.data_account_type_revenue').id,
})

# Create service products
uom_hour = cls.env.ref('uom.product_uom_hour')

# -- ordered quantities (ordered, timesheet)
cls.product_order_timesheet1 = cls.env['product.product'].create({
'name': "Service Ordered, create no task",
'standard_price': 11,
'list_price': 13,
'type': 'service',
'invoice_policy': 'order',
'uom_id': uom_hour.id,
'uom_po_id': uom_hour.id,
'default_code': 'SERV-ORDERED1',
'service_type': 'timesheet',
'service_tracking': 'no',
'project_id': False,
'taxes_id': False,
'property_account_income_id': cls.account_sale.id,
})
# -- timesheet on tasks (delivered, timesheet)
cls.product_delivery_timesheet1 = cls.env['product.product'].create({
'name': "Service delivered, create no task",
'standard_price': 11,
'list_price': 13,
'type': 'service',
'invoice_policy': 'delivery',
'uom_id': uom_hour.id,
'uom_po_id': uom_hour.id,
'default_code': 'SERV-DELI1',
'service_type': 'timesheet',
'service_tracking': 'no',
'project_id': False,
'taxes_id': False,
'property_account_income_id': cls.account_sale.id,
})

# -- milestones (delivered, manual)
cls.product_delivery_manual1 = cls.env['product.product'].create({
'name': "Service delivered, create no task",
'standard_price': 11,
'list_price': 13,
'type': 'service',
'invoice_policy': 'delivery',
'uom_id': uom_hour.id,
'uom_po_id': uom_hour.id,
'default_code': 'SERV-DELI1',
'service_type': 'manual',
'service_tracking': 'no',
'project_id': False,
'taxes_id': False,
'property_account_income_id': cls.account_sale.id,
})

0 comments on commit 15034eb

Please sign in to comment.
You can’t perform that action at this time.