Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
3664 Tampilan

Hello, I have a question for imports csv with Odoo. I have a function who to call a webservices according to fields in my model. When I import a csv file, this function is called. However, I don't want this function is called. How to do ? PS : This function for webservices is called when I create or when I modify a record.

Code :

# Appel cette méthode quand on créé un nouvel enregistrement
 @api.model def create(self, vals):
   record = super(ResPartnerSchool, self).create(vals)
   record.changed_half_pension()
   return record

# Appel cette méthode quand on modifie un enregistrement
@api.multi def write(self, vals):
    result = super(ResPartnerSchool, self).write(vals)
    self.changed_half_pension()
    return result

Thanks

Avatar
Buang
Jawaban Terbai

Hi PseudoWithK,

You should pass some type of value in context by overriding the method of the CSV import and add the condition in your create method for the context.

Avatar
Buang
Jawaban Terbai

Hello,

when you import the data, at that time you get some additional value into the context.

like {'tracking_disable': True, 'defer_parent_store_computation': True, 'import_file': True, '_import_current_module': '', 'install_mode': True}

so using above value of context (tracking_disable / import_file) into create method you can check that the record is create from UI or from import button.

@api.model
def create(self, vals):
    record = super(ResPartnerSchool, self).create(vals) 
    if not self.env.context.get('tracking_disable'):
        record.changed_half_pension()
    return record
Avatar
Buang
Penulis

Thanks you for your response. How to configure your example in Odoo 10 ? Have you a example in Python ?

Thanks

i update my answer. i add some demo code at there. please check

Jawaban Terbai

You have to pass custom identification field on csv file while importing

example is_import = True

then try the following code


@api.model def create(self, vals):

is_import = False 

if 'is_import' in vals.get('is_import',False):

is_import = vals.get('is_import',False)

del vals['is_import']

record = super(ResPartnerSchool, self).create(vals) 

if not is_import:

record.changed_half_pension() 

return record




@api.multi def write(self, vals): 

is_import = False 

if 'is_import' in vals.get('is_import',False):

is_import = vals.get('is_import',False)

del vals['is_import']

result = super(ResPartnerSchool, self).write(vals) 

if not is_import:

self.changed_half_pension()

return result

Avatar
Buang