콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
6 답글
20355 화면

I'm trying to create a module that will do some stuff on install. As I understand it, I need to create a model with an init method and place my code there. This is what I have so far;

class geo_subdivision(models.Model):
    _name = 'geo_subdivision.geo_subdivision'
    def init(self,cr):
        res_country = self.env['res.country']

I'm getting;

AttributeError: 'geo_subdivision.geo_subdivision' object has no attribute 'env'

Google has turned up a lot of conflicting information and trying everything suggested elsewhere has gotten me nowhere.

If my appraoch correct? Is this even the correct method to use for my purpose?


아바타
취소
작성자

I should mention; I'm on Odoo 9.

작성자

@Bharat;

Tried your suggestion.

I get;

ImportError: cannot import name models

Changing back to my original import;

from openerp import models, fields, api

I get;

AttributeError: 'module' object has no attribute 'model_cr'

i updated my answer that's same as yours and it is works for me well.

작성자

Using exactly what you have below gives me;

AttributeError: 'geo_subdivision.geo_subdivision' object has no attribute 'env'

Basically, back to what I started with.

작성자

I did finally figure this out and the answer was as Yousif has posted. Unfortunately the site won't allow me to post answers, so I could post my findings.

베스트 답변

hello ,

if you want to call function when install the module you can try this method :

from openerp import models
class geo_subdivision(models.Model):
     _name = 'geo_subdivision.geo_subdivision'
 
def myfunction(self):
         res_country = self.env['res.country']


<openerp>  
<data>
  
 <function model="geo_subdivision.geo_subdivision" name="myfunction"/>
</data>
</openerp>




아바타
취소

one thing this function will be called even when you upgrade the module

yes , it will be called when you install/upgrade the modules.

베스트 답변

i think you need to try like this,

from openerp import models
class geo_subdivision(models.Model):
     _name = 'geo_subdivision.geo_subdivision'
     
     def init(self,cr):
         res_country = self.env['res.country']

 

I hope this will help you.

아바타
취소
관련 게시물 답글 화면 활동
2
9월 24
44
2
8월 24
1533
2
8월 22
27205
0
12월 23
17
1
4월 24
7507