Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Unable to validate a warning message in sale order form

By
Vikram
on 6/24/14, 4:47 AM 1,907 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.

1
Rajkumar
On 6/24/14, 6:12 AM

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'))

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/24/14, 4:47 AM
Seen: 1907 times
Last updated: 3/16/15, 8:10 AM