Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
7 Vastaukset
4516 Näkymät

Hi,

I'm new to Odoo. I have module "crm.lead" and my module "record.clone". Now I want to create a record that has some fields I need of the recent record has just been created.

Example: When I click on button "Create" in CRM and fill info on form, after that it will create a record in CRM, I want to create a record the same as that record in my module (maybe has less fields than CRM). How can I do that ? (Sorry for my english.)

Avatar
Hylkää
Paras vastaus

Ok, The solution is to override create method of odoo. The idea is to override create method and on the click of create button method update or create new record in "record.clone" model. Below is how you can override odoo create method:

class Campus(models.Model):
    _name='campus'    
    @api.model
    def create(self,values):
        campus_create = super(Campus,self).create(values)
        return campus_create

For more details

Reference: https://goo.gl/4BkizH

Avatar
Hylkää

For more details

Reference: https://goo.gl/4BkizH

Paras vastaus

Hello Hserht,

you have to inherit crm model like this.

class CRM(models.Model):

    _inherit = 'crm.lead'    


    @api.model

    def create(self,values):

        result = super(CRM,self).create(values)

        clone_vals = {

                        what are all the fields you want pass here, you can get fields data from values

                        }

        self.env['record.clone'].create(clone_vals)

        return result


make sure record.clone model have create permission for logged in user

Avatar
Hylkää
Tekijä Paras vastaus

I can't comment in your answer because I dont have enough Karma, sorry about that.

Maybe you're not clear my problem (or my english is bad). The point is when I click button "Create" IN "crm.lead" NOT IN "record.clone".  CRM will create a record, and so does my module. (1 click create 2 record , one in CRM and one in mine).

Avatar
Hylkää
Tekijä

I found solution. Just creating some fields in module "record.clone" which is the same type as fields in "crm.lead", and create another models that _inherit models "crm.lead" (ex. "CRMLeadinherit"), then override create method in "crm.lead" and create the clone record in that method:

class CRMLeadinherit(models.Model):

_inherit='crm.lead'

@api.model

def create(self,values):

result = super(CRMLeadinherit,self).create(values)

vals = {'name': values.get('name'), ...}

return result

thanks Sehrish for your help !

Tekijä

'name' in vals is a fields that have the same type with values['name'] belongs to "record.clone" :))

welcome :)

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
elok. 25
1448
0
toukok. 25
728
0
elok. 24
1039
2
maalisk. 24
1346
1
heinäk. 22
2664