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.

1

How to create different sequence number for an object?(please help me)

By
rosey
on 9/24/14, 7:55 AM 3,543 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...

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.

Saravanan Sakthivel
on 9/25/14, 5:52 AM

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.

rosey
on 9/27/14, 5:41 AM

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

Prakash
on 9/29/14, 1:21 AM

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

Saravanan Sakthivel
on 9/30/14, 12:59 AM
1
Saravanan Sakthivel
On 9/30/14, 1:01 AM

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>

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

Dimple
on 9/30/14, 1:52 AM

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

Saravanan Sakthivel
on 9/30/14, 1:58 AM

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.

rosey
on 9/30/14, 3:15 AM

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

rosey
on 9/30/14, 3:18 AM

i cant point what was the issue.

rosey
on 9/30/14, 3:18 AM

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)

Saravanan Sakthivel
on 9/30/14, 3:47 AM

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

Saravanan Sakthivel
on 9/30/14, 3:49 AM

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?

rosey
on 9/30/14, 5:01 AM

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.

rosey
on 9/30/14, 5:15 AM

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

Saravanan Sakthivel
on 9/30/14, 5:20 AM

Issue is fixed.

rosey
on 9/30/14, 5:26 AM

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.

rosey
on 9/30/14, 5:27 AM

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

Saravanan Sakthivel
on 9/30/14, 5:35 AM

In the above view.xml file i have already given

Saravanan Sakthivel
on 9/30/14, 5:46 AM

but its not working i checked it.

rosey
on 9/30/14, 5:56 AM

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

Saravanan Sakthivel
on 9/30/14, 6:01 AM

yes.

rosey
on 9/30/14, 6:23 AM

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

Saravanan Sakthivel
on 9/30/14, 6:27 AM

Can i post my code?

rosey
on 9/30/14, 7:01 AM

yeah sure.!

Saravanan Sakthivel
on 9/30/14, 7:05 AM

I posted my code please check it.

rosey
on 9/30/14, 7:18 AM

I have changed the code,plz take a look.

Saravanan Sakthivel
on 9/30/14, 7:29 AM

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

rosey
on 9/30/14, 8:16 AM

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

rosey
on 9/30/14, 8:36 AM

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

Saravanan Sakthivel
on 10/1/14, 12:13 AM

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

rosey
on 10/1/14, 5:46 AM

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

Saravanan Sakthivel
on 10/1/14, 5:51 AM

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

3 follower(s)

Stats

Asked: 9/24/14, 7:55 AM
Seen: 3543 times
Last updated: 3/16/15, 8:10 AM