This question has been flagged
3445 Views

Hi all,

I have 3 users firstlevel,second level and admin users.

Need 3 approval for existing sale orders /quotation activity

when I create a new quotation ,then First Level Button should visible,after click on this button Second Level Button should visible ,then only confirm sale button should visible.

user1 have only privlige is approve firstlevel,User2 has only privilege is approve second level,Admin have all rights to first and second level approval.How to acheive this task in sale order work flow?

In  sale order form ,confirm order button should shown only after this two approval. 

User 1 will shows only firstlevel button 

User 2 will shows only secondlevel button 

admin will shows these 2 button .How to acheive this task..

This is my code========================================

.py file--

 

from openerp.osv import fields, osv
from openerp.tools.translate import _

class sale_order(osv.osv):
    '''
    extension to existing sale.order model
    '''
    _inherit = 'sale.order'
    
    
    _columns = {
        'state': fields.selection([
            ('draft', 'Draft Quotation'),
            ('quotation_approved', 'First Approval'),
            ('quotation_second', 'Second Approval'),
            ('sent', 'Quotation Sent'),
            ('cancel', 'Cancelled'),
            ('waiting_date', 'Waiting Schedule'),
            ('progress', 'Sales Order'),
            ('manual', 'Sale to Invoice'),
            ('invoice_except', 'Invoice Exception'),
            ('done', 'Done'),
            ], 'Status', readonly=True, track_visibility='onchange',
            help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sales order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
    }
    
    def action_quotation_approve(self,cr,uid,ids,context=None):
        self.write(cr,uid,ids,{'state':'quotation_approved'})
        return True
    
    def action_quotation_approve_second(self,cr,uid,ids,context=None):
        self.write(cr,uid,ids,{'state':'quotation_second'})
        return True

view.xml----------------------

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
                 
        <record id="my_quotation_form" model="ir.ui.view">
            <field name="name">sale.order.form</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
            
                    <button name="action_quotation_send" position="before">
                        <button name="approve_quotation" string="First Approval" states="draft"
                            type="workflow" class="oe_highlight" groups="base.group_user"/>
                            
                          <button name="action_quotation_approve_second" string="Second Approval" states="draft"
                            type="workflow" class="oe_highlight" groups="base.group_user"/>
                    </button>
                    
                    <button name="action_quotation_send" position="attributes">
                        <attribute name="states">quotation_approved,quotation_second,sent,progress,manual</attribute>
                    </button>
                    
                    <button name="print_quotation" position="attributes">
                        <attribute name="states">quotation_approved,sent,progress,manual</attribute>
                    </button>
                    
                     <button name="action_button_confirm" position="attributes">
                        <attribute name="states">quotation_approved,quotation_second,sent,progress,manual</attribute>
                    </button>
                    
                    
                    <field name="state" position="attributes">
                        <attribute name="statusbar_visible">draft,quotation_approved,quotation_second,sent,progress,done</attribute>
                    </field>  
            </field>
        </record>
        <record id="my_action_quotations" model="ir.actions.act_window">
            <field name="name">My Quotations</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">sale.order</field>
            <field name="view_type">tree</field>
            <field name="view_id" ref="sale.view_quotation_tree"/>
            <field name="view_mode">tree,form,calendar,graph</field>
            <field name="context">{'search_default_my_sale_orders_filter': 1}</field>
            <field name="domain">[('state','in',('draft','quotation_approved','quotation_second', 'sent','cancel'))]</field>
            <field name="search_view_id" ref="sale.view_sales_order_filter"/>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                You Can See Here all the Approval Types Here
              </p><p>
                Odoo will help you handle efficiently the complete sale flow:
                from the quotation to the sales order, the
                delivery, the invoicing and the payment collection.
              </p><p>
                The social feature helps you organize discussions on each sales
                order, and allow your customers to keep track of the evolution
                of the sales order.
              </p>
            </field>
        </record>

        <menuitem action="my_action_quotations"
            name="Approval Details"
            id="menu_my_quotation"
            parent="base.menu_sales"
            sequence="99"/>

workflow.xml-------

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="act_quotation_approved" model="workflow.activity">
            <field name="wkf_id" ref="sale.wkf_sale"/>
            <field name="name">Approved</field>
            <field name="kind">function</field>
            <field name="action">action_quotation_approve()</field>
        </record>
        <record id="trans_quotation_draft_to_approved" model="workflow.transition">
            <field name="act_from" ref="sale.act_draft"/>
            <field name="act_to" ref="act_quotation_approved"/>
            <field name="signal">approve_quotation</field>
        </record>
        
        
        <record id="act_quotation_approved_second" model="workflow.activity">
            <field name="wkf_id" ref="sale.wkf_sale"/>
            <field name="name">Second</field>
            <field name="kind">function</field>
            <field name="action">action_quotation_approve_second()</field>
        </record>
        <record id="trans_quotation_draft_to_approved_second" model="workflow.transition">
            <field name="act_from" ref="sale.act_draft"/>
            <field name="act_to" ref="act_quotation_approved_second"/>
            <field name="signal">approve_quotation_second</field>
        </record> 
        
        
        
        
    </data>
</openerp>

openerp.py-------

{
    "name": "My Sale Approvals",
    "version": "1.0",
    "category": "Sales Management",
    "depends": ['sale'],
    "description": """
    This is for demo extension to sale order
    """,
    'demo': [],
    'data': [
             'sale_approval_view.xml',
             'sale_order_workflow.xml'
    ],
    'test': [],
    'author': "Me",
    'installable': True,
    'auto_install': False,

Avatar
Discard