This question has been flagged
1 Reply
15356 Views

I have an object named purchase.order,

I want to create 3 different menus and i want to generate 3 different sequence for these three menus.

Menus                                                   Sequence number

Purchase order                                     PO00006

Request for material                             RFM00006

Request for product                              RFP00006

How can i create three different sequence number for same object?

 

Another doubt:

There are draft and confirmed purchase orders. I want to generate sequence number only for the confirmed quotations.

How can i do that?

 

 

Code

.py

 

from openerp.osv import fields, osv

from openerp.tools.translate import _

 

class purchase_seq(osv.osv):

    _inherit = 'purchase.requisition'

    _columns = {

                'sequence_type':fields.selection([('mr','Material Request'),('pr','Purchase Requisition')],'Sequece Type'),

           }

    def create(self, cr, uid, vals, context=None):        

        if context is None:

            context = {}

        if vals.get('sequence_type') == 'mr':

            vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'material.order') or '/'

            print "vals['name']1",vals['name']

        if vals.get('sequence_type') == 'pr':

            vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition') or '/'  

            print "vals['name']2",vals['name']

        return super(purchase_seq, self).create(cr, uid, vals, context=context)

    

purchase_seq()

 

view.xml

<?xml version="1.0" encoding="utf-8"?>

<openerp>

    <data>    

        <record id="purchase_sequence_form" model="ir.ui.view">

            <field name="name">purchase.sequence.form.inherit</field>

            <field name="model">purchase.requisition</field>

            <field name="inherit_id" ref="purchase_requisition.view_purchase_requisition_form"/>

            <field name="arch" type="xml">

                <field name='name' position='after'>

                    <field name="sequence_type"/>

               </field>

            </field>

        </record>

 

<record id="purchase_menu1" model="ir.actions.act_window">

            <field name="name">Material Request</field>

            <field name="type">ir.actions.act_window</field>

            <field name="res_model">purchase.requisition</field>

            <field name="domain">[('sequence_type','=',mr)]</field>

            <field name="view_mode">tree,form</field>

        </record>

        <record id="purchase_menu2" model="ir.actions.act_window">

            <field name="name">Purchase Requisitions</field>

            <field name="type">ir.actions.act_window</field>

            <field name="res_model">purchase.requisition</field>

            <field name="domain">[('sequence_type','=',pr)]</field>

            <field name="view_mode">tree,form</field>

        </record>

     </data>

</openerp>

 

sequence.xml

<?xml version="1.0" encoding="utf-8"?>

<openerp>

    <data>

 

       

        <record id="seq_dcbnumber" model="ir.sequence">

            <field name="name">Material Request</field>

            <field name="code">material.order</field>

            <field name="prefix">RFM</field>

            <field name="padding">4</field>

        </record>

        

        <record id="seq_filenumber" model="ir.sequence">

            <field name="name">Purchase Requisition</field>

            <field name="code">purchase.order.requisition</field>

            <field name="prefix">RPQ</field>

            <field name="padding">4</field>

       </record>

     </data>

</openerp>

But its not generating the sequence number. I think my code has any mistake, but i dont know to fix it. Please help me...

Avatar
Discard

hi rosey.Create one selection type field which contain three type.Based on the type(PO,RM,RP) you write condition and generate sequence number in the confirm button function.

Author

Hi Saravanan, i know how to generate sequence number. But i dont know how to generate based on a condition. I dont know python code.

Using  *Context * to create three different sequence number for same object. For example in the created 3 different menu in the 3 different action. xml window action pass the context value. In the window action 1 Quotations ir.actions.act_window purchase.order *            {'purchase': True}* [] tree,form,graph,calendar In the window action 2 *      {'reqestformaterial': True}* In the window action 3 *       {'reqestforproduct': True}* And create 3 sequence in xml and python create method using context get sequence value. def create(self, cr, uid, vals, context=None): if context is None: context = {} if context.get('purchase'): vals['name'] = // refer the link same object more than one sequence field get if context.get('reqestformaterial'): vals['name'] = // refer the link same object more than one sequence field get if context.get('reqestforproduct'): vals['name'] = // refer the link same object more than one sequence field get return super(employee_sequence, self).create(cr, uid, vals, context=context) Refer the link [1]*https://www.odoo.com/forum/help-1/question/how-to-assign-sequence-number-for-two-different-fields-in-the-same-class-62046   *   to get more than one sequence number for same object. [1] https://www.odoo.com/forum/help-1/question/how-to-assign-sequence-number-for-two-different-fields-in-the-same-class-62046

Hi Rosey,You just try this code sequence.xml Material Request material.order.requisition RFM 4 Purchase Requisition purchase.order.requisition RPQ 4 .py from openerp.osv import fields, osv from openerp.tools.translate import _ class purchase_seq(osv.osv): _inherit = 'purchase.requisition' _columns = { 'sequence_type':fields.selection([('mr','Material Request'),('pr','Purchase Requisition')],'Sequece Type',readonly=True), } def create(self, cr, uid, vals, context=None): if context is None: context = {} if context.get('sequence_type') == 'mr': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'material.order.requisition') or '/' if context.get('sequence_type') == 'pr': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition') or '/' return super(purchase_seq, self).create(cr, uid, vals, context=context) purchase_seq() view.xml purchase.sequence.form.inherit purchase.requisition Reqest For Material ir.actions.act_window purchase.order [('sequence_type','=',mr)] tree,form Request Purchase Requisition ir.actions.act_window purchase.order [('sequence_type','=',pr)] tree,form

Best Answer

