Exemple #1
0
 def __init__(self, cookie, csrf):
     self.common = common.Common(cookie, csrf)
     self.base_url = const.BASE_URL
     self.csrf = csrf
     self.cookie = cookie
     self.response = ''
     self.user_id = ''
     self.customers_id = []
     self.params = ''
     self.testAddCustomer = AddCustomer(cookie, csrf)
     self.testGetDepartment = GetDepartment(cookie, csrf)
     self.user = users.GetUser(cookie, csrf)
     pass
 def __init__(self, cookie, csrf):
     self.common = common.Common(cookie, csrf)
     self.testAddCustomer = AddCustomer(cookie, csrf)
     self.user = users.GetUser(cookie, csrf)
     self.DepartmentId = departmentid.GetDepartment(cookie, csrf)
     self.base_url = const.BASE_URL
     self.base_url2 = const.SIGN_IN_BASE_URL
     self.csrf = csrf
     self.cookie = cookie
     self.response = ''
     self.user_id = ''
     self.user = users.GetUser(cookie, csrf)
     self.contracts_id = ''
     self.params = ''
     self.contract_id = ''
Exemple #3
0
 def __init__(self, cookie, csrf):
     self.common = common.Common(cookie, csrf)
     # self.testCase.customers = add_customers
     # self.testAddCustomer = AddCustomer
     self.testAddCustomer = AddCustomer(cookie, csrf)
     self.testGetDepartment = GetDepartment(cookie, csrf)
     self.user = users.GetUser(cookie, csrf)
     self.base_url = const.BASE_URL
     self.base_url2 = const.SIGN_IN_BASE_URL
     self.csrf = csrf
     self.cookie = cookie
     self.response = ''
     self.user_id = ''
     self.opportunities_id = []
     self.params = ''
     self.opportunity_id = ''
     pass
Exemple #4
0
 def __init__(self, cookie, csrf):
     self.common = common.Common(cookie, csrf)
     self.base_url = const.BASE_URL
     self.base_url2 = const.SIGN_IN_BASE_URL
     self.testAddCustomer = AddCustomer(cookie, csrf)
     self.testAddContract = AddContract(cookie, csrf)
     self.csrf = csrf
     self.cookie = cookie
     self.username = ''
     self.password = ''
     self.response = ''
     self.csrf1 = ''
     self.given_cookie = ''  # 用于存储人工指定的cookie,一旦设置后,就不使用页面内获取的cookie
     self.authorization = ''
     self.lead_ids = []
     self.user_id = ''
     self.customer_id = ''
     self.contracts_id =[]
     self.contracts_id1 = ''
     self.contracts_id = ''
     self.sql_host = 'rdscbq34656z0ix59br0.mysql.rds.aliyuncs.com'
     self.products_id = ''
     self.expense_id = ''
     self.expense_id_list = []
     self.expense_accounts_id = ''
     self.payment_id_list = []
     self.payslip_stats_list = []
     self.commission_rules_id = []
     self.performance_indicator_id  = ''
     self.stations_id = ''
     self.revisit_logs_list = []
     self.payslip_stats_list = []
     self.commission_rules_id = []
     self.performance_indicator_id  = ''
     self.stations_id = ''
     self.revisit_logs_list = []
     self.users_id = []
     self.scope = ''
     pass
Exemple #5
0
 def __init__(self, cookie, csrf):
     #'https://e.ikcrm.com/
     # self.base_url = base_url
     self.common = common.Common(cookie, csrf)
     self.testAddCustomer = AddCustomer(cookie, csrf)
     self.testGetDepartment = GetDepartment(cookie, csrf)
     self.user = users.GetUser(cookie, csrf)
     self.base_url = const.BASE_URL
     self.base_url2 = const.SIGN_IN_BASE_URL
     self.csrf = csrf
     self.cookie = cookie
     self.contacts_id =[]
     self.contacts_id1 = ''
     self.contact_id = ''
     self.contact_id =[]
     self.contact_id = ''
     pass
