[FIX] sale{,_timesheet}: Generate activity on duplicated sales order

Steps to reproduce:
- Create a service product with Project & Task created on order
- Make an SO for 1 hour and confirm it
- In the task add 5 hours of timesheet
- An activity should be made in the SO
- Copy the SO and add the 5 hour of timesheet like before

Issue:
No activity is made.

opw-3660169

closes odoo/odoo#148929

X-original-commit: 1f7844f9384e3d78599923c2487ae938de9cddfc
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
Signed-off-by: Mattis Megevand (mmeg) <mmeg@odoo.com>
This commit is contained in:
Mattis Megevand (mmeg)
2024-01-11 08:46:58 +00:00
parent 61ca757fd1
commit 980e6a53b2
2 changed files with 114 additions and 1 deletions
+1 -1
View File
@@ -154,7 +154,7 @@ class SaleOrderLine(models.Model):
analytic_line_ids = fields.One2many(domain=[('project_id', '=', False)]) # only analytic lines, not timesheets (since this field determine if SO line came from expense)
remaining_hours_available = fields.Boolean(compute='_compute_remaining_hours_available', compute_sudo=True)
remaining_hours = fields.Float('Remaining Hours on SO', compute='_compute_remaining_hours', compute_sudo=True, store=True)
has_displayed_warning_upsell = fields.Boolean('Has Displayed Warning Upsell')
has_displayed_warning_upsell = fields.Boolean('Has Displayed Warning Upsell', copy=False)
timesheet_ids = fields.One2many('account.analytic.line', 'so_line', domain=[('project_id', '!=', False)], string='Timesheets')
@api.depends('remaining_hours_available', 'remaining_hours')
@@ -693,6 +693,119 @@ class TestSaleTimesheet(TestCommonSaleTimesheet):
])
self.assertEqual(len(message_sent), 1, 'Sale Timesheet: An email should only be sent to the saleperson when the state of the sale order change to upselling')
def test_timesheet_upsell_copied_so(self):
""" Test that copying a SO which had an upsell activity still create an upsell activity on the copy. """
sale_order = self.env['sale.order'].with_context(mail_notrack=True, mail_create_nolog=True).create({
'partner_id': self.partner_a.id,
'partner_invoice_id': self.partner_a.id,
'partner_shipping_id': self.partner_a.id,
'user_id': self.user_employee_company_B.id,
})
# create SO and confirm it
uom_days = self.env.ref('uom.product_uom_day')
sale_order_line = self.env['sale.order.line'].create({
'order_id': sale_order.id,
'product_id': self.product_order_timesheet3.id,
'product_uom': uom_days.id,
})
sale_order.action_confirm()
task = sale_order_line.task_id
# let's log some timesheets
self.env['account.analytic.line'].create({
'name': 'Test Line',
'project_id': task.project_id.id,
'task_id': task.id,
'unit_amount': 8,
'employee_id': self.employee_manager.id,
})
sale_order._create_invoices()
last_message_id = self.env['mail.message'].search([('model', '=', 'sale.order'), ('res_id', '=', sale_order.id)], limit=1).id or 0
self.env['account.analytic.line'].create({
'name': 'Test Line',
'project_id': task.project_id.id,
'task_id': task.id,
'unit_amount': 5,
'employee_id': self.employee_user.id,
})
self.assertEqual(sale_order.invoice_status, 'upselling', 'Sale Timesheet: "invoice on delivery" timesheets should not modify the invoice_status of the so')
message_sent = self.env['mail.message'].search([
('id', '>', last_message_id),
('subject', 'like', 'Upsell'),
('model', '=', 'sale.order'),
('res_id', '=', sale_order.id),
])
self.assertEqual(len(message_sent), 1, 'Sale Timesheet: An email should always be sent to the saleperson when the state of the sale order change to upselling')
self.env['account.analytic.line'].create({
'name': 'Test Line',
'project_id': task.project_id.id,
'task_id': task.id,
'unit_amount': 5,
'employee_id': self.employee_user.id,
})
message_sent = self.env['mail.message'].search([
('id', '>', last_message_id),
('subject', 'like', 'Upsell'),
('model', '=', 'sale.order'),
('res_id', '=', sale_order.id),
])
self.assertEqual(len(message_sent), 1, 'Sale Timesheet: An email should only be sent to the saleperson when the state of the sale order change to upselling')
sale_order = sale_order.copy()
sale_order.action_confirm()
task = sale_order.order_line.task_id
# let's log some timesheets
self.env['account.analytic.line'].create({
'name': 'Test Line',
'project_id': task.project_id.id,
'task_id': task.id,
'unit_amount': 8,
'employee_id': self.employee_manager.id,
})
sale_order._create_invoices()
last_message_id = self.env['mail.message'].search([('model', '=', 'sale.order'), ('res_id', '=', sale_order.id)], limit=1).id or 0
self.env['account.analytic.line'].create({
'name': 'Test Line',
'project_id': task.project_id.id,
'task_id': task.id,
'unit_amount': 5,
'employee_id': self.employee_user.id,
})
self.assertEqual(sale_order.invoice_status, 'upselling', 'Sale Timesheet: "invoice on delivery" timesheets should not modify the invoice_status of the so')
message_sent = self.env['mail.message'].search([
('id', '>', last_message_id),
('subject', 'like', 'Upsell'),
('model', '=', 'sale.order'),
('res_id', '=', sale_order.id),
])
self.assertEqual(len(message_sent), 1, 'Sale Timesheet: An email should always be sent to the saleperson when the state of the sale order change to upselling')
self.env['account.analytic.line'].create({
'name': 'Test Line',
'project_id': task.project_id.id,
'task_id': task.id,
'unit_amount': 5,
'employee_id': self.employee_user.id,
})
message_sent = self.env['mail.message'].search([
('id', '>', last_message_id),
('subject', 'like', 'Upsell'),
('model', '=', 'sale.order'),
('res_id', '=', sale_order.id),
])
self.assertEqual(len(message_sent), 1, 'Sale Timesheet: An email should only be sent to the saleperson when the state of the sale order change to upselling')
def test_unlink_timesheet(self):
sale_order = self.env['sale.order'].create({
'partner_id': self.partner_a.id,