Hi Rosey,You just try this code

sequence.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
 
       
        <record id="seq_dcbnumber" model="ir.sequence">
            <field name="name">Material Request</field>
            <field name="code">material.order.requisition</field>
            <field name="prefix">RFM</field>
            <field name="padding">4</field>
        </record>
        
        <record id="seq_filenumber" model="ir.sequence">
            <field name="name">Purchase Requisition</field>
            <field name="code">purchase.order.requisition</field>
            <field name="prefix">RPQ</field>
            <field name="padding">4</field>
       </record>
     </data>
</openerp>

 

.py

 

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

class purchase_seq(osv.osv):
    _inherit = 'purchase.requisition'
    _columns = {
                'sequence_type':fields.selection([('mr','Material Request'),('pr','Purchase Requisition')],'Sequece Type',readonly=True),
           }
    def create(self, cr, uid, vals, context=None):        
        if context is None:
            context = {}
        if vals.get('sequence_type') == 'mr':
            vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'material.order.requisition') or '/'
        if vals.get('sequence_type') == 'pr':
            vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition') or '/'  
        return super(purchase_seq, self).create(cr, uid, vals, context=context)
    
purchase_seq()   

 

view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
        <data>
        <record id="purchase_sequence_form" model="ir.ui.view">
            <field name="name">purchase.sequence.form.inherit</field>
            <field name="model">purchase.requisition</field>
            <field name="inherit_id" ref="purchase_requisition.view_purchase_requisition_form"/>
            <field name="arch" type="xml">
                <field name='name' position='after'>
                    <field name="sequence_type"/>
               </field>
            </field>
        </record>

<record id="purchase_menu1" model="ir.actions.act_window">
            <field name="name">Reqest For Material</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">purchase.order</field>

            <field name="view_type">form</field>   
            <field name="view_id" ref="purchase.your_tree_view"/>
            <field name="search_view_id" ref="purchase.your_search_filter_view"/> 
            <field name="domain">[('sequence_type','=',mr)]</field>
        </record>

<menuitem id="my_id1" action="purchase_menu1" name="PO1"
            parent="purchase.my_parent_id" sequence="2" />


        <record id="purchase_menu2" model="ir.actions.act_window">
            <field name="name">Request Purchase Requisition</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">purchase.order</field>

            <field name="view_type">form</field>   
            <field name="view_id" ref="purchase.your_tree_view"/>
            <field name="search_view_id" ref="purchase.your_search_filter_view"/> 
            <field name="domain">[('sequence_type','=',pr)]</field>
        </record>

<menuitem id="my_id2" action="purchase_menu2" name="PO2"
            parent="purchase.my_parent_id" sequence="3" />
     </data>
</openerp>

Avatar
Discard

hai saravanan, from where this 'material.order.requisition' and 'purchase.order.requisition' comes from or taken from ?

Hi dimple, It is taken from ir_sequence.We have to define this in order to get different type of sequence

Author

Hi Saravanan, i tried this code, but its not working. If condition is not working. i printed the vals[name] in both case but it is not getting any value.

Author

I am inheriting purchase.requisition base model. and already my two menu are present.

Author

i cant point what was the issue.

Hi Rosey,Can you try this, def create(self, cr, uid, vals, context=None): if context is None: context = {} if vals.get('sequence_type') == 'mr': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'material.order.requisition') or '/' if vals.get('sequence_type') == 'pr': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition') or '/' return super(purchase_seq, self).create(cr, uid, vals, context=context)

Sry i forgrot to change the code,try this vals.get('sequence_type') == 'mr' instead of context.get('sequence_type').

Author

Still the same issue. if vals.get('sequence_type') == 'mr': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'material.order.requisition') or '/' print "vals['name']1",vals['name'] // doesnt print any value if vals.get('sequence_type') == 'pr': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition') or '/' print "vals['name']2",vals['name'] //here print RFM0022 But sequence number of mr is RFM and pr is RPQ. Then it is wrong na?

Author

Sorry Saravanan, its a mistake from me. Now it is clear. Can we seperate both the request. ie,Now it is lke--- When we create a material request it can also see in the purchase requisition window and viceversa. I wants--- when we create a material request it doesnt show in purchase requisition window.

kindly print and check,what value vals.get('sequence_type') holds.You having two menu item rit??.one is for material request,another one for purchase requisition. Also comment this code in default" 'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition')".and again If you got nothing mail me the module(saravanan.it28@gmail.com).

Author

Issue is fixed.

Author

I want to ask you another thing---Can we seperate both the request. ie,Now it is lke--- When we create a material request it can also see in the purchase requisition window and viceversa. I wants--- when we create a material request it doesnt show in purchase requisition window.

Yeah you can seperate rosey.For that you have to define your menu record item domain. Reqest For Material ir.actions.act_window purchase.order [('sequence_type','=',mr)] tree,form Request Purchase Requisition ir.actions.act_window purchase.order [('sequence_type','=',pr)] tree,form

In the above view.xml file i have already given

Author

but its not working i checked it.

Did you removed that noupdate="1" from view.xml

Author

yes.

It works for me.I dono what is happening in your code.

Author

Can i post my code?

Author

I posted my code please check it.

I have changed the code,plz take a look.

Author

NameError: name 'mr' is not defined. it shows the error. when i update my code.

Author

Already there is menu present. Then why should add again?

You need two menu right?.one is for mr and another one is pr.

Author

Yes right. But in my case the two menus are already present.

Okay if you have two menu item,then map the following record id(purchase_menu1,purchase_menu2) respective action definition in menuitem.