Exemple #6
0
class GetContracts:
    def __init__(self, cookie, csrf):
        self.common = common.Common(cookie, csrf)
        self.base_url = const.BASE_URL
        self.base_url2 = const.SIGN_IN_BASE_URL
        self.testAddCustomer = AddCustomer(cookie, csrf)
        self.testAddContract = AddContract(cookie, csrf)
        self.csrf = csrf
        self.cookie = cookie
        self.username = ''
        self.password = ''
        self.response = ''
        self.csrf1 = ''
        self.given_cookie = ''  # 用于存储人工指定的cookie,一旦设置后,就不使用页面内获取的cookie
        self.authorization = ''
        self.lead_ids = []
        self.user_id = ''
        self.customer_id = ''
        self.contracts_id =[]
        self.contracts_id1 = ''
        self.contracts_id = ''
        self.sql_host = 'rdscbq34656z0ix59br0.mysql.rds.aliyuncs.com'
        self.products_id = ''
        self.expense_id = ''
        self.expense_id_list = []
        self.expense_accounts_id = ''
        self.payment_id_list = []
        self.payslip_stats_list = []
        self.commission_rules_id = []
        self.performance_indicator_id  = ''
        self.stations_id = ''
        self.revisit_logs_list = []
        self.payslip_stats_list = []
        self.commission_rules_id = []
        self.performance_indicator_id  = ''
        self.stations_id = ''
        self.revisit_logs_list = []
        self.users_id = []
        self.scope = ''
        pass

    #获得所有的我的合同,我协作的合同,我的合同来查询 获取   Obtain
    def contracts_get_scopes(self):
        url = self.base_url + 'contracts'
        params = {
            'scope': 'all_own',
            'section_only': 'true'
        }
        response = self.common.get_response_json(url, params, '获取合同页面的scope')
        soup = BeautifulSoup(response.content, 'html.parser')
        scopes = re.findall(r"contracts\?scope=(.*?)\">",str(soup))
        # scopes = re.findall(r"hetongs\?scope=(.*?)\">", str(soup))
        return scopes

    def contract(self, contract_id):
        # soup = self.get_contract(contract_id)
        # self.contracts_revisit_logs(soup, contract_id)
        self.get_contract_detail(contract_id)
        self.get_expenses(contract_id)
        self.get_events(contract_id)
        self.get_attachment(contract_id)
        self.get_operation_logs(contract_id)
        # self.get_contract(contract_id)
        # self.export_selected_contracts(scope)
        # self.export_all_contracts(scope)
        # self.contracts_revisit_logs(soup, contract_id)
        self.get_contract_detail(contract_id)
        self.get_invoiced_payments_tab(contract_id)
        self.contract_add_received_payments(contract_id)
        self.get_received_payments_tab(contract_id)
        self.get_tab_products(contract_id)
        self.get_attachment(contract_id)
        self.get_events(contract_id)
        self.get_operation_logs(contract_id)


    #获取合同ID
    def contract_ids(self):
        url = self.base_url + 'contracts'
        body = {
            'order':'asc',
            'scope':'all_own',
            'sort': 'contracts.updated_at desc',
            'per_page':10,
            'type':'advance',
            'section_only':'true'
        }
        response = self.common.get_response_json(url, body, '获取当前页的合同')
        if not response:
            return {}
        self.response = response
        S = self.response.content
        #print S
        soup = BeautifulSoup(S, "html.parser")
        checked_contract = soup.find(attrs={'data-entity-table-name':'contract'})
        if checked_contract:
            a = str(checked_contract)
            contract_id_list = re.findall(r"data-id=\"(.*?)\">",a)
            return contract_id_list

    #导出所选合同
    def export_selected_contracts(self, scope):
        contract_ids = self.contract_ids()
        url = self.base_url + 'contracts?export_page=1&format_type=calculate_export_pages&order=asc&per_page=10&scope='+scope+'&sort=contracts.updated_at+desc&type=advance&selected_ids%5B%5D='+contract_ids[0]+'&selected_ids%5B%5D='+contract_ids[1]+'&format=js'
        self.common_get_resonse_json(url, 'export_selected_contracts')
        url = self.base_url + 'contracts.js?export_page=1&format_type=xlsx&order=asc&per_page=10&scope='+scope+'&selected_ids%5B%5D='+contract_ids[0]+'&selected_ids%5B%5D='+contract_ids[1]+'&sort=contracts.updated_at+desc&type=advance'
        self.common_get_resonse_json(url, 'excute download export selected file')
    #导出全部合同
    def export_all_contracts(self, scope):
        url = self.base_url + 'contracts?format_type=calculate_export_pages&order=asc&per_page=10&scope='+scope+'&sort=contracts.updated_at+desc&type=advance'
        self.common_get_resonse_json(url, 'export_all_contracts')

        #点击下载文档
        url = self.base_url + 'contracts?export_page=1&format_type=xlsx&order=asc&per_page=10&scope='+scope+'&sort=contracts.updated_at+desc&type=advance'
        self.common_get_resonse_json(url, 'excute download export all contract file')

    #获取单个合同详情
    def get_contract(self, contract_id):
        print(contract_id)
        url = self.base_url + 'contracts/'+ str(contract_id)
        body = {}
        response = self.common.get_response_json(url, body, '获取当前用户详情')
        if response !='False':
            soup = BeautifulSoup(response.content, 'html.parser')
            return soup
        #
        url = self.base_url + 'contracts/'+ str(contract_id) + '?tab=tab_base'
        params = {
            'tab': 'tab_base'
        }
        self.common.get_response_json(url, params, '合同的基本资料')


    #合同写跟进
    def contracts_revisit_logs(self, soup, contract_id):
        status_list = re.findall(r"data-status=\"(.*?)\">",str(soup))
        if status_list:
            for status in status_list:
                url = self.base_url + 'api/contracts/%s/revisit_logs' %contract_id
                body = {
                    'utf8':'✓',
                    'authenticity_token': self.csrf,
                    'revisit_log[category]':'91160',
                    'revisit_log[real_revisit_at]':self.common.get_today_str_yymmddhhmm(),
                    'revisit_log[content]':'写跟进%s' %self.common.get_random_int(9999),
                    'revisit_log[loggable_attributes][status]':status,
                    'revisit_log[loggable_attributes][id]':contract_id,
                    'revisit_log[remind_at]':self.common.get_tomorrow_srt_yymmddhhmm()
                }
                response = self.common.post_response_json(url, body, '合同写跟进')
                if not response:
                    return {}

    #查看合同资料
    def get_contract_detail(self, contract_id):
        url = self.base_url + 'contracts/'+ str(contract_id)
        params = {
            'only_base_info': 'true'
        }
        self.common.get_response_json(url, params, '获取合同的详细资料')

    # 合同获取回款记录tab
    def get_received_payments_tab(self, contract_id):
        # url = self.base_url + str(contract_id) +'?tab=tab_received_payments'
        url = self.base_url +'api/received_payments?page=&perPage=15&contract_id=' + str(contract_id)
        params ={
            'tab': 'tab_received_payments'
        }
        self.common.get_response_json(url, params, '获取合同详情的回款tab页')

    #合同详情页新增回款计划
    def add_received_payment_plans(self,contract_id):
        url = self.base_url + 'contracts/'+ str(contract_id)+'?tab=tab_received_payments'
        params ={
            'tab': 'tab_received_payments'
        }
        url = self.base_url +'api/received_payment_plans/batch_create?contract_id='+ str(contract_id)
        body = {
            'utf8': ' ✓',
            'authenticity_token': self.csrf,
            'plans[0][customer_id]': self.testAddCustomer.add_customers(),
            'plans[0][contract_id]': self.testAddContract.add_contracts(),
            'plans[0][receive_stage]': '1',
            'plans[0][receive_date]': '2018-08-01',
            'plans[0][amount]': '5000',
            'plans[0][note]':'',
            'plans[1][customer_id]': self.testAddCustomer.add_customers(),
            'plans[1][contract_id]': self.testAddContract.add_contracts(),
            'plans[1][receive_stage]': '1',
            'plans[1][receive_date]': '2018-08-01',
            'plans[1][amount]': '6000',
            'plans[1][note]': ''
        }
        response = self.common.post_response_json(url, body, '新增回款计划 api是' + url)
        if not response:
            return {}
        self.response = response
        received_payments_id = self.response.json()['data']['id']
        return received_payments_id

    #合同详情页新增回款记录
    def contract_add_received_payments(self, contract_id):
        url = self.base_url +'/contracts/' +str(contract_id) + '/received_payments'
        body ={
            'authenticity_token':self.csrf,

            'contract_id': 30939,
            'received_payment[receive_date]': '2018-06-22',
            'received_payment[amount]': '2000',
            'received_payment[customer_id]': self.customer_id,
            'received_payment[contract_id]': self.contracts_id,
            'received_payment[received_payment_plan_id]': '',
            'received_payment[payment_type]':'',
            'received_payment[received_types]':'',
            'received_payment[receive_user_id]': self.user_id,
            'received_payment[note]':'备注',
        }
        response = self.common.post_response_json(url, body, '合同详情页新增回款记录 api是'+url)
        if not response:
            return {}
        self.response = response
        received_payments_amount = self.response.json()['data']['amount']
        return received_payments_amount


    # 合同获取开票记录tab
    def get_invoiced_payments_tab(self, contract_id):
        url = self.base_url +'api/invoiced_payments?page=&perPage=15&contract_id=' + str(contract_id)
        params ={
            'tab': 'tab_invoiced_payments'
        }
        self.common.get_response_json(url, params, '获取合同详情的开票tab页')

    #合同详情页新增开票记录
    def contract_add_invoiced_payments(self, contract_id):
        url = self.base_url +'/contracts/' +str(contract_id) + '/invoiced_payments'
        body ={
            'authenticity_token':self.csrf,
            'invoiced_payment[amount]': '2000',
            'invoiced_payment[invoice_types]': '205671',
            'invoiced_payment[invoice_no]':'',
            'invoiced_payment[note]':'备注',
            'invoiced_payment[invoiced_date]': '2018-06-23',
            'invoiced_payment[broker_user_id]': self.user_id,
            'invoiced_payment[content]': '开票' %self.common.get_random_int(99999),
        }
        response = self.common.post_response_json(url, body, '合同详情页新增开票记录 api是'+url)
        if not response:
            return {}
        self.response = response
        invoiced_payment_amount = self.response.json()['data']['amount']
        return invoiced_payment_amount

    #查看合同关联的产品
    def get_tab_products(self,contract_id):
        url = self.base_url + 'api/product_assets?page=&perPage=15&assetable_id='+str(contract_id)+'&assetable_type=Contract'
        print(url)
        params = {
            'tab': 'tab_products'
        }
        self.common.get_response_json(url, params, '获取合同详情的产品tab页')

    #查看合同的费用
    def get_expenses(self, contract_id):
        url = self.base_url + 'api/expenses?page=&perPage=100&contract_id='+str(contract_id)
        params = {
            'page': '',
            'perPage': 100,
            'contract_id': contract_id
        }
        self.common.get_response_json(url, params, '获取当前合同的费用')

    #查看合同的任务
    def get_events(self, contract_id):
        url = self.base_url + 'events?entity_id='+str(contract_id)+'&entity_klass=Contract'
        params = {
            'entity_id': contract_id,
            'entity_klass': 'Contract'
        }
        self.common.get_response_json(url, params, '获取当前合同的任务')

    #查看合同下的附件
    def get_attachment(self, contract_id):
        url = self.base_url + 'api/attachments?page=&perPage=15&entity_id='+str(contract_id)+'&klass=Contract&sub_type=file'
        params = {
            'page':'',
            'perPage':15,
            'entity_id':contract_id,
            'klass':'Contract'
        }
        self.common.get_response_json(url, params, '获取当前合同的附件')

    #查看合同的操作日志
    def get_operation_logs(self, contract_id):
        url = self.base_url + 'api/operation_logs?page=&perPage=15&loggable_id='+str(contract_id)+'&loggable_type=Contract'
        params = {
            'page':'',
            'perPage':15,
            'loggable_id':contract_id,
            'loggable_type':'Contract'
        }
        self.common.get_response_json(url, params, '查看合同的操作日志')

    #返回到合同详情(基本信息tab)
    def get_contracts_tab_base(self,contract_id):
        url = self.base_url + 'contracts/'+ str(contract_id) + '?tab=tab_base'
        params = {
            'tab': 'tab_base'
        }
        self.common.get_response_json(url, params, '切换回合同的基本资料')
