This question has been flagged
1 Reply
6718 Views

My requirement is OpenERP should throws a warning message when i click a Cancel button in Sale order. In warning wizard, If i press OK then state of Sale order should be changed to cancel or if i press button cancel the wizard should close and state wont change.

Wizard is shown, but my problem is when i click any button (OK or Cancel or Close (X)), the state of Sale order is changed. I need to control this for only pressing OK button. If i click other button it should close a warning or wizard box.

 

Installed : warning_box module(Author: Jme Steve)

Inherit a sale module and button here. As per details given in waning_box module, i created a line in end of cancel button for picking a 

i customized a warning message 

Sale Order file.

 def cancel_ordersss(self,cr,uid,ids,context=None):
        self.write(cr, uid, ids, {'state':'cancel'})
        return self.pool.get('warning_box').warning(cr, uid, title='Cancel Order', message='Are you sure to cancel this order')
        

Wizard file

<openerp> 
    <data> 
        <record id="warning_box_form" model="ir.ui.view">
             <field name="name">warning_box.form</field> 
             <field name="model">warning_box</field> 
             <field eval="20" name="priority"/> 
             <field name="arch" type="xml"> 
                 <form string="Warning" version="7.0"> 
                     <field name="message" nolabel="1"/> 
                     <footer> 
                        <button string="OK" name="message" type="object" class="oe_highlight" special="cancel"/> 
                        or
                        <button class="oe_link" name="return_false" type="object" string="Cancel"/> 
                        
                     </footer> 
                 </form> 
            </field>
        </record>
    
        <record model="ir.actions.act_window" id="action_warning_box">
            <field name="name">Warning Box</field>
            <field name="res_model">warning_box</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="warning_box_form" />
            <field name="target">new</field>
        </record>
    </data>
 
</openerp>

 

Kindly provide a solution to solve this problem. 

 

--------------------------------------------------------------------------------------------------------------

I created my own module to do that. For that also having errors. kindly suggest a solution.

Wizard view file

<record id="view_cancel_order_wizard" model="ir.ui.view">
            <field name="name">Cancel Repair</field>
            <field name="model">sale.order.confirm</field>
            <field name="arch" type="xml">
                <form string="Confirm Sale Order" version="7.0">
                    <group>
                        <label string="This Sale Order will be confirmed with service Product. Agree?"/>
                    </group>
                    <footer>
                        <button name="action_cancel" string="Yes" type="object" class="oe_highlight"/>
                        or
                        <button string="Cancel" class="oe_link" special="cancel" />
                    </footer>
                </form>
            </field>
        </record>

Wizard Python file

import time
from lxml import etree

from osv import fields, osv
from tools.translate import _
import pooler
    
class sale_order_confirm(osv.osv):
    _name = "sale.order.confirm"
    _description = "Sales Order Confirm"

def action_cancel(self, cr, uid, ids, context=None):
        assert len(ids) == 1, 'This option should only be used for a single id at a time.'
        #~ wf_service = netsvc.LocalService('workflow')
        #~ wf_service.trg_validate(uid, 'sale.order', ids[0], 'order_confirm', cr)
        self.write(cr, uid, ids, {'state':'cancel'})
        # redisplay the record as a sales order
        view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sale.order.confirm', 'view_cancel_order_wizard')
        view_id = view_ref and view_ref[1] or False,
        return {
            'type': 'ir.actions.act_window',
            'name': _('Sales Order'),
            'res_model': 'sale.order',
            'res_id': ids[0],
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': view_id,
            'target': 'current',
            'nodestroy': True,
        }
        return True
        

sale_order_confirm()

Getting error invalid xml when i start update this module. Kindly suggest a solution.

Avatar
Discard
Best Answer

Hi,

Try below code in your customized module

In view.xml

<button name="action_cancel_yes" string="YES" type="object" class="oe_highlight"/>

<button name="action_cancel_no" string="NO" type="object" class="oe_highlight"/>

In python

def action_cancel_yes(self, cr, uid, ids, context=None):

       return True

def action_cancel_no(self, cr, uid, ids, context=None):

      raise osv.except_osv(_('Alert !!'), _('Your sale order is  NOT Cancel'))

 

Avatar
Discard