0

I have a custom module called admission form with some fields suppose name, phone, email, etc. how to add this form to website module using templatr to work like contact form in contact us page when filled data is automatically created in new leads. instead of leads i want it to transfer the information to my custom module.

Summary: instruction to relate website to custom module.

class AdmissionForm(models.Model):
     _name = 'admission.form'


     name = fields.Char()
     phone = fields.Integer()
     email = fields.Char()
     faculty = field.Many2one('res.faculty')
Omeed Totakhel
  • 487
  • 1
  • 10
  • 32

1 Answers1

1

In ODOO Whenever you want to performe some task at the time of creation ,then you must override create method in your model (:admission.form).

Let say you want to create a partner just after creation of the record in admission.form model then follow these steps:

  1. Override create method .
  2. Call the super with the argument and hold it value in result.
  3. Now do your task .
  4. return result.

Code snippet:

    @api.model
    def create(self, vals):
    result = super(AdmissionForm, self).create(vals)
    new_vals = dict(name=result.name,
                    phone=result.phone,
                    email=result.email,
                    is_company=1,
                    supplier=1,
                    customer=1,
                    )
    self.env['res.partner'].create(new_vals)
    return result

In case if you want to do some task before creation of record then follow these steps:

  1. Override create method .
  2. Do your task .
  3. Call the super with the argument and return it.

    @api.model
    def create(self, vals):
    new_vals = dict(name=vals.get('name'),
                    phone=vals.get('phone'),
                    email=vals.get('email'),
                    is_company=1,
                    supplier=1,
                    customer=1,
                    )
    partner=self.env['res.partner'].create(new_vals)
    return super(AdmissionForm, self).create(vals)
    
Prakash Kumar
  • 2,554
  • 2
  • 18
  • 28
  • @parakash sorry i edit my question but dont know why it revert back to old one. I want to add a form in website just like contact form in contact us page. When customer fill the form new lead is auto created – Omeed Totakhel Apr 15 '16 at 06:34
  • so create a template , put the form in side and set the url of your controller where you want to handle the data , Now on the controller you can access the model by request.env['admission.form'] , – Prakash Kumar Apr 15 '16 at 06:41
  • Sounds logic parakash! Can u please show me an examplr i never used controller, it can be very simple just name field will work fine. Thanks in advance – Omeed Totakhel Apr 15 '16 at 07:00
  • try this link https://github.com/odoo/odoo/blob/9.0/addons/website_sale/controllers/main.py – Prakash Kumar Apr 15 '16 at 07:25
  • Prakash checked the linked got very confused. I dont know how controller work. I am saying if you could post a simple one here just pass the name field from website to module – Omeed Totakhel Apr 15 '16 at 08:02
  • 1
    just visit https://github.com/odoo/odoo/blob/9.0/addons/website_sale/views/templates.xml#L68 for form xml and https://github.com/odoo/odoo/blob/9.0/addons/website_sale/controllers/main.py#L359 for controller – Prakash Kumar Apr 15 '16 at 09:05
  • hi @Omeed hope your query has been resolved after visiting the previously shared link [about form xml and controller action ] – Prakash Kumar Apr 19 '16 at 19:16