class AddReceivedPayment:
    def __init__(self, cookie, csrf):
        self.common = common.Common(cookie, csrf)
        self.base_url = const.BASE_URL
        self.csrf = csrf
        self.cookie = cookie
        self.response = ''
        self.user_id = ''
        self.customers_id = []
        self.params = ''
        self.user = users.GetUser(cookie, csrf)
        self.DepartmentId = departmentid.GetDepartment(cookie, csrf)
        self.testAddCustomer = AddCustomer(cookie, csrf)
        self.testAddContract = AddContract(cookie, csrf)
        self.customer_id = ''
        self.contract_id = ''
        pass

    # 新增回款计划
    def add_received_payment_plans(self):
        url = self.base_url + 'api/received_payments'
        body = {
            'utf8': ' ✓',
            'authenticity_token': self.csrf,
            'plans[0][customer_id]': self.testAddCustomer.add_customers(),
            'plans[0][contract_id]': self.testAddContract.add_contracts(),
            'plans[0][receive_stage]': '1',
            'plans[0][receive_date]': '2018-08-01',
            'plans[0][amount]': '4500',
            'plans[0][note]': ''
        }
        response = self.common.post_response_json(url, body,
                                                  '新增回款计划 api是' + url)
        if not response:
            return {}
        self.response = response
        received_payments_id = self.response.json()['data']['id']
        return received_payments_id

    #获取回款计划id
    def received_payment_plan_id_get(
        self,
        contract_id,
    ):
        url = self.base_url + 'contracts/%s?tab=tab_received_payments' % contract_id
        body = {}
        response = self.common.get_response_json(url, body,
                                                 '获取回款计划id api是' + url)
        self.response = response
        S = self.response.text
        soup = BeautifulSoup(S, 'html.parser')
        received_payment_plan_id = re.findall(
            r"received_payment_plan_id: (.*?),", str(soup))
        return received_payment_plan_id

    # 获取回款计划id按照回款页面
    def received_payment_plan_id_get_page(self):
        url = self.base_url + 'received_payment_center/received_payment_plans?scope=received_payment_plans&per_page=10&type=advance&section_only=true'
        body = {}
        response = self.common.get_response_json(url, body,
                                                 '获取回款计划id api是' + url)
        self.response = response
        S = self.response.text
        soup = BeautifulSoup(S, 'html.parser')
        # print (str(soup))
        received_payment_plan_id = re.findall(r"data-id=\"(.*?)\">", str(soup))
        return received_payment_plan_id

    # 新增回款记录
    def add_received_payments(self,
                              contract_id,
                              receive_date='2018-06-22',
                              amount='2000',
                              customer_id=''):
        url = self.base_url + 'api/received_payments'
        body = {
            'utf8':
            ' ✓',
            'authenticity_token':
            self.csrf,
            'request_ticket':
            self.common.get_random_int(9999999999999),
            'contract_id':
            contract_id,
            'received_payment[receive_date]':
            receive_date,
            'received_payment[amount]':
            amount,
            'received_payment[customer_id]':
            customer_id,
            'received_payment[contract_id]':
            contract_id,
            'received_payment[received_payment_plan_id]':
            self.received_payment_plan_id_get_page()[0],
            'received_payment[payment_type]':
            '',
            'received_payment[received_types]':
            '',
            'received_payment[receive_user_id]':
            self.user.getMyUserId(),
            'received_payment[note]':
            '备注',
        }
        response = self.common.post_response_json(url, body,
                                                  '新增回款记录 api是' + url)
        if not response:
            return {}
        self.response = response
        received_payments_id = self.response.json()['data']['id']
        return received_payments_id

    # 新增开票记录
    def add_invoiced_payments(self, contract_id):
        url = self.base_url + 'api/invoiced_payments'
        body = {
            'utf8': ' ✓',
            'authenticity_token': self.csrf,
            'invoiced_payment[amount]': '2000',
            'invoiced_payment[invoice_types]': '205671',
            'invoiced_payment[invoice_no]': '',
            'invoiced_payment[note]': '备注',
            'invoiced_payment[invoiced_date]': '2018-06-23',
            'invoiced_payment[broker_user_id]': self.user_id,
            'invoiced_payment[content]':
            '开票' % self.common.get_random_int(99999),
        }
        response = self.common.post_response_json(url, body,
                                                  '新增开票记录 api是' + url)
        if not response:
            return {}
        self.response = response
        invoiced_payment_id = self.response.json()['data']['id']
        return invoiced_payment_id
