2015-01-15 3 views
1

Crm Lead에서 Sale Orders를 생성하는 함수를 호출하여! python 블록에서 작성된 레코드가 있습니다. 이제는 새롭게 생성 된 Sale Order에 대한 워크 플로를 테스트하려고합니다. 새로운 sale_order의 ID를 YAML로 다시 전달할 수있는 방법이 있습니까? 그럼 워크 플로 명령을 사용할 수 있습니까?! python에서 Odoo/OpenERP 테스트의 YAML로 레코드 ID 전달

+0

는 주문, CRM을 리드 등을 판매하는 :

이 금주 모임 파이썬 블록에서 그룹을 생성하고 기록 블록에서에 사용자를 추가하는 예입니다 '! workflow' 태그. – yucer

답변

1

!python 블록 안에 ID를 ir.model.data으로 저장할 수 있으며 다른 블록에서도 볼 수 있습니다. ! 내 샘플을 적용 할 수 있습니다 당신은 당신의 코드를 게시 할 경우

- 
    Create an external id 'test_group_id' 
-                                                            
    !python {model: res.groups}: |                                                    
    from openerp import SUPERUSER_ID                                                   
    obj_id = self.create(cr, uid, {'name':'Test Group'}, context=context)                                          
    imd_values = {'module':'base', 'model': model._name, 'name': 'test_group_id', 'res_id': obj_id}                                    
    id = self.pool['ir.model.data'].create(cr, SUPERUSER_ID, imd_values, context=context)                                      
    assert obj_id == ref('test_group_id'), 'saved reference should be equal'                                         
    assert id, 'external id should be saved'                                                 
- 
    The identifier 'test_group_id' should be visible from other "python" tags 
-                                                            
    !python {model: res.groups}: | 
    assert ref('test_group_id'), 'External Id should exists' 
- 
    Create user 'Test User' to include it in 'test_group_id' 
-                                                            
    !record {model: res.users, id: res_users_test, view: False}: 
    company_id: base.main_company 
    name: Test User 
    login: testuser 
    password: testuser 
- 
    Include the user in the referenced group. Then 'test_group_id' is visible from "record" tags. 
-                                                            
    !record {model: res.users, id: res_users_test}: 
    groups_id: 
     - base.test_group_id 
+0

이 해결책은'external id' ('xml_id')가이 테스트에서 유일 할 때만 작동합니다. 'yaml_import.py'에있는'process_record'의 구현은'get_id'를 사용하여 외부 id에 대한 참조 (별칭'ref')를 해결합니다. 'get_id' 메쏘드는 먼저'! python' 태그의 코드에서 접근 할 수없는'id_map'이라는 캐시를 찾습니다. ! python 태그에서 접근 할 수있는 환경 변수는'process_python' 메소드의'code_context' 사전에 정의되어 있습니다. – yucer

+0

yaml_import.py 코드를 수정하지 않으려면 그렇지 않으면'process_python'의'code_context'에 이것을 포함시킬 수 있습니다 :'{ 'yaml': self}'그리고'yaml.id_map [ 'test_group_id']로 코드 확장하기 = id' – yucer