0

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'

Matt
  • 1,518
  • 4
  • 16
  • 30
Caludio
  • 135
  • 11
  • is it odoo 8 or 9? – Vishnu VaNnErI Sep 21 '18 at 10:36
  • Is there a reason why you're creating a completely new model (and its database table) with `_name` and `_inherit` different in comparison? This inheritance is just inheriting model fields but no methods. So first you should clear that inheritance idea, before somebody can really answer your questions. Because the answer depends on it. – CZoellner Sep 21 '18 at 12:25

1 Answers1

1

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'
  • You guys just assume the models and relations with no idea, what his real requirements are. This answer and like every other one could be just wrong. – CZoellner Sep 21 '18 at 12:22