Hello, I want to open wizard with action server.
How to open this wizard when I click on action server and open with context and active_ids.
start:
- hr_expense_sheet.py
- hr_expense_sheet_view.xml
wizard:
- edit_date_expense_sheet_view.xml
- edit_date_expense_sheet_wizard.py
part xml view (hr_expense_sheet_view.xml) :
<record id="change_date_expense_sheet_server" model="ir.actions.server">
<field name="name">Change validation date</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="rp_hr.model_hr_expense_sheet"/>
<field name="state">code</field>
<field name="code">
if context.get('active_model') == 'edit.hr.expense.wizard' and context.get('active_ids'):
env['edit.hr.expense.wizard'].browse(context['active_ids']).open_wizard()
</field>
</record>
<record id="change_date_expense_sheet_values" model="ir.values">
<field name="name">Change validation date</field>
<field name="model_id" ref="model_hr_expense_sheet"/>
<field name="model">hr.expense.sheet</field>
<field name="key2">client_action_multi</field>
<field eval="'ir.actions.server,%d'%change_date_expense_sheet_server" name="value"/>
</record>
edit_date_expense_sheet_wizard.py :
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class EditHrExpenseSheetDateWizard(models.TransientModel):
_name = 'edit.hr.expense.wizard'
validation_date = fields.Many2one('hr.expense.sheet', string="Validation date")
@api.multi
def validate_modifications():
print "validate_modifications"
return True
# @api.multi
# def approve_expense_sheets(self):
# self.write({'state': 'approve', 'validation_date': fields.Date.today(), 'responsible_id': self.env.user.id})
@api.multi
def open_wizard(self):
print "call wizard function 1"
return {
'view_type': 'form',
'view_mode': 'form',
'view_id': 'change_date_expense_sheet_form',
'res_model':'edit.hr.expense.wizard',
'target': 'current',
'type': 'ir.actions.act_window',
}
print "call wizard function 2"
Wizard view : edit_date_expense_sheet_view.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="change_date_expense_sheet_form" model="ir.ui.view">
<field name="name">Change date expense sheet</field>
<field name="model">edit.hr.expense.wizard</field>
<field name="priority">1</field>
<field name="arch" type="xml">
<form name="Change Date Expense Sheet">
<field name="validation_date"/>
<footer>
<button string="Validate" class="oe_highlight" type="object" name="validate_modifications"/>
<button string="Cancel" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="change_expense_sheet_action" model="ir.actions.act_window">
<field name="name">Change Date Expense Sheet</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">edit.hr.expense.wizard</field>
<field name="view_type">form</field>
<field name="view_id" ref="rp_hr.change_date_expense_sheet_form"/>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</odoo>
Tanks a lot .
Hello
karim bryant
Try below code in your server action xml file.
if model == 'edit.hr.expense.wizard' and env.context.get('active_ids'):
env['edit.hr.expense.wizard'].browse(env.context['active_id']).open_wizard()
tanks Hiren.
Get an idea from here: http://learnopenerp.blogspot.com/2020/01/open-wizard-on-button-click-in-odoo.html
if you solved this could you give a hand on how did you do it?