mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-26 11:52:06 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -10,7 +10,7 @@ from odoo.tests import tagged
|
|||
class TestSaleTimesheetMargin(TestCommonSaleTimesheet):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSaleTimesheetMargin, self).setUp()
|
||||
super().setUp()
|
||||
uom_day_id = self.ref('uom.product_uom_day')
|
||||
self.uom_day = self.env['uom.uom'].browse(uom_day_id)
|
||||
self.product_1 = self.env['product.product'].create({
|
||||
|
|
@ -19,7 +19,30 @@ class TestSaleTimesheetMargin(TestCommonSaleTimesheet):
|
|||
'type': 'service',
|
||||
'invoice_policy': 'order',
|
||||
'uom_id': uom_day_id,
|
||||
'uom_po_id': uom_day_id,
|
||||
'default_code': 'SERV-ORDERED-DAY',
|
||||
'service_type': 'timesheet',
|
||||
'service_tracking': 'task_in_project',
|
||||
'project_id': False,
|
||||
'taxes_id': False,
|
||||
})
|
||||
self.product_2 = self.env['product.product'].create({
|
||||
'name': "Delivered Manual Service",
|
||||
'list_price': 1.0,
|
||||
'type': 'service',
|
||||
'invoice_policy': 'order',
|
||||
'uom_id': uom_day_id,
|
||||
'default_code': 'SERV-ORDERED-DAY',
|
||||
'service_type': 'timesheet',
|
||||
'service_tracking': 'task_in_project',
|
||||
'project_id': False,
|
||||
'taxes_id': False,
|
||||
})
|
||||
self.product_3 = self.env['product.product'].create({
|
||||
'name': "Delivered Milestones Service",
|
||||
'list_price': 1.0,
|
||||
'type': 'service',
|
||||
'invoice_policy': 'order',
|
||||
'uom_id': uom_day_id,
|
||||
'default_code': 'SERV-ORDERED-DAY',
|
||||
'service_type': 'timesheet',
|
||||
'service_tracking': 'task_in_project',
|
||||
|
|
@ -36,7 +59,7 @@ class TestSaleTimesheetMargin(TestCommonSaleTimesheet):
|
|||
Command.create({
|
||||
'product_id': self.product_1.id,
|
||||
'price_unit': 1.0,
|
||||
'product_uom': self.uom_day.id,
|
||||
'product_uom_id': self.uom_day.id,
|
||||
'product_uom_qty': 1.0,
|
||||
})],
|
||||
'partner_id': self.partner_b.id,
|
||||
|
|
@ -65,25 +88,63 @@ class TestSaleTimesheetMargin(TestCommonSaleTimesheet):
|
|||
self.assertEqual(sale_order.order_line.purchase_price, expected_cost, "Sale order line cost should be number of working hours on one day * timesheet cost of the employee set on the timesheet linked to the SOL.")
|
||||
|
||||
def test_no_recompute_purchase_price_not_timesheet(self):
|
||||
"""
|
||||
check that if a sale order line is linked to a task but the service is ordered_prepaid, delivered_manual
|
||||
or delivered_milestones, adding a timesheet line does not trigger a recomputation of purchase_price.
|
||||
We also check that the pruchase price of new sale order lines added after the confirmation
|
||||
is computed correctly.
|
||||
"""
|
||||
project = self.env['project.project'].create({
|
||||
'name': "Test",
|
||||
})
|
||||
self.product_1.write({
|
||||
'uom_id': self.ref('uom.product_uom_unit'),
|
||||
'uom_po_id': self.ref('uom.product_uom_unit'),
|
||||
'service_type': 'timesheet',
|
||||
'service_policy': 'ordered_prepaid',
|
||||
'service_tracking': 'task_global_project',
|
||||
'project_id': project.id,
|
||||
'standard_price': 2,
|
||||
})
|
||||
self.product_2.write({
|
||||
'uom_id': self.ref('uom.product_uom_unit'),
|
||||
'service_type': 'timesheet',
|
||||
'service_policy': 'delivered_manual',
|
||||
'service_tracking': 'task_global_project',
|
||||
'project_id': project.id,
|
||||
'standard_price': 2,
|
||||
})
|
||||
self.product_3.write({
|
||||
'uom_id': self.ref('uom.product_uom_unit'),
|
||||
'service_type': 'timesheet',
|
||||
'service_policy': 'delivered_milestones',
|
||||
'service_tracking': 'task_global_project',
|
||||
'project_id': project.id,
|
||||
'standard_price': 2,
|
||||
})
|
||||
simple_service = self.env['product.product'].create({
|
||||
'name': "Simple service",
|
||||
'list_price': 1.0,
|
||||
'type': 'service',
|
||||
'invoice_policy': 'order',
|
||||
'service_type': 'timesheet',
|
||||
'standard_price': 5,
|
||||
})
|
||||
sale_order = self.env['sale.order'].create({
|
||||
'name': 'Test_SO0002',
|
||||
'order_line': [
|
||||
Command.create({
|
||||
'product_id': self.product_1.id,
|
||||
'price_unit': 1.0,
|
||||
'product_uom': self.ref('uom.product_uom_unit'),
|
||||
'product_uom_qty': 1.0,
|
||||
}),
|
||||
Command.create({
|
||||
'product_id': self.product_2.id,
|
||||
'price_unit': 1.0,
|
||||
'product_uom_qty': 1.0,
|
||||
}),
|
||||
Command.create({
|
||||
'product_id': self.product_3.id,
|
||||
'price_unit': 1.0,
|
||||
'product_uom_qty': 1.0,
|
||||
})],
|
||||
'partner_id': self.partner_b.id,
|
||||
|
|
@ -93,7 +154,6 @@ class TestSaleTimesheetMargin(TestCommonSaleTimesheet):
|
|||
sale_order.order_line.purchase_price = 3
|
||||
# Confirm the sales order, create project and task.
|
||||
sale_order.action_confirm()
|
||||
|
||||
# Add timesheet line
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line 222',
|
||||
|
|
@ -101,9 +161,37 @@ class TestSaleTimesheetMargin(TestCommonSaleTimesheet):
|
|||
'amount': 1,
|
||||
'employee_id': self.employee_manager.id,
|
||||
'project_id': project.id,
|
||||
'task_id': sale_order.order_line.task_id.id,
|
||||
'task_id': sale_order.order_line[0].task_id.id,
|
||||
'account_id': self.analytic_account_sale.id,
|
||||
'so_line': sale_order.order_line.id,
|
||||
'so_line': sale_order.order_line[0].id,
|
||||
})
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line 333',
|
||||
'unit_amount': 2,
|
||||
'amount': 1,
|
||||
'employee_id': self.employee_manager.id,
|
||||
'project_id': project.id,
|
||||
'task_id': sale_order.order_line[1].task_id.id,
|
||||
'account_id': self.analytic_account_sale.id,
|
||||
'so_line': sale_order.order_line[1].id,
|
||||
})
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line 444',
|
||||
'unit_amount': 2,
|
||||
'amount': 1,
|
||||
'employee_id': self.employee_manager.id,
|
||||
'project_id': project.id,
|
||||
'task_id': sale_order.order_line[2].task_id.id,
|
||||
'account_id': self.analytic_account_sale.id,
|
||||
'so_line': sale_order.order_line[2].id,
|
||||
})
|
||||
self.env.flush_all()
|
||||
self.assertEqual(sale_order.order_line.purchase_price, 3)
|
||||
self.assertEqual(sale_order.order_line.filtered(lambda sol: sol.product_id == self.product_1).purchase_price, 3)
|
||||
self.assertEqual(sale_order.order_line.filtered(lambda sol: sol.product_id == self.product_2).purchase_price, 3)
|
||||
self.assertEqual(sale_order.order_line.filtered(lambda sol: sol.product_id == self.product_3).purchase_price, 3)
|
||||
sale_order.order_line = [Command.create({
|
||||
'product_id': simple_service.id,
|
||||
'price_unit': 1.0,
|
||||
'product_uom_qty': 1.0,
|
||||
})]
|
||||
self.assertEqual(sale_order.order_line.filtered(lambda sol: sol.product_id == simple_service).purchase_price, 5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue