İçereği Atla
Menü
Bu soru işaretlendi
7 Cevaplar
4525 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç

For more details

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

En İyi Yanıt

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
Vazgeç
Üretici En İyi Yanıt

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
Vazgeç
Üretici

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 !

Üretici

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

welcome :)

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Ağu 25
1458
0
May 25
735
0
Ağu 24
1056
2
Mar 24
1346
1
Tem 22
2670