Omeed Totakhel
Omeed Totakhel

Reputation: 487

Open another module form view with button

I am trying to open another model form view but receiving error external id not found.

in the py file

class ru_assignments(models.Model):
 name = 'ru.assignments

class ru_assignments_sub(models.Model):
_name = 'ru.assignments.sub'

This is ru_assignments_sub xml

        <record model="ir.actions.act_window" id="action_sub">
        <field name="name">Assignment Sub</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">ru.assignments.sub</field>
        <field name="view_type">form</field>
        <field name="view_id" ref="ru_assignments_sub_view"/>
    </record>

this is ru_assignments xml view where i made button to open ru_assignments_sub window

        <record id="ru_assignments_view" model="ir.ui.view">
        <field name="name">Assignments Form View</field>
        <field name="model">ru.assignments</field>
        <field name="arch" type="xml">
        <form string="Assignments">
                <sheet>
                    <button type="action" name="%(ru_assignments_sub.action_sub)d" string="Submit" class="oe_right oe_highlight"/>
                    <div class="oe_title">
                        <label for="teacher"/>
                        <field name="teacher" required="1" placeholder="e.g. Business Administration"/>
                    </div>
                    <group>
                        <field name="batch"/>
                        <field name="class_id"/>
                        <field name="faculty"/>
                    </group>
                    <notebook>
                        <page string="Related Students">
                            <field name="students"/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

This is the openerp.py file

    # always loaded
'data': [
    # 'security/ir.model.access.csv',
    'ru_students/workflow/workflow.xml',
    'ru_students/students_view.xml',
    'ru_students/sequence.xml',
    'ru_students/address_view.xml',
    'ru_teacher/teacher_view.xml',
    'ru_teacher/batch_view.xml',
    'ru_teacher/sequence.xml',
    'ru_faculty/faculty_view.xml',
    'ru_batch/batch_view.xml',
    'ru_class/class_view.xml',
    'ru_subjects/subjects_view.xml',
    'ru_standards/standards_view.xml',
    'ru_schedule/schedule_view.xml',
    'ru_assignments_sub/assignments_sub_view.xml',
    'ru_assignments/assignments_view.xml',
    'ru_attendance/op_attendance_sheet_view.xml',
    'ru_attendance_line/op_attendance_line_view.xml',
    'ru_invoice/invoice_view.xml',
    'ru_invoice_line/invoice_line_view.xml',
    'ru_exam_line/exam_line_view.xml',
    'ru_exam/exam_view.xml',
    'ru_menu/menu.xml',
    'css.xml',

Upvotes: 1

Views: 7582

Answers (1)

Tintumon M
Tintumon M

Reputation: 1164

There are two method to call Open another module form view using button.

  1. Object Button:

Write this in python

def show_ru_assignments_sub_view(self, cr, uid, ids, context=None):
    return {
        'name': ('Assignment Sub'),
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'ru.assignments.sub',
        'view_id': False,
        'type': 'ir.actions.act_window',
        'target':'new'
    }

write this button in XML:

<button name="show_ru_assignments_sub_view" string="Submit" type="object" status="draft" />
  1. Action Button

Write both of this coding in XML:

<record id="action_assignments_sub_view" model="ir.actions.act_window">
        <field name="name">Assignment Sub</field>
        <field name="res_model">ru.assignments.sub</field>
        <field name="src_model">ru.assignments</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
        <field name="context">{'order_id': active_id}</field>
    </record>

For button action

<button name="%(action_assignments_sub_view)d" type="action" string="Submit" />

Upvotes: 3

Related Questions