Exemple #8
0
class AddOpportunities:
    def __init__(self, cookie, csrf):
        self.common = common.Common(cookie, csrf)
        # self.testCase.customers = add_customers
        # self.testAddCustomer = AddCustomer
        self.testAddCustomer = AddCustomer(cookie, csrf)
        self.testGetDepartment = GetDepartment(cookie, csrf)
        self.user = users.GetUser(cookie, csrf)
        self.base_url = const.BASE_URL
        self.base_url2 = const.SIGN_IN_BASE_URL
        self.csrf = csrf
        self.cookie = cookie
        self.response = ''
        self.user_id = ''
        self.opportunities_id = []
        self.params = ''
        self.opportunity_id = ''
        pass

    # 新增商机(关闭审批)
    def add_opportunities(self,
                          sign_date='2018-05-16',
                          total_amount=500,
                          approve_status='approved',
                          stage='',
                          DepartmentId=0):
        # self.testAddCustomer.add_customers()
        # self.testGetDepartment.getDepartmentId()
        url = self.base_url + 'api/opportunities'
        body = {
            'utf8':
            '✓',
            'authenticity_token':
            self.csrf,
            'refer_call_record_id':
            '',
            # 'opportunity[customer_id]': self.testAddCustomer.add_customers(),
            'request_ticket':
            self.common.get_random_int(99999999),
            'opportunity[id]':
            '',
            'opportunity[approve_status]':
            approve_status,
            'opportunity[title]':
            'opportunity%s' % self.common.get_random_int(99999999),
            # 'opportunity[customer_id]': self.testAddCustomer.add_customers(),
            'opportunity[customer_id]':
            '1228332',
            'opportunity[expect_amount]':
            total_amount,
            'opportunity[expect_sign_date]':
            sign_date,
            'opportunity[stage]':
            stage,
            'opportunity[kind]':
            '',
            'opportunity[get_time]':
            '2018-07-03',
            'opportunity[source]':
            '205676',
            'opportunity[revisit_remind_at]':
            '2018-09-14 19:00',
            'opportunity[note]':
            '',
            'opportunity[user_id]':
            self.user.getMyUserId(),
            'opportunity[want_department_id]':
            self.testGetDepartment.getDepartmentId()[DepartmentId]
        }
        response = self.common.post_response_json(url, body, '新增商机 api是' + url)
        if not response:
            return {}
        self.response = response
        opportunity_id = self.response.json()['data']['id']
        return opportunity_id

    #新增待审批商机
    def add_applying_opportunities(self):
        url = self.base_url + 'api/opportunities'
        body = {
            'utf8':
            '✓',
            'authenticity_token':
            self.csrf,
            # 'request_ticket': '23ca40d3-e1ee-468b-9d25-710bb0306d30',
            'opportunity[id]':
            '',
            'opportunity[approve_status]':
            'applying',
            'opportunity[title]':
            'opportunity%s' % self.common.get_random_int(99999999),
            'opportunity[customer_id]':
            self.testAddCustomer.add_customers(),
            # 'opportunity[customer_id]': self.testAddCustomer.add_customers(),
            # 'opportunity[product_assets_attributes][][id]':'',
            # 'opportunity[product_assets_attributes][][_destroy]': 'false',
            # 'opportunity[product_assets_attributes][][product_id]': '',
            # 'opportunity[product_assets_attributes][][recommended_unit_price]': '',
            # 'opportunity[product_assets_attributes][][quantity]': '',
            # 'opportunity[product_assets_attributes][][remark]':'',
            # 'opportunity[product_assets_attributes][][product_attr_id]':'',
            'opportunity[expect_amount]':
            '5000',
            'opportunity[expect_sign_date]':
            '2018-05-16',
            'opportunity[stage]':
            '81797',
            'opportunity[kind]':
            '',
            'opportunity[get_time]':
            '2018-07-06',
            'opportunity[source]':
            '',
            'opportunity[revisit_remind_at]':
            '2018-09-14 19:00',
            'opportunity[note]':
            '',
            # 'opportunity[user_id]':self.user.getUserId()[0] ,    #,"2222396"
            'opportunity[want_department_id]':
            str(self.testGetDepartment.getDepartmentId()[0])  #5168
        }
        response = self.common.post_response_json(url, body,
                                                  '开启审批新增商机 api是' + url)
        if not response:
            return {}
        self.response = response
        opportunity_id = self.response.json()['data']['id']
        print(opportunity_id)
        return opportunity_id

    # 撤销之后重新提交商机审批
    def re_add_applying_opportunities(self, opportunity_id):
        url = self.base_url + 'api/opportunities/' + str(opportunity_id)
        body = {
            'utf8':
            '✓',
            '_method':
            'patch',
            'authenticity_token':
            self.csrf,
            # 'request_ticket': '23ca40d3-e1ee-468b-9d25-710bb0306d30',
            'opportunity[id]':
            opportunity_id,
            'opportunity[approve_status]':
            'applying',
            'opportunity[title]':
            'opportunity%s' % self.common.get_random_int(99999999),
            'opportunity[customer_id]':
            self.testAddCustomer.add_customers(),
            # 'opportunity[customer_id]': self.testAddCustomer.add_customers(),
            # 'opportunity[product_assets_attributes][][id]':'',
            # 'opportunity[product_assets_attributes][][_destroy]': 'false',
            # 'opportunity[product_assets_attributes][][product_id]': '',
            # 'opportunity[product_assets_attributes][][recommended_unit_price]': '',
            # 'opportunity[product_assets_attributes][][quantity]': '',
            # 'opportunity[product_assets_attributes][][remark]':'',
            # 'opportunity[product_assets_attributes][][product_attr_id]':'',
            'opportunity[expect_amount]':
            '5000',
            'opportunity[expect_sign_date]':
            '2018-05-16',
            'opportunity[stage]':
            '81797',
            'opportunity[kind]':
            '',
            'opportunity[get_time]':
            '2018-07-06',
            'opportunity[source]':
            '',
            'opportunity[revisit_remind_at]':
            '2018-09-14 19:00',
            'opportunity[note]':
            '',
            'opportunity[user_id]':
            self.user.getMyUserId(),  # ,"2222396"
            'opportunity[want_department_id]':
            str(self.testGetDepartment.getDepartmentId()[0])  # 5168
        }
        response = self.common.post_response_json(url, body, '撤销之后重新提交商机审批')

    #新增任务
    def add_event_for_opportunitie(self, opportunity_id):
        url = self.base_url + 'events/new?ajax_back_to=%2Fevents%3Fentity_id%3D' + str(
            opportunity_id
        ) + '%26entity_klass%3DOpportunitie&entity_id=' + str(
            opportunity_id) + '&entity_klass=Opportunitie'
        params = {}
        self.common.get_response_json(url, params, '商机详情页新增任务打开窗口')
        url = self.base_url + 'api/events'
        params = {
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'event[note]': '打电话给客户',
            'event[remind_at]': self.common.get_today_str_yymmddhhmm(),
            'event[remind_type]': 'punctual',
            'event[related_item_id]': str(opportunity_id),
            'event[related_item_type]': 'Lead',
            'event[user_ids]': str(self.user.getUserId()[0])
        }
        response = self.common.post_response_json(url, params, '给单个商机新增任务')
        event_id = response.json()['data']['id']
        return event_id
