Search code examples
pythonodooodoo-8odoo-10

odoo call a method on button from anthor class


Hello everyone i want to call a method from another object but i can't how to fix that to call a method this is my code xml i'm using an record to inherit button to create a button call my method

<record id="view_send_email_homework" model="ir.ui.view">
    <field name="name">send.email.homework</field>
    <field name="model">homework.student</field>
    <field name="inherit_id" ref="parent_access.view_homework_student_form"/>
    <field name="arch" type="xml">
        <xpath expr="//button[@name='send_message']" position="replace">
            <button
                name="send_mail" type="object"
                string="Envoyer"
                class="oe_highlight"
            />
        </xpath>
    </field>
</record>  

the method is defined on another object my code python

          class send_email_homework(models.Model):
          _name = 'send.email.homework'
          _inherit = 'homework.student'

         def send_mail(self, cr, uid, ids, context=None):
             email_template_obj = self.pool.get('email.template')

he shows me this message when i press on button

AttributeError: 'homework.student' object has no attribute 'send_mail'


Solution

  • You must remove _name = 'send.email.homework' because in that types of inheritance you can not inherit methods. it only inherit fields...

    Replace your code using following:

    class send_email_homework(models.Model):
            _inherit = 'homework.student'