Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

How to call a wizard prior to showing the tree view?

形象
odoo
形象
丢弃
1 答案
0
形象
odoo
最佳答案

Hi,

For calling wizard directly from the menu, you can see this video : How To Call Wizard From Menu Item Odoo

Sample Code:

 <record id="create_appointment_form" model="ir.ui.view">
<field name="name">create.appointment.wizard</field>
<field name="model">create.appointment</field>
<field name="arch" type="xml">
<form string="Create Appointment">
<group>
<field name="patient_id"/>
<field name="appointment_date"/>
</group>
<footer>
<button name="print_report" string="Print" type="object" class="btn-primary"/>
<button name="create_appointment" string="Create" type="object" class="btn-primary"/>
<button name="get_data" string="Get Data" type="object" class="btn-primary"/>
<button name="delete_patient" string="Delete Patient" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>

<record id="create_appointment_wizard" model="ir.actions.act_window">
<field name="name">Create Appointment</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">create.appointment</field>
<field name="view_mode">form</field>
<field name="view_id" ref="create_appointment_form"/>
<field name="target">new</field>
</record>


In the wizard you can ask user for entering some data and from here you can return the corresponding view after deleting old records or by adding domain to records.


For deleting records(if needed), you can use self.unlink()


Thanks

1 备注
形象
丢弃
形象
odoo
-

Hello Niyas,

Thank you! So I managed to call the wizard prior to showing the view. However I still cannot delete the old records in the table after I select the "year" from the wizard.

What I need to do is when I select the "year" from the input selection in the wizard, all previous records from the stock.consumption table are to be deleted. Then based on the year of the transactions from the stock.move.line table, copy those records into the stock.consumption table if the transaction year is equal to the selected "year" from the wizard.

I added below code inside the do_filter_year function which is what's called after selecting the "year" to delete the records but they are not being deleted, new records are just being added:

@api.multi

def do_filter_year(self):

if self.filter_year:

# delete stock consumption records

stocks = self.env['stock.consumption'].search([('state','=','active')])

for stock in stocks:

stock['state'] = 'cancel'

stock.unlink()