Exemple #9
0
class AddContact:
    def __init__(self, cookie, csrf):
        self.common = common.Common(cookie, csrf)
        self.base_url = const.BASE_URL
        self.csrf = csrf
        self.cookie = cookie
        self.response = ''
        self.user_id = ''
        self.customers_id = []
        self.params = ''
        self.testAddCustomer = AddCustomer(cookie, csrf)
        self.testGetDepartment = GetDepartment(cookie, csrf)
        self.user = users.GetUser(cookie, csrf)
        pass

    #新增联系人
    def add_contact(self):
        url = self.base_url + 'api/contacts'
        body = {
            'utf8':
            '✓',
            'authenticity_token':
            self.csrf,
            'refer_call_record_id':
            '',
            'contact[id]':
            '',
            'contact[name]':
            '联系人%s' % self.common.get_today_str_yymmddhhmm(),
            'contact[customer_id]':
            self.testAddCustomer.add_customers(),
            'contact[department]':
            '',
            'contact[job]':
            '',
            'contact[address_attributes][tel]':
            '191%s' % self.common.get_random_int(99999999),
            'contact[address_attributes][phone]':
            '',
            'contact[address_attributes][wechat]':
            '',
            'contact[address_attributes][qq]':
            '',
            'contact[address_attributes][wangwang]':
            '',
            'contact[address_attributes][email]':
            'test%s @test.com' % self.common.get_random_int(9999),
            'contact[address_attributes][url]':
            'www.test%s.com' % self.common.get_random_int(9999),
            'china_tag_id':
            '4',
            'contact[address_attributes][country_id]':
            '4',
            'contact[address_attributes][province_id]':
            '',
            'contact[address_attributes][city_id]':
            '',
            'contact[address_attributes][district_id]':
            '',
            'contact[address_attributes][detail_address]':
            '',
            'contact[address_attributes][zip]':
            '',
            'contact[gender]':
            '',
            'contact[birth_date]':
            '',
            'contact[note]':
            '123',
            # 'contact[user_id]': self.user.getMyUserId(),
            # 'contact[want_department_id]':self.DepartmentId.getDepartmentId()
        }
        response = self.common.post_response_json(url, body, '新增联系人是' + url)
        if not response:
            return {}
        self.response = response
        contact_id = self.response.json()['data']['id']
        return contact_id

    #扫描名片
    def contacts_camcard_launch(self):
        url = self.base_url + 'contacts/camcard_launch'
        body = {}
        self.common.get_response_json(url, body, '打开扫描名片窗口')
        #开始扫描
        url = self.base_url + 'contacts/camcard_explain'
        params = {
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'attachment_id': '33272'
        }
        self.common.post_response_json(url, params, '联系人-扫描名片添加图片')
        #开始添加联系人
        url = self.base_url + 'api/contacts/camcard'
        params = {
            'utf8':
            '✓',
            'authenticity_token':
            self.csrf,
            'attachment_id':
            '33276',
            'entity_attributes[name]':
            '联系人名称%s' % self.common.get_random_int(99999999),
            'entity_attributes[company_name]':
            '扫描名片添加联系人%s' % self.common.get_random_int(99999999),
            'entity_attributes[department]':
            '',
            'entity_attributes[job]':
            '',
            'entity_attributes[address_attributes][tel]':
            '',
            'entity_attributes[address_attributes][phone]':
            '',
            'entity_attributes[address_attributes][email]':
            '',
            'entity_attributes[address_attributes][qq]':
            '',
            'entity_attributes[address_attributes][fax]':
            '',
            'entity_attributes[address_attributes][url]':
            '',
            'entity_attributes[address_attributes][detail_address]':
            '',
            'entity_attributes[address_attributes][zip]':
            ''
        }
        self.common.post_response_json(url, params, '扫描名片添加联系人')

    #新增任务
    def add__event_for_contact(self, contact_id):
        url = self.base_url + 'events/new?ajax_back_to=%2Fevents%3Fentity_id%3D111662%26entity_klass%3DContact&entity_id=' + str(
            contact_id) + '&entity_klass=Contact'
        params = {}
        self.common.get_response_json(url, params, '联系人详情页新增任务打开窗口')
        url = self.base_url + 'api/events'
        params = {
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'event[note]': '打电话给客户',
            'event[remind_at]': self.common.get_today_str_yymmddhhmm(),
            'event[remind_type]': 'punctual',
            'event[related_item_id]': str(contact_id),
            'event[related_item_type]': 'Contact',
            'event[user_ids]': str(self.user.getMyUserId())
        }
        response = self.common.post_response_json(url, params, '给单个联系人新增任务')
        id = response.json()['data']['id']
