Skip to Content
Menu
This question has been flagged
8 Replies
3930 Views

Consider a Path 

Patient -> selected Patient -> Prescriptions -> New

On that path there's a prescription form, in that form there are two buttons "button 1" and "button 2", now i want to these two buttons when Path is like that 

Patient -> selected Patient -> New  

Now i am able to open new Prescription form on button click using code like that 


def goto_prescription_form(self, cr, uid, ids, context=None):

      return {

             'type': 'ir.actions.act_window',

             'name': 'Reffer Patient to Physician',

             'res_model': 'oeh.medical.prescription',

             'view_type': 'form',

             'view_mode': 'form',

       }

Avatar
Discard
Author Best Answer

So i found a solution to that issue. Solution is i set a value in conext like that

def goto_prescription_form(self, cr, uid, ids, context=None):
      return {
             'type': 'ir.actions.act_window',
             'name': 'Reffer Patient to Physician',
             'res_model': 'oeh.medical.prescription',
             'view_type': 'form',
             'view_mode': 'form',
             'context': {'refer':True}
       }

and in xml file i make it invisible like that 

<button invisible="context.get('refer')" type="object"/>


Avatar
Discard
Best Answer

Ahmed,

Which ever field/button you want to hide on adding 'new' form, just  add this to your xml,

<button/field name="name_of _field" attrs="{'invisible':[('id', '=' ,False)]}"/>

as id will be False when a new form is opened(it will generate once you save the form)

and before this just add id field to your view and keep it hidden as:

<field name="id" invisible="1"/>


Hope this help!    

Avatar
Discard
Author

Thank You "Pawan" for your Help. But i want to hide those two buttons when path is like that "Patient -> selected Patient -> New", i don't want to hide buttons when path are like "Patient -> selected Patient -> Prescriptions -> New"

those buttons are in "perscriptions" object, right??
If yes, then how can u see them from being at "patient" object
can u pls elaborate it... so that i can help u ...

Author

So Basically "prescription" is model, and it model name is like "medical.prescription" So basically what i was thinking is to create a new form view for that model and that form view don't have those two buttons, and i call that form on that specific path. How is that ?

Author

@pawan is it possible to create multiple form view of a model ? Could you plz help me with code

@ahmed,
Sorry for the delay....yes it is possible to create multiple form view form a model... please elaborate your requirement so that i can help(if you still need ;) )..

Best Answer

Pass context in the the return , and on the form view use attrs for button based on that context .

Avatar
Discard
Author

I am not clear yet, could you please explain your answer with code. Please Thank You

Related Posts Replies Views Activity
0
Sep 23
496
0
Sep 23
450
2
Feb 23
9253
6
Oct 23
19272
3
Mar 24
7688