This question has been flagged
1 Reply
11512 Views

Help with my code I don't know where i seem to be going wrong. Thank you in advance

class sale_order_confirm(osv.osv):
_name = 'sale.order.confirm'
_inherit = "sale.order"


def my_action_button_confirm(self, cr, uid, ids, context=None):
    wf_service = netsvc.LocalService('workflow')
    if context is None:
        context = {}

  #  record_id = context and context.get('ids', False)
    pool_obj = pooler.get_pool(cr.dbname)
    order = pool_obj.get('sale.order').read(cr, uid, ids, ['state'], context=context)
    for o in order:
        if not o.order_line:
            raise osv.except_osv(_('Error'),_("Cannot confirm order without order line"))
        wf_service.trg_validate(uid, 'sale.order', o.id, 'order_confirm', cr)

   #        view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sale', 'view_order_form')
   #        view_id = view_ref and view_ref[1] or False,

    return {'type': 'ir.actions.act_window_close'}

   sale_order_confirm()

   <openerp>
       <data>
    <record id="view_sale_confirm_order" model="ir.ui.view">
        <field name="name">sale.order.confirm.form1</field>
        <field name="model">sale.order.confirm</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Confirm Sale Orders">
                <separator colspan="4" string="Do you really want to confirm order(s) ?" />
                <separator string="" colspan="6"/>
                <button special="cancel" string="Cancel" icon="gtk-cancel"/>
                <button name="my_action_button_confirm" string="Confirm SO" icon="gtk-execute" type="object"/>
           </form>
        </field>
    </record>        

    <act_window id="action_sale_order_confirm_sales"
        multi="True"
        key2="client_action_multi" name="Confirm SO"
        res_model="sale.order.confirm" src_model="sale.order"
        view_mode="form" target="new" view_type="form" />

    <record model="ir.values" id="sale_order_confirm_sales">
        <field name="model_id" ref="sale.model_sale_order" />
        <field name="name">Confirm SO</field>
        <field name="value" eval="'ir.actions.act_window,' + str(ref('action_sale_order_confirm_sales'))"/>
        <field name="key">action</field>
        <field name="model">sale.order</field>
    </record>

</data>

</openerp>

help please and thank you in advance log message is

2013-08-20 15:30:14,575 7100 INFO ? werkzeug: 127.0.0.1 - - [20/Aug/2013 15:30:14] "POST /web/action/load HTTP/1.1" 200 -
2013-08-20 15:30:14,851 7100 INFO ? werkzeug: 127.0.0.1 - - [20/Aug/2013 15:30:14] "POST /web/view/load HTTP/1.1" 200 -
2013-08-20 15:30:15,608 7100 INFO ? werkzeug: 127.0.0.1 - - [20/Aug/2013 15:30:15] "POST /web/dataset/create HTTP/1.1" 200 -
2013-08-20 15:30:15,742 7100 INFO ? werkzeug: 127.0.0.1 - - [20/Aug/2013 15:30:15] "POST /web/dataset/get HTTP/1.1" 200 -
2013-08-20 15:30:15,946 7100 INFO ? werkzeug: 127.0.0.1 - - [20/Aug/2013 15:30:15] "POST /web/dataset/call_button HTTP/1.1" 200 -
2013-08-20 15:30:15,966 7100 INFO ? werkzeug: 127.0.0.1 - - [20/Aug/2013 15:30:15] "POST /web/session/eval_domain_and_context HTTP/1.1" 200 -
2013-08-20 15:30:16,188 7100 INFO ? werkzeug: 127.0.0.1 - - [20/Aug/2013 15:30:16] "POST /web/dataset/search_read HTTP/1.1" 200 -
Avatar
Discard
Best Answer

Ok, i will try something :

 class sale_order(osv.osv):
    _inherit = "sale.order"

    def my_action_button_confirm(self, cr, uid, ids, context=None):
        wf_service = netsvc.LocalService('workflow')
        if context is None:
            context = {}
        print "ids",ids
        order = self.read(cr,uid,ids,['state'])
        print "order",order
        for o in order:
            print "o",o
            if not o.order_line:
                raise osv.except_osv(_('Error'),_("Cannot confirm order without order line"))
            wf_service.trg_validate(uid, 'sale.order', o.id, 'order_confirm', cr)

    return {'type': 'ir.actions.act_window_close'}
sale_order()

<openerp>
    <data>
         <record id="view_sale_confirm_order" model="ir.ui.view">
             <field name="name">sale.order.confirm.form1</field>
             <field name="model">sale.order</field>
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <form string="Confirm Sale Orders">
                     <separator colspan="4" string="Do you really want to confirm order(s) ?" />
                     <separator string="" colspan="6"/>
                     <button special="cancel" string="Cancel" icon="gtk-cancel"/>
                     <button name="my_action_button_confirm" string="Confirm SO" icon="gtk-execute" type="object"/>
                </form>
             </field>
         </record>        

        <act_window id="action_sale_order_confirm_sales"
            multi="True"
            key2="client_action_multi" name="Confirm SO"
            res_model="sale.order" view_mode="form"
            src_model="sale.order" view_type="form"/>

        <record model="ir.values" id="sale_order_confirm_sales">
            <field name="model_id" ref="sale.model_sale_order" />
            <field name="name">Confirm SO</field>
            <field name="value" eval="'ir.actions.act_window,' + str(ref('action_sale_order_confirm_sales'))"/>
            <field name="key">action</field>
            <field name="model">sale.order</field>
        </record>
    </data>
</openerp>

Please can you post the log now ?

Avatar
Discard
Author

thanks for your response. I was trying to create a confirm button for multiple Sales order in tree view. the error comes up when i click the confirm button.

Multiple Sales order in tree view ? What's exactly going on ? In which view are you ? What would you doing with you button ?

I guess you want to select multiple sales orders in the tree view in purpose to validate them in one click ?

Author

I have imported some sales order into openerp from access about 100 of them and I want to confrm them all without doing it one at a time. So i want to create a button that allows me to confirm one or many sales order at once from tree view. this orders are old but needed them for tracability of past sales. Yes i want to validate many selected SOs in one click. Thank you so much

Author

Yes is the answer to your last question.

This is an operation you should repeat often ? Because if it's no, maybe a script is more indicate (or more ugly : edit directly in db with a sql script). Anyway, your mandatories fields in each sale order are well filled ?

Author

Yes the is an operation that will be repeated many times because SO are validated in batches therefore will need this function. I have tried but i keep getting error not sure if my xml or python code is letting me down. Will be glad if you can help.

Author

Yes they are all filled. Like i said they are old sales that i imported into the system

I've edited my answer.

Author

Thanks will do those and get back to you.

Author

I have made changes to the code above but i am still not getting anything. The application loads but does nothing

Author

I made the changes but nothing is still happening can you please check if my xml is correct as well. Thank so very much for your help, merci beaucoup

Yes i know, my new edit don't change anything but normally it prints some values on the logs. And this should help for debugging. I take a look on the xml.

Author

Your new edit does not work the confirm so button did not show up on Sales Order I added src_model="sale.order" to bring it to Sales order. Now is shows but when I click it tries to create a new quote.

And now ?

Author

It tries to create a new sales order/quote

Ok, i have no more ideas. Sorry. Can you keeping me in touch if you find, please.

Author

Ok, thanks for your time