问题
I want to add to my purchase order a 'cancel' button. This button will change the state of my record to 'canceled'. When the user click on this button the script verify all the purchase inquiries and provider orders if there is any one not done or canceled yet. I want to add a pop-up to warn the user about them. The user can cancel the operation or pursuit and cancel all the related inquiries and orders.
This is my wizard model :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class confirm_wizard(models.TransientModel):
_name = 'tjara.confirm_wizard'
yes_no = fields.Char(default='Do you want to proceed?')
@api.multi
def yes(self):
return True
@api.multi
def no(self):
return False
My wizards view :
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="confirm_wizard_form">
<field name="name">wizard.form</field>
<field name="model">tjara.confirm_wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Confirm dialog">
<field name="yes_no" readonly="1" />
<footer>
<button class="oe_highlight" name="yes" string="Yes" />
<button class="oe_highlight" name="no" string="No" />
</footer>
</form>
</field>
</record>
</data>
</odoo>
The button :
<button string="Canceled" type="object" name="canceled_progressbar" class="oe_highlight" attrs="{'invisible': [('state', '=', 'done')]}"/>
And finally the two methods :
@api.multi
def return_confirmation(self):
return {
'name': 'Are you sure?',
'type': 'ir.actions.act_window',
'res_model': 'tjara.confirm_wizard',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
}
@api.multi
def canceled_progressbar(self):
if(self.return_confirmation()):
#Do some code
else:
#Do some code
The model is triggered only when the button is pointed on return_confirmation method. Which make me incapable to pursuit my code. Only a pop-up appear then disappear when the user click on a button. I want to call the return_confirmation (pop-up) via the canceled_progressbar, so I can return the value and moving on.
回答1:
You should return the Action directly from def canceled_progressbar
method, instead of defining it separately.
Also, I don't think your method def return_confirmation
will be able to receive the value the way you tried by returning either 'True' or 'False'.
Here you should directly add your code in the wizard based on the clicking 'Yes' or 'No' buttons, the one that you are planning in def return_confirmation
.
回答2:
Well, this is what I wrote :
@api.multi
def yes(self):
print 'yes function'
self.env['tjara.purchase_order'].function1()
@api.multi
def no(self):
print 'no function'
self.env['purchase_order'].function1()
The 'canceled_progressbar' method return :
@api.multi
def canceled_progressbar(self):
print 'canceled_progressbar'
return {
'name': 'Are you sure?',
'type': 'ir.actions.act_window',
'res_model': 'tjara.confirm_wizard',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
}
And I added two function according to the confirmation :
@api.multi
def function1(self):
print 'this function 1'
@api.multi
def function2(self):
print 'this function 2'
I was wondering if I can make only one function but it seems like impossible.
Thank you all for helping.
回答3:
You can add:
confirm="Your Custom message like Are you sure you want to process this?"
in button in xml.
来源:https://stackoverflow.com/questions/43983595/odoo-10-call-a-confirmation-form-yes-no-from-wizard