class AddContract:
    def __init__(self, cookie, csrf):
        self.common = common.Common(cookie, csrf)
        self.testAddCustomer = AddCustomer(cookie, csrf)
        self.user = users.GetUser(cookie, csrf)
        self.DepartmentId = departmentid.GetDepartment(cookie, csrf)
        self.base_url = const.BASE_URL
        self.base_url2 = const.SIGN_IN_BASE_URL
        self.csrf = csrf
        self.cookie = cookie
        self.response = ''
        self.user_id = ''
        self.user = users.GetUser(cookie, csrf)
        self.contracts_id = ''
        self.params = ''
        self.contract_id = ''
        # self.DepartmentId = self.DepartmentId.getDepartmentId()
        # pass

    # 新增合同(关闭审批)
    def add_contracts(self,
                      sign_date='2018-07-22',
                      total_amount=2000,
                      approve_status='approved',
                      DepartmentId=0):
        # customer_id = self.testAddCustomer.add_customers()
        ## 钉钉测试环境客户id
        customer_id = 1228332
        ##钉钉回归环境客户
        # customer_id=1207240
        url = self.base_url + 'api/contracts'
        body = {
            'utf8':
            '✓',
            'authenticity_token':
            self.csrf,
            'refer_call_record_id':
            '',
            'request_ticket':
            self.common.get_random_int(999999999),
            'contract[id]':
            '',
            'contract[approve_status]':
            approve_status,
            'contract_action_name':
            'new',
            'contract[title]':
            'contracts%s' % self.common.get_today_str_yymmddhhmm(),
            'contract[customer_id]':
            customer_id,
            'contract[total_amount]':
            total_amount,
            'contract[sign_date]':
            sign_date,
            'contract[start_at]':
            '2018-06-30',
            'contract[end_at]':
            '2018-08-30',
            'contract[opportunity_id]':
            '',
            'contract[received_payment_plans_attributes][][id]':
            '',
            'contract[received_payment_plans_attributes][][receive_stage]':
            '1',
            'contract[received_payment_plans_attributes][][receive_date]':
            '2019-01-22',
            'contract[received_payment_plans_attributes][][amount]':
            '100',
            'contract[received_payment_plans_attributes][][received_types]':
            '268979',
            'contract[received_payment_plans_attributes][][note]':
            '',
            'contract[status]':
            '',
            'contract[sn]':
            '',
            'contract[special_terms]':
            '',
            'contract[category]':
            '',
            'contract[payment_type]':
            '',
            'contract[customer_signer]':
            '',
            'contract[our_signer]':
            '',
            'contract[revisit_remind_at]':
            '',
            'contract[note]':
            '',
            'contract[user_id]':
            self.user.getMyUserId(),
            'contract[want_department_id]':
            self.DepartmentId.getDepartmentId()[DepartmentId]
        }
        # print (body)
        response = self.common.post_response_json(url, body, '新增合同 api是' + url)
        if not response:
            return {}
        self.response = response
        contract_id = self.response.json()['data']['id']
        # print (contract_id)
        return contract_id, customer_id

    #新增待审批合同
    def add_applying_contract(self):
        url = self.base_url + 'api/contracts'
        body = {
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'refer_call_record_id': '',
            'request_ticket': 'edb57235-246e-4776-a85f-b658cd4e668e',
            'contract[id]': '',
            'contract[approve_status]': 'applying',
            'contract_action_name': 'new',
            'contract[title]':
            'contracts%s' % self.common.get_random_int(99999999),
            'contract[customer_id]': self.testAddCustomer.add_customers(),
            'contract[total_amount]': '20000',
            'contract[sign_date]': '2018-06-30',
            'contract[start_at]': '2018-06-30',
            'contract[end_at]': '2018-08-30',
            'contract[opportunity_id]': '',
            'contract[product_assets_attributes][][id]': '',
            'contract[product_assets_attributes][][_destroy]': 'false',
            'contract[product_assets_attributes][][product_id]': '',
            'contract[product_assets_attributes][][recommended_unit_price]':
            '',
            'contract[product_assets_attributes][][quantity]': '',
            'contract[product_assets_attributes][][remark]': '',
            'contract[product_assets_attributes][][product_attr_id]': '',
            'contract[status]': '',
            'contract[sn]': '',
            'contract[special_terms]': '',
            'contract[category]': '',
            'contract[payment_type]': '',
            'contract[customer_signer]': '',
            'contract[our_signer]': '',
            'contract[revisit_remind_at]': '',
            'contract[note]': '',
            'contract[user_id]': self.user.getMyUserId(),
            'contract[want_department_id]':
            self.DepartmentId.getDepartmentId()
        }
        response = self.common.post_response_json(url, body,
                                                  '开启审批新增合同 api是' + url)
        if not response:
            return {}
        self.response = response
        # print(self.response.json())
        contract_id = self.response.json()['data']['id']
        self.contract_id = contract_id
        return contract_id

    #新增合同关联产品
    def add_contracts_products_add(self,
                                   goods_id_list=[11012, 11013],
                                   quantity_list=[[0], [1]],
                                   price_list=[[0], [1]],
                                   product_name_list=['测试产品01', '测试产品02'],
                                   total_amount=5000,
                                   sign_date='2019-01-12',
                                   start_at='2018-12-21',
                                   approve_status='approved',
                                   DepartmentId=0):
        url = self.base_url + 'api/contracts'
        if len(goods_id_list) != len(quantity_list):
            print(u'产品数组与数量数组不一致,请修改!')
            return
        if len(goods_id_list) != len(price_list):
            print(u'产品数组与价格数组不一致,请修改!')
            return
        product_assets_attributes = []
        for i in range(len(goods_id_list)):
            product_info = {
                'product_id': goods_id_list[i],
                'recommended_unit_price': price_list[i],
                'quantity': quantity_list[i],
                'product_attr_id': '',
                'product_name_list': product_name_list[i],
            }
            product_assets_attributes.append(product_info)
        body = {
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'contract_action_name': 'new',
            'contract': {
                'product_assets_attributes': [],
                'approve_status':
                approve_status,
                'id':
                '',
                'title':
                '合同%s' % self.common.get_random_int(99999999),
                'customer_id':
                self.testAddCustomer.add_customers(),
                'opportunity_id':
                '',
                'total_amount':
                total_amount,
                'sign_date':
                sign_date,
                'start_at':
                start_at,
                'end_at':
                '',
                'status':
                '',
                'sn':
                '',
                'category':
                '',
                'payment_type':
                '',
                'customer_signer':
                '',
                'our_signer':
                '',
                'revisit_remind_at':
                '',
                'special_terms':
                '',
                'user_id':
                self.user.getMyUserId(),
                'want_department_id':
                self.DepartmentId.getDepartmentId()[DepartmentId]
            }
        }
        body['contract'][
            'product_assets_attributes'] = product_assets_attributes
        response = self.common.post_json_response_json(url, body,
                                                       'add contracts')
        if not response:
            return {}
        self.response = response
        contract_id = self.response.json()['data']['id']
        self.contract_id = contract_id
        return contract_id

    #
    # #新增待审批合同关联产品
    # def add_applying_contracts_products_add(self, goods_id_list=[11012,11013],quantity_list=[[0],[1]],price_list=[[0],[1]],product_name_list=['测试产品01','测试产品02'],total_amount= 5000,sign_date = '2019-01-12',start_at='2018-12-21',approve_status = 'applying',DepartmentId=0):
    #     url = self.base_url + 'api/contracts'
    #     if len(goods_id_list) != len(quantity_list):
    #         print (u'产品数组与数量数组不一致,请修改!')
    #         return
    #     if len(goods_id_list) != len(price_list):
    #         print (u'产品数组与价格数组不一致,请修改!')
    #         return
    #     product_assets_attributes = []
    #     for i in range(len(goods_id_list)):
    #         product_info = {
    #                     'product_id': goods_id_list[i],
    #                     'recommended_unit_price':price_list[i],
    #                     'quantity': quantity_list[i],
    #                     'product_attr_id':'',
    #                     'product_name_list':product_name_list[i],
    #         }
    #         product_assets_attributes.append(product_info)
    #     body = {
    #         'utf8': '✓',
    #         'authenticity_token': self.csrf,
    #         'contract_action_name': 'new',
    #         'contract':{
    #             'product_assets_attributes':[
    #
    #             ],
    #             'approve_status': approve_status,
    #             'id': '',
    #             'title': '合同%s' % self.common.get_random_int(99999999),
    #             'customer_id': self.testAddCustomer.add_customers(),
    #             'opportunity_id': '',
    #             'total_amount': total_amount,
    #             'sign_date': sign_date,
    #             'start_at': start_at,
    #             'end_at': '',
    #             'status':'',
    #             'sn': '',
    #             'category': '',
    #             'payment_type': '',
    #             'customer_signer': '',
    #             'our_signer': '',
    #             'revisit_remind_at': '',
    #             'special_terms': '',
    #             'contract[user_id]': self.user.getMyUserId(),
    #             'contract[want_department_id]': self.DepartmentId.getDepartmentId()[DepartmentId]
    #         }
    #     }
    #     body['contract']['product_assets_attributes'] =  product_assets_attributes
    #     response = self.common.post_json_response_json(url, body, 'add contracts')
    #     if not response:
    #         return {}
    #     self.response = response
    #     contract_id = self.response.json()['data']['id']
    #     self.contract_id = contract_id
    #     return contract_id
    #
    # #新增合同草稿关联产品
    # def add_contracts_draft_products_add(self, goods_id_list=[11012,11013],quantity_list=[[0],[1]],price_list=[[0],[1]],product_name_list=['测试产品01','测试产品02'],total_amount= 5000,sign_date = '2019-01-12',approve_status='draft',DepartmentId=0):
    #     url = self.base_url + 'api/contracts'
    #     if len(goods_id_list) != len(quantity_list):
    #         print (u'产品数组与数量数组不一致,请修改!')
    #         return
    #     if len(goods_id_list) != len(price_list):
    #         print (u'产品数组与价格数组不一致,请修改!' )
    #         return
    #     product_assets_attributes = []
    #     for i in range(len(goods_id_list)):
    #         product_info = {
    #                     'product_id': goods_id_list[i],
    #                     'recommended_unit_price':price_list[i],
    #                     'quantity': quantity_list[i],
    #                     'product_attr_id':'' ,
    #                     'product_name_list':product_name_list[i],
    #         }
    #         product_assets_attributes.append(product_info)
    #     body = {
    #         'utf8': '✓',
    #         'authenticity_token': self.csrf,
    #         'contract_action_name': 'new',
    #         'contract':{
    #             'product_assets_attributes':[
    #
    #             ],
    #             'approve_status': approve_status,
    #             'id': '',
    #             'title': '合同%s' % self.common.get_random_int(99999999),
    #             'customer_id': self.testAddCustomer.add_customers(),
    #             'opportunity_id': '',
    #             'total_amount': total_amount,
    #             'sign_date': sign_date,
    #             'start_at': '',
    #             'end_at': '',
    #             'status': '',
    #             'sn': '',
    #             'category': '',
    #             'payment_type': '',
    #             'customer_signer': '',
    #             'our_signer': '',
    #             'revisit_remind_at': '',
    #             'special_terms': '',
    #             'contract[user_id]': self.user.getMyUserId(),
    #             'contract[want_department_id]': self.DepartmentId.getDepartmentId()[DepartmentId]
    #         }
    #     }
    #     body['contract']['product_assets_attributes'] =  product_assets_attributes
    #     response = self.common.post_json_response_json(url, body, 'add contracts')
    #     if not response:
    #         return {}
    #     self.response = response
    #     contract_id = self.response.json()['data']['id']
    #     self.contract_id = contract_id
    #     return contract_id
    #

    #新增任务
    def add_event_for_contract(self, contract_id):
        url = self.base_url + 'events/new?ajax_back_to=%2Fevents%3Fentity_id%3D' + str(
            contract_id) + '%26entity_klass%3DContract&entity_id=' + str(
                contract_id) + '&entity_klass=Contract'
        params = {}
        self.common.get_response_json(url, params, '合同详情页新增任务打开窗口')
        url = self.base_url + 'api/events'
        params = {
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'event[note]': '打电话给客户',
            'event[remind_at]': self.common.get_tomorrow_srt_yymmddhhmm(),
            'event[remind_type]': 'punctual',
            'event[related_item_id]': str(contract_id),
            'event[related_item_type]': 'Contract',
            'event[user_ids]': str(self.user.getMyUserId())
        }
        # print(params)
        response = self.common.post_response_json(url, params, '给单个合同新增任务')
        event_id = response.json()['data']['id']
        return event_id
