Skip to Content
Menu
This question has been flagged
1 Reply
5339 Views

Hi,

I'm creating a wizard to write the refuse reason for Applicant (hr.applicant). I want receive the value of the fields on wizard form before it be saved. Is there any way to do it?

Code to open wizard

@api.multi
def archive_applicant_sure(self):
return {
'name': _('Update Your Refuse Reason'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'view_type': 'form',
'res_model': 'hr.applicant',
'target': 'new',
'view_id': self.env.ref('icoeuro_hr.hr_applicant_interview_refuse_wizard', False).id,
'res_id': self.id,
}

Wizard form

<!-- Refuse wizard -->
<record model="ir.ui.view" id="hr_applicant_interview_refuse_wizard">
<field name="name">hr.applicant.refuse.wizard.form</field>
<field name="model">hr.applicant</field>
<field name="arch" type="xml">
<form>
<group string="Refuse Reason">
<field name="refuse_reason" nolabel="1" required="1"/>
</group>
<footer>
<button string="Save" type="object" name="archive_applicant" class="oe_highlight"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>

The function that I want to receive the value

@api.multi
def archive_applicant(self, form):
print(form)
# self._context.get('refuse_reason')
if form.get('refuse_reason'):
self.action_applicant_refuse(form.get('refuse_reason'))
else:
raise UserError(_('You must type some reason'))
return {'type': 'ir.actions.act_window_close'}

Now, when I click "Save" in wizard form Odoo execute the write function then archive_applicant and the form parameter do not receive the field value. I know we can use other solution but if we have a way to do this, I think we can apply it to some other case

Avatar
Discard
Best Answer

Hello,

First of all I don't think you create a wizard in any way. You are calling a custom view (but it's not a wizard) based on hr.applicant which is a persistant model and not at all a transient model.

Second I think write method will be called after your method "archive_applicant", as your return the method that closes the view at the end of this method.

Third, I don't know how you want to get the value from field "refuse_reason" by calling the dict method get() on the "form" parameter, since it should return metadata, but maybe that's something I still have to learn and I don't know about.

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 20
5035
2
Sep 23
2920
2
Sep 22
3254
0
Jan 21
2143
1
Dec 19
4147