This question has been flagged
1 Reply
3171 Views

I am using odoo11, and i am working on the following code, that adds a menu item in the "action" dropdown for sale orders, in order for the user to confirm multiple sale orders at once:


Python:

class SaleOrderConfirmWizard(models.TransientModel):
    _name = "sale.order.confirm.wizard"
    _description = "Wizard - Sale Order Confirm"

    @api.multi
    def confirm_sale_orders(self):
        self.ensure_one()
        active_ids = self._context.get('active_ids')
        orders = self.env['sale.order'].browse(active_ids)
        for order in orders:
            print(order.id)
            if order.state in ['draft', 'sent']:
                order.action_confirm()
 

XML:

    <record id="view_confirm_sale_order" model="ir.ui.view">
        <field name="model">sale.order.confirm.wizard</field>
        <field name="arch" type="xml">
            <form string="Confirm Sale Orders">
                <footer>
                    <button name="confirm_sale_orders" string="Confirm" type="object" class="oe_highlight"/>
                    or
                    <button string="Cancel" class="oe_link" special="cancel" />
                </footer>
            </form>
        </field>
    </record>

    <record id="action_confirm_sale_order" model="ir.actions.act_window">
        <field name="name">Confirm Sale Orders</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">sale.order.confirm.wizard</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="view_confirm_sale_order" />
        <field name="target">new</field>
        <field name="multi">True</field>
    </record>

    <act_window id="confirm_sale_order"
        name="Confirm Sale Orders"
        src_model="sale.order"
        res_model="sale.order.confirm.wizard"
        view_type="form"
        view_mode="form"
        key2="client_action_multi"
        target="new"/>

Now, I may be blind, but I can't see anywhere the reference to the treeview (which is "sale.view_order_tree" if im not wrong) this stuff should appear in.

I wanted something similar for the "quotation" treeview, and i thought i had to change some view reference (quotations are still instances of "sale.order" model, so i guess i have to change nothing on the model side)...

But, as strange as it sounds, i cannot find in this code any reference to the sale order treeview to change. I am probably missing something very evident, so please forgive this pretty dumb question.

Thank you in advance


EDIT:

I can't really explain why, but now i can see the new menu item even in the quotation page (maybe i didn't refresh properly the page?). In any case, i'd like to know if its normal that there is no explicit reference to the view?

Avatar
Discard
Best Answer

Didn't get why you added 2 act windows.

For your purpose, ie to confirm together multiple sale records, the action button should only appear only in the tree view, and not in the form view.

So after you defined the view (id="view_confirm_sale_order")
you'll need to define just one act window

something like

<act_window id="action_confirm_multiple_orders"
            name="Confirm Multiple orders"
            key2="client_action_multi"
            view_mode="form"
            multi="True"
            target="new"
            src_model="sale.order"
            res_model="sale.order.confirm.wizard"
        />


Instead of 2 act windows.

Please accept and Upvote, if useful.

Avatar
Discard
Author

Thank you for your kind answer... I must admit that i based my code on stuff i found online. Probably the original author was interested in making the menu voice appear in both kind of views...

Cheers