Search code examples
odooopen-sourceodoo-9odoo-10

How to call server action from a button click in odoo web client


I want to create a student mark-sheet for which I need information about

  1. Student name
  2. Course to which student belongs
  3. units under that course
  4. syllabus under each unit
  5. syllabus has certain criteria under them

Hierarchy explained:- student is enrolled in a course, 1 course has several units, 1 unit have a certain syllabus(divided in chapters), each chapter has a criteria for which evaluation is to be done. Mark-sheet is based on either a course or a unit and score is given for each criteria.

So, for this I was thinking if I could load units, syllabus and criteria for this hierarchy by executing sql in a server action and calling that action through a button in mark-sheet form.

While trying I just wrote a log statement in server action and tried to call it by using <button type="action" name="%(action_name)d" string="log"/>, but it didn't do anything.

Also please suggest alternatives to do this, in case this is not a good way or not possible to do so in odoo web client.

Thanks in advance for help.

Server action This is the server Action

I am using it as <button type="action" name="%(getUnitsForCourse)d" string="log"/> in my view, but it is neither doing anything nor giving any errors. When i call it from Action button in header it is running correctly and logging the results.


Solution

  • Instead of type="action" you need to use type="object" in button and need to create py function as we are using type="object".

    For example.

    XML

    <button type="object" name="test_server_action" string="call Server Action"/>
    

    PY

     @api.multi
     def test_server_action(self):
        self.env.ref('external_id  of  server action').run()