Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

open the same form from button

By
Julian Osorio
on 5/11/16, 7:08 PM 236 views
Hello
I want to doisthe following

1. Aformis filled
2.when clickingon the "done" buttonanda dialog boxappears with twofields of the sameform
3.fills andclick onaccept thedialog
4.changes the status of"draft"to"done"
5.the two fieldson the form


my questionsis

1. the contextto pass dataused inthe actionorthe button
asseriouscontext

2.
aswould defineinpythonmove from"drafta" done "

Thank you


<header>
    <button name="%(action_done)d" type="action"
  string="done"
attrs="{'invisible': [('state','=', 'done')]}"
class="oe_highlight"/>
</header>
<sheet>
<field name="name"/>
<field name="field 1" attrs="{'invisible': ['!', ('state', '=', 'done')]}"/>
<field name="field 2" attrs="{'invisible': ['!', ('state', '=', 'done')]}""/>
</sheet>



          <field name="arch" type="xml">
<form>
<group class="oe_title">
<field name="field 1"/>
<field name="field 2"/>
</group>
<footer>
<button name="action_done" string="done" type="object" class="btn btn-sm btn-primary"/>
<button string="Cancel" class="btn btn-sm btn-default" special="cancel"/>
</footer>
</form>
</field>
 

    <record id="action_done" model="ir.actions.act_window">
<field name="name">done</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">model.model</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_model_done_form"/>
<field name="target">new</field>
    </record>

 

2
Gavin Yap
On 5/12/16, 3:59 AM

I believe you cannot do in this way.


First of all, in your "action_done", it does not have a res_id reference. To would meant that when you open up the form, the form does not know which record in the model to reference to and hence, your popup form will be empty.


What you can do is instead of using "%(action_done)d", you could create a method in your model.


@api.multi
def action_done(self):
 id = self.id
   return {
'name': self.name,
'res_model': 'module.Model',
'type': 'ir.actions.act_window',
'context': {},
'view_mode': 'form',
'view_type': 'form',
      'view_id': self.env.ref('module.my_form_view'),
'target': 'current',
}


and change your button to

<button name="action_done" type="object" .. />



0
Julian Osorio
On 5/12/16, 3:19 PM

Thanks,

it worked

@api.multi
def action_done(self):
return {
'name': self.name,
'res_model': 'calendar.event',
'type': 'ir.actions.act_window',
'res_id': self.id,
'context': {},
'view_type': 'form',
'view_mode': 'form',
'views': [(self.env.ref('ceiinc_crm.view_calendar_event_done_form').id, 'form')],
'view_id': self.env.ref('ceiinc_crm.view_calendar_event_done_form').id,
'target': 'new',

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/11/16, 7:08 PM
Seen: 236 times
Last updated: 5/12/16, 3:19 PM