Skip to content
Snippets Groups Projects
Commit 93c4cc3c authored by Kartik Chavda's avatar Kartik Chavda Committed by ravb-odoo
Browse files

[FIX] sale_timesheet: fix activity 'upsell' when threshold is not exceed


Description of the issue/feature this PR addresses:
In sale, when threshold value of product is not exceed than upsell activity is
created while creating invoice. upsell activity is only create when threshold
value exceed otherwise not.

Current behavior before PR:
When creating an invoice, an 'upsell' activity is created on the sales order and
assigned to the salesperson even if the threshold has not been exceeded.

Desired behavior after PR is merged:
Do not create a 'upsell' activity unless threshold is exceeded.

Fix:
super class is invoke before checking the upsell and create activity. so
now, we prevent super method from creating upsell activity via passing
`mail_activity_automation_skip` context.

task- 3330815

closes odoo/odoo#126017

X-original-commit: 9232093d
Signed-off-by: default avatarXavier Bol (xbo) <xbo@odoo.com>
parent 550ca067
Branches
Tags
No related merge requests found
......@@ -55,9 +55,8 @@ class SaleOrder(models.Model):
sale_order.timesheet_total_duration = round(total_time)
def _compute_field_value(self, field):
super()._compute_field_value(field)
if field.name != 'invoice_status' or self.env.context.get('mail_activity_automation_skip'):
return
return super()._compute_field_value(field)
# Get SOs which their state is not equal to upselling and if at least a SOL has warning prepaid service upsell set to True and the warning has not already been displayed
upsellable_orders = self.filtered(lambda so:
......@@ -66,12 +65,14 @@ class SaleOrder(models.Model):
and so.id
and (so.user_id or so.partner_id.user_id) # salesperson needed to assign upsell activity
)
super(SaleOrder, upsellable_orders.with_context(mail_activity_automation_skip=True))._compute_field_value(field)
for order in upsellable_orders:
upsellable_lines = order._get_prepaid_service_lines_to_upsell()
if upsellable_lines:
order._create_upsell_activity()
# We want to display only one time the warning for each SOL
upsellable_lines.write({'has_displayed_warning_upsell': True})
super(SaleOrder, self - upsellable_orders)._compute_field_value(field)
def _get_prepaid_service_lines_to_upsell(self):
""" Retrieve all sols which need to display an upsell activity warning in the SO
......
......@@ -84,3 +84,72 @@ class TestUpsellWarning(TestCommonSaleTimesheet):
# 5) Check if the SO has an 'sale.mail_act_sale_upsell' activity.
self.assertEqual(len(so.activity_search(['sale.mail_act_sale_upsell'])), 1, 'A upsell warning should appear in the SO.')
def test_display_upsell_warning_when_invoiced(self):
""" Test to display an upsell warning when threshold value (10000%) exceed while creating invoice.
We display an upsell warning in SO when this following condition is satisfy in its SOL:
(qty_delivered / product_uom_qty) >= product_id.service_upsell_threshold
Test Case:
=========
1) Configure the upsell warning in prepaid service product
2) Create SO with a SOL containing this updated product,
3) Create Project and Task,
4) Timesheet in the task to satisfy the condition for the SOL to display an upsell warning,
5) Create Invoice of the SO,
6) Check if the SO has an 'sale.mail_act_sale_upsell' activity.
"""
# 1) Configure the upsell warning in prepaid service product with 100 (10000%)
self.product_order_timesheet1.write({
'service_upsell_threshold': 100,
})
# 2) Create SO with a SOL containing this updated product
so = self.env['sale.order'].create({
'partner_id': self.partner_a.id,
'partner_invoice_id': self.partner_a.id,
'partner_shipping_id': self.partner_a.id,
})
self.env['sale.order.line'].create({
'order_id': so.id,
'name': self.product_order_timesheet1.name,
'product_id': self.product_order_timesheet1.id,
'product_uom_qty': 1,
'price_unit': self.product_order_timesheet1.list_price,
})
so.action_confirm()
# 3) Create Project and Task
project = self.env['project.project'].create({
'name': 'Project',
'allow_timesheets': True,
'allow_billable': True,
'partner_id': self.partner_a.id,
'analytic_account_id': self.analytic_account_sale.id,
})
task = self.env['project.task'].create({
'name': 'Task Test',
'project_id': project.id,
'sale_line_id': so.order_line.id
})
# 4) Timesheet in the task to satisfy the condition for the SOL to display an upsell warning
self.env['account.analytic.line'].create({
'name': 'Test Line',
'unit_amount': 50,
'employee_id': self.employee_manager.id,
'project_id': project.id,
'task_id': task.id,
})
so.order_line._compute_qty_delivered()
# 5) Create Invoice of the SO
so._create_invoices()
# Normally this method is called at the end of _get_invoice_status and other compute method. Here, we simulate for invoice_status field
so._compute_field_value(so._fields['invoice_status'])
# 6) Check if the SO has an 'sale.mail_act_sale_upsell' activity.
self.assertEqual(len(so.activity_search(['sale.mail_act_sale_upsell'])), 0, 'No upsell warning should appear in the SO.')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment