Debian Codegraph @

addons/sale_crm/tests/test_sale_crm.py

raw symbols SCIP
1 from odoo.addons.crm.tests.common import TestCrmCommon
2 from odoo.fields import Command
3
4
5 class TestSaleCrm(TestCrmCommon):
6
7 def test_sale_crm_revenue(self):
8 """ Test the updation of the expected_revenue when the is confirmed.
9 If the expected_revenue of the lead is smaller than the total of quote which we are confirming, update it with that.
10 e.g. if the lead has a expected revenue of 40 $
11 Quotes - q1 = 45$
12 ===> The expected_revenue would be updated, from 40 to 45$.
13 """
14 product1, product2 = self.env['product.template'].create([{
15 'name': 'Test product1',
16 'list_price': 100.0,
17 }, {
18 'name': 'Test product2',
19 'list_price': 200.0,
20 }])
21
22 my_pricelist = self.env['product.pricelist'].create({
23 'name': 'Rupee',
24 'currency_id': self.ref('base.INR')
25 })
26 pricelist_expected_by_lead = self.env['product.pricelist'].create({
27 'name': 'Rupee',
28 'currency_id': self.ref('base.USD')
29 })
30
31 so_values = {
32 'partner_id': self.env.user.partner_id.id,
33 'opportunity_id': self.lead_1.id,
34 }
35 so1, so2 = self.env['sale.order'].create([{
36 **so_values,
37 'pricelist_id': my_pricelist.id,
38 'order_line': [
39 Command.create({
40 'product_id': product1.product_variant_id.id,
41 }),
42 ],
43 }, {
44 **so_values,
45 'pricelist_id': pricelist_expected_by_lead.id,
46 'order_line': [
47 Command.create({
48 'product_id': product2.product_variant_id.id,
49 }),
50 ],
51 }])
52
53 self.assertEqual(self.lead_1.expected_revenue, 0)
54
55 # Revenue should not be updated when the currency of sale order is different from lead.
56 so1.action_confirm()
57 self.assertEqual(self.lead_1.expected_revenue, 0)
58 # Revenue should be updated when the currency is same.
59 so2.action_confirm()
60 self.assertEqual(self.lead_1.expected_revenue, 200)