[IMP]:sale_crm:remove setup method and improve msg

bzr revid: sunilsharma.sharma07@gmail.com-20131017104442-6kw85h9524grftsw
This commit is contained in:
Sunil Sharma (OpenERP) 2013-10-17 16:14:42 +05:30
parent 09789afc2b
commit b686ee51af
1 changed files with 32 additions and 48 deletions

View File

@ -20,49 +20,38 @@
##############################################################################
from openerp.addons.mail.tests.common import TestMail
from openerp.osv.orm import except_orm
class TestSaleCrm(TestMail):
def setUp(self):
super(TestSaleCrm, self).setUp()
cr, uid = self.cr, self.uid
class TestSaleCrmCase(TestSaleCrm):
def test_sale_crm_case(self):
""" Testing Sale Crm """
"""Testing __get_bar_values method"""
cr, uid, = self.cr, self.uid
# Usefull models
#Usefull models
ir_model_obj = self.registry('ir.model.data')
res_company_obj = self.registry('res.company')
res_users_obj = self.registry('res.users')
crm_case_section_obj = self.registry('crm.case.section')
crm_lead_obj = self.registry('crm.lead')
# Find Direct Sales
direct_sales_ref = ir_model_obj.get_object_reference(cr, uid, 'crm', 'section_sales_department')
#Get required ids
direct_sales_id = ir_model_obj.get_object_reference(cr, uid, 'crm', 'section_sales_department')[1]
usd_id = ir_model_obj.get_object_reference(cr, uid, 'base', 'USD')[1]
your_company_id = ir_model_obj.get_object_reference(cr, uid, 'base', 'main_company')[1]
# for Opportunities
usd_ref = ir_model_obj.get_object_reference(cr, uid, 'base', 'USD')
your_company_ref = ir_model_obj.get_object_reference(cr, uid, 'base', 'main_company')
#Call _get_opportunities_data method before creating new opportunity in another currency.
opportunities_before = crm_case_section_obj._get_opportunities_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
# Before opportunities
opportunities_before = crm_case_section_obj._get_opportunities_data(cr, uid, [direct_sales_ref[1]], field_name=False, arg=False, context=False)
#I Create company with USD currency.
#Create new company with USD currency.
res_company_id = res_company_obj.create(cr, uid,{
'name': 'New Company',
'currency_id': usd_ref and usd_ref[1] or False,
'parent_id': your_company_ref and your_company_ref[1] or False
'currency_id': usd_id,
'parent_id': your_company_id
})
# Find Sale Manager group
#Create sales manager of new company.
group_sale_manager_id = ir_model_obj.get_object_reference(cr, uid, 'base', 'group_sale_manager')[1]
#I Create User of new company.
res_users_id = res_users_obj.create(cr, uid,{
'name': 'User',
'login': 'admin@example.com',
@ -72,49 +61,44 @@ class TestSaleCrmCase(TestSaleCrm):
'groups_id': [(6, 0, [group_sale_manager_id])]
})
#I create Opportunitie for new created user
#Create Opportunitie by new created user.
opportunities_id = crm_lead_obj.create(cr, res_users_id,{
'name': 'Opportunities',
'type': 'opportunity',
'planned_revenue': 10000,
'user_id' : res_users_id,
'section_id': direct_sales_ref and direct_sales_ref[1] or False
'section_id': direct_sales_id
})
user_rate = res_company_obj.browse(cr, uid ,[res_company_id])[0].currency_id.rate_silent
user_rate = res_company_obj.browse(cr, uid, [res_company_id])[0].currency_id.rate_silent
# After opportunities
opportunities_after = crm_case_section_obj._get_opportunities_data(cr, uid, [direct_sales_ref[1]], field_name=False, arg=False, context=False)
#Assertion Error
#Call _get_opportunities_data method and check Currency Conversion of amount for new created opportunity which was in another currency.
opportunities_after = crm_case_section_obj._get_opportunities_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
self.assertTrue(round(opportunities_after[1]['monthly_planned_revenue'][4]['value']) == round(opportunities_before[1]['monthly_planned_revenue'][4]['value'] + (10000 / user_rate)), "Not Proper Currency Conversion for Opportunities")
# Before Sale or Quotations
sale_order_before = crm_case_section_obj._get_sale_orders_data(cr, uid, [direct_sales_ref[1]], field_name=False, arg=False, context=False)
#Call _get_sale_orders_data method before changing currency of user.
sale_order_before = crm_case_section_obj._get_sale_orders_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
# Before Invoice
invoice_before = crm_case_section_obj._get_invoices_data(cr, uid, [direct_sales_ref[1]], field_name=False, arg=False, context=False)
#Call _get_invoices_data method before changing currency of user.
invoice_before = crm_case_section_obj._get_invoices_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
#I Write company .
#Change currency of company to INR.
company_id = res_users_obj._get_company(cr, uid, context=False, uid2=False)
inr_ref = ir_model_obj.get_object_reference(cr, uid, 'base', 'INR')
inr_id = ir_model_obj.get_object_reference(cr, uid, 'base', 'INR')[1]
res_company_obj.write(cr, uid, [company_id], {
'currency_id': inr_ref and inr_ref[1] or False
'currency_id': inr_id,
})
# After Sale or Quotations
sale_order_after = crm_case_section_obj._get_sale_orders_data(cr, uid, [direct_sales_ref[1]], field_name=False, arg=False, context=False)
#Call _get_sale_orders_data method after changing currency of user.
sale_order_after = crm_case_section_obj._get_sale_orders_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
# After Invoice
invoice_after = crm_case_section_obj._get_invoices_data(cr, uid, [direct_sales_ref[1]], field_name=False, arg=False, context=False)
#Call _get_invoices_data method after changing currency of user.
invoice_after = crm_case_section_obj._get_invoices_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
new_rate = res_company_obj.browse(cr, uid, [company_id])[0].currency_id.rate_silent
#Assertion Error
#Check currency conversion for Quotations,Sale orders and Invoices in to the current users currency
for month in range(0,5):
# for Quotations
self.assertTrue(round(sale_order_before[1]['monthly_quoted'][month]['value'] * new_rate) == round(sale_order_after[1]['monthly_quoted'][month]['value']), "Currency Conversion For Quotations Is Wrong")
# for sale order
self.assertTrue(round(sale_order_before[1]['monthly_confirmed'][month]['value'] * new_rate) == round(sale_order_after[1]['monthly_confirmed'][month]['value']), "Currency Conversion For Sale Order Is Wrong")
# for Invoice
self.assertTrue(round(invoice_before[1][month]['value'] * new_rate) == round(invoice_after[1][month]['value']), "Currency Conversion For Invoice Is Wrong")
self.assertTrue(round(sale_order_before[1]['monthly_quoted'][month]['value'] * new_rate) == round(sale_order_after[1]['monthly_quoted'][month]['value']), "Currency conversion for quotations is wrong")
self.assertTrue(round(sale_order_before[1]['monthly_confirmed'][month]['value'] * new_rate) == round(sale_order_after[1]['monthly_confirmed'][month]['value']), "Currency conversion for sale orders is wrong")
self.assertTrue(round(invoice_before[1][month]['value'] * new_rate) == round(invoice_after[1][month]['value']), "Currency conversion for invoices is wrong")