[IMP] sale_timesheet: remove project of a Sales Order
The project of a SO will not be used anymore, as we planned to have a sale order creating multiple projects. The concept of 'only project from SO' does not make sense.
This commit is contained in:
@@ -18,7 +18,6 @@ class SaleOrder(models.Model):
|
||||
tasks_ids = fields.Many2many('project.task', compute='_compute_tasks_ids', string='Tasks associated to this sale')
|
||||
tasks_count = fields.Integer(string='Tasks', compute='_compute_tasks_ids', groups="project.group_project_user")
|
||||
|
||||
project_project_id = fields.Many2one('project.project', compute='_compute_project_project_id', string='Project associated to this sale')
|
||||
project_ids = fields.Many2many('project.project', compute="_compute_project_ids", string='Projects', copy=False, groups="project.group_project_user", help="Projects used in this sales order.")
|
||||
|
||||
@api.multi
|
||||
@@ -42,18 +41,10 @@ class SaleOrder(models.Model):
|
||||
order.tasks_count = len(order.tasks_ids)
|
||||
|
||||
@api.multi
|
||||
@api.depends('analytic_account_id.project_ids')
|
||||
def _compute_project_project_id(self):
|
||||
for order in self:
|
||||
order.project_project_id = self.env['project.project'].search([('analytic_account_id', '=', order.analytic_account_id.id)])
|
||||
|
||||
@api.multi
|
||||
@api.depends('order_line.product_id', 'project_project_id')
|
||||
@api.depends('order_line.product_id')
|
||||
def _compute_project_ids(self):
|
||||
for order in self:
|
||||
projects = order.order_line.mapped('product_id.project_id')
|
||||
if order.project_project_id:
|
||||
projects |= order.project_project_id
|
||||
order.project_ids = projects
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -106,7 +106,7 @@ class TestSaleService(TestCommonSaleTimesheetNoChart):
|
||||
# let's log some timesheets
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': self.sale_order.project_project_id.id,
|
||||
'project_id': task.project_id.id,
|
||||
'task_id': task.id,
|
||||
'unit_amount': 16,
|
||||
'employee_id': self.employee_manager.id,
|
||||
@@ -115,7 +115,7 @@ class TestSaleService(TestCommonSaleTimesheetNoChart):
|
||||
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': self.sale_order.project_project_id.id,
|
||||
'project_id': task.project_id.id,
|
||||
'task_id': task.id,
|
||||
'unit_amount': 24,
|
||||
'employee_id': self.employee_user.id,
|
||||
|
||||
@@ -58,7 +58,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
task_serv2 = self.env['project.task'].search([('sale_line_id', '=', so_line_ordered_global_project.id)])
|
||||
|
||||
self.assertEqual(sale_order.tasks_count, 1, "One task should have been created on SO confirmation")
|
||||
self.assertTrue(sale_order.project_project_id, "A project should have been created by the SO, when confirmed.")
|
||||
self.assertTrue(sale_order.project_ids, "A project should have been created by the SO, when confirmed.")
|
||||
|
||||
# create invoice
|
||||
sale_order.action_invoice_create()
|
||||
@@ -66,7 +66,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
# let's log some timesheets (on the project created by so_line_ordered_project_only)
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': sale_order.project_project_id.id,
|
||||
'project_id': task_serv2.project_id.id,
|
||||
'task_id': task_serv2.id,
|
||||
'unit_amount': 10.5,
|
||||
'employee_id': self.employee_user.id,
|
||||
@@ -76,7 +76,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': sale_order.project_project_id.id,
|
||||
'project_id': task_serv2.project_id.id,
|
||||
'task_id': task_serv2.id,
|
||||
'unit_amount': 39.5,
|
||||
'employee_id': self.employee_user.id,
|
||||
@@ -86,7 +86,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': sale_order.project_project_id.id,
|
||||
'project_id': task_serv2.project_id.id,
|
||||
'unit_amount': 10,
|
||||
'employee_id': self.employee_user.id,
|
||||
})
|
||||
@@ -95,7 +95,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
# log timesheet on task in global project (higher than the initial ordrered qty)
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': sale_order.project_project_id.id,
|
||||
'project_id': task_serv2.project_id.id,
|
||||
'task_id': task_serv2.id,
|
||||
'unit_amount': 5,
|
||||
'employee_id': self.employee_user.id,
|
||||
@@ -112,6 +112,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
'order_id': sale_order.id,
|
||||
})
|
||||
task_serv3 = self.env['project.task'].search([('sale_line_id', '=', so_line_ordered_task_new_project.id)])
|
||||
project_serv2 = self.env['project.project'].search([('sale_line_id', '=', so_line_ordered_project_only.id)])
|
||||
self.assertEqual(sale_order.invoice_status, 'to invoice', 'Sale Timesheet: Adding a new service line (so line) should put the SO in "to invocie" state.')
|
||||
self.assertEqual(sale_order.tasks_count, 2, "Two tasks (1 per SO line) should have been created on SO confirmation")
|
||||
|
||||
@@ -120,7 +121,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
invoice = self.env['account.invoice'].browse(invoice_id)
|
||||
self.assertEqual(len(sale_order.invoice_ids), 2, "A second invoice should have been created from the SO")
|
||||
self.assertTrue(float_is_zero(invoice.amount_total - so_line_ordered_task_new_project.price_unit * 3, precision_digits=2), 'Sale: invoice generation on timesheets product is wrong')
|
||||
self.assertEqual(sale_order.project_project_id, task_serv3.project_id, "When creating task in new project, the task should be in SO project (if already exists), otherwise it created one.")
|
||||
self.assertEqual(project_serv2, task_serv3.project_id, "When creating task in new project, the task should be in SO project (if already exists), otherwise it created one.")
|
||||
|
||||
def test_timesheet_delivery(self):
|
||||
""" Test timesheet invoicing with 'invoice on delivery' timetracked products
|
||||
@@ -161,6 +162,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
sale_order.action_confirm()
|
||||
task_serv2 = self.env['project.task'].search([('sale_line_id', '=', so_line_deliver_global_project.id)])
|
||||
task_serv3 = self.env['project.task'].search([('sale_line_id', '=', so_line_deliver_task_project.id)])
|
||||
project_serv3 = self.env['project.project'].search([('sale_line_id', '=', so_line_deliver_task_project.id)])
|
||||
|
||||
self.assertEqual(task_serv2.project_id, self.project_global, "Sale Timesheet: task should be created in global project")
|
||||
self.assertTrue(task_serv2, "Sale Timesheet: on SO confirmation, a task should have been created in global project")
|
||||
@@ -212,12 +214,12 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
'price_unit': self.product_delivery_timesheet4.list_price,
|
||||
'order_id': sale_order.id,
|
||||
})
|
||||
self.assertEqual(sale_order.project_project_id, task_serv3.project_id, "SO should not have create a second project, since so line 3 already create one project for the SO")
|
||||
self.assertEqual(project_serv3, task_serv3.project_id, "SO should not have create a second project, since so line 3 already create one project for the SO")
|
||||
|
||||
# let's log some timesheets on the project
|
||||
self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': sale_order.project_project_id.id, # global project
|
||||
'project_id': project_serv3.id, # global project
|
||||
'unit_amount': 7,
|
||||
'employee_id': self.employee_user.id,
|
||||
})
|
||||
@@ -253,7 +255,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
|
||||
# confirm SO
|
||||
sale_order.action_confirm()
|
||||
self.assertTrue(sale_order.project_project_id, "Sales Order should have create a project")
|
||||
self.assertTrue(sale_order.project_ids, "Sales Order should have create a project")
|
||||
self.assertEqual(sale_order.invoice_status, 'no', 'Sale Timesheet: manually product should not need to be invoiced on so confirmation')
|
||||
|
||||
# let's log some timesheets (on task and project)
|
||||
@@ -267,7 +269,7 @@ class TestSaleTimesheet(TestCommonSaleTimesheetNoChart):
|
||||
|
||||
timesheet2 = self.env['account.analytic.line'].create({
|
||||
'name': 'Test Line',
|
||||
'project_id': sale_order.project_project_id.id, # global project
|
||||
'project_id': self.project_global.id, # global project
|
||||
'unit_amount': 3,
|
||||
'employee_id': self.employee_manager.id,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user