Exemple #11
0
class AddExpenseCenters:
    def __init__(self, cookie, csrf):
        self.common = common.Common(cookie, csrf)
        self.testAddCustomer = AddCustomer(cookie, csrf)
        self.user = users.GetUser(cookie, csrf)
        self.DepartmentId = departmentid.GetDepartment(cookie, csrf)
        self.base_url = const.BASE_URL
        self.base_url2 = const.SIGN_IN_BASE_URL
        self.csrf = csrf
        self.cookie = cookie
        self.response = ''
        self.user_id = ''
        self.user = users.GetUser(cookie, csrf)
        self.expense_centers_id =[]
        self.params = ''
        self.expense_center_id = ''
        pass

    #新增费用
    def add_expenses(self):
        url = self.base_url +'api/expenses'
        body ={
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'expense[id]':'',
            'expense[related_item_type]':'',
            'last_expense_id':'',
            'expense[sn]': '10000',
            'expense[category]': '91962',
            'expense[description]': '10000',
            'expense[amount]': '5000',
            'expense[incurred_at]': '2018-08-28',
            'expense[customer_id]': self.testAddCustomer.add_customers(),
            'expense[contacts_expenses]':'',
            'expense[related_item_id]':'',
            'expense[revisit_log_id]':'',
            'expense[checkin_id]':'',
            'expense[user_id]': self.user.getMyUserId(),
        }
        response = self.common.post_response_json(url, body, '新增费用 api是'+url)
        if not response:
            return {}
        self.response = response
        print(response.json())
        expense_id = self.response.json()['data']['id']
        return expense_id

    #新增报销单(未开启审批 )
    def add_expense_accounts(self):
        url = self.base_url +'api/expense_accounts'
        body ={
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'expense_account[id]':'',
            'expense_account[approve_status]': 'approved',
            'expense_account[user_id]': self.user.getMyUserId(),
            'expense_account[department_id]': self.DepartmentId.getDepartmentId(),
            'expense_account[note]':'备注123',
            'expense_ids':self.add_expenses,
        }
        response = self.common.post_response_json(url, body, '新增费用 api是'+url)
        if not response:
            return {}
        self.response = response
        expense_account_id = self.response.json()['data']['id']
        return expense_account_id

    #开启审批新增报销单
    def add_expense_accounts_applying(self):
        url = self.base_url +'api/expense_accounts'
        body ={
            'utf8': '✓',
            'authenticity_token': self.csrf,
            'expense_account[id]':'',
            'expense_account[approve_status]': 'applying',
            'expense_account[user_id]': self.user.getMyUserId(),
            'expense_account[department_id]': self.DepartmentId.getDepartmentId(),
            'expense_account[note]':'备注123',
            'expense_ids':self.add_expenses,
        }
        response = self.common.post_response_json(url, body, '新增费用 api是'+url)
        if not response:
            return {}
        self.response = response
        expense_account_id = self.response.json()['data']['id']
        return expense_account_id