This question has been flagged
13 Replies
9871 Views

I need the file & dcb fields to follow different sequecing ,
for example-
the field 'file' need to follow sequencing like F0001, F0002.....(or like F2500, F2501,...)
and the field 'dcb' neet to follow sequencing like D0001, D0002,....(or like D5600, D5601,...)
to achieve this,
i wrote the code in my py file given below,..

class easy_filedcb(osv.Model):
    _name="easy.filedcb"
    _columns={
        'file': fields.char('File', size=64,readonly=True),
        'dcb':fields.char('DCB', size=64,readonly=True),
        }
    
    def create(self, cr, uid, vals, context=None):
           if vals.get('file','/')=='/':
                   vals['file'] = self.pool.get('ir.sequence').get(cr, uid, 'easy.filedcb') or '/'
            return super(easy_filedcb, self).create(cr, uid, vals, context=context)
    
    def create(self, cr, uid, vals, context=None):
           if vals.get('dcb','/')=='/':
                   vals['dcb'] = self.pool.get('ir.sequence').get(cr, uid, 'easy.filedcb') or '/'
            return super(easy_filedcb, self).create(cr, uid, vals, context=context)
    _defaults = {
        'dcb': lambda obj, cr, uid, context: '/',
        'file': lambda obj, cr, uid, context: '/',  
                }
 
easy_filedcb()


and i created an xml file filedcb_sequence.xml and updated this in openerp.py file
the code is given below,

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
 
        <record id="seq_easy_filedcb_type" model="ir.sequence.type">
            <field name="name">dcb</field>
            <field name="code">easy.filedcb</field>
        </record>
        <record id="seq_dcbnumber" model="ir.sequence">
            <field name="name">dcb</field>
            <field name="code">easy.filedcb</field>
            <field name="prefix">D</field>
            <field name="padding">4</field>
        </record>
            <record id="seq_easy_filedcb_type" model="ir.sequence.type">
            <field name="name">file</field>
            <field name="code">easy.filedcb</field>
        </record>
        <record id="seq_filenumber" model="ir.sequence">
            <field name="name">file</field>
            <field name="code">easy.filedcb</field>
            <field name="prefix">F</field>
            <field name="padding">4</field>
        </record>
               
    </data>
</openerp>

the result i got is not acceptable.

the field 'file' sequencing like D0001, D0002,.....
and the field 'dcb' sequencing like / , / , .....(ie, only front slash)

when i inter changed the position of 'def create' function for 'file' & 'dcb' in the class,

the field 'dcb' sequencing like D0001, D0002,.....
and the field 'file' sequencing like / , / , .....(ie, only front slash)

 

how can i solve this problem...?
(i achieved the result for single field with the code of same pattern, but when two field came the problem also came)

i need help.

 

Avatar
Discard
Best Answer

Using the below code to assign  sequence number for two different fields in the same class.

Method 1:

class easy_filedcb(osv.osv):
_name="easy.filedcb"
_columns={
'file': fields.char('File', size=64),
'dcb':fields.char('DCB', size=64),
}

def next_by_code(self, cr, uid, sequence_code, name, context=None):
seq_obj = self.pool.get('ir.sequence')
seq_obj.check_access_rights(cr, uid, 'read')
company_ids = self.pool.get('res.company').search(cr, uid, [], order='company_id', context=context) + [False]
ids = seq_obj.search(cr, uid, ['&','&',('code','=', sequence_code),('name','=',name),('company_id','in',company_ids)])
return seq_obj._next(cr, uid, ids, context)

def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
vals['file'] = self.next_by_code(cr, uid, 'easy.filedcb', 'file', context=context) or '/'
vals['dcb'] = self.next_by_code(cr, uid, 'easy.filedcb', 'dcb', context=context) or '/'
return super(easy_filedcb, self).create(cr, uid, vals, context=context)

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="seq_easy_filedcb_type" model="ir.sequence.type">
<field name="name">dcb</field>
<field name="code">easy.filedcb</field>
</record>

<record id="seq_dcbnumber" model="ir.sequence">
<field name="name">dcb</field>
<field name="code">easy.filedcb</field>
<field name="prefix">D</field>
<field name="padding">4</field>
</record>

<record id="seq_filenumber" model="ir.sequence">
<field name="name">file</field>
<field name="code">easy.filedcb</field>
<field name="prefix">F</field>
<field name="padding">4</field>
</record>
</data>
</openerp>

Method 2:

create second sequence with other object name (Any Master screen used in the custom module and sequence No does not used in that screen)  and call in the same class

EXample:-

 class easy_filedcb(osv.Model):
_name="easy.filedcb"
_columns={
'file': fields.char('File', size=64,readonly=True),
'dcb':fields.char('DCB', size=64,readonly=True),
}

def create(self, cr, uid, vals, context=None):
vals['dcb'] = self.pool.get('ir.sequence').get(cr, uid, 'easy.filedcb') or '/'
vals['file'] = self.pool.get('ir.sequence').get(cr, uid, 'other.mastername') or '/'
return super(easy_filedcb, self).create(cr, uid, vals, context=context)


_defaults = {
'dcb': lambda obj, cr, uid, context: '/',
'file': lambda obj, cr, uid, context: '/',
}

easy_filedcb()

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">

<record id="seq_easy_filedcb_type" model="ir.sequence.type">
<field name="name">dcb</field>
<field name="code">easy.filedcb</field>
</record>
<record id="seq_dcbnumber" model="ir.sequence">
<field name="name">dcb</field>
<field name="code">easy.filedcb</field>
<field name="prefix">D</field>
<field name="padding">4</field>
</record>
<record id="seq_easy_file_type" model="ir.sequence.type">
<field name="name">file</field>
<field name="code">other.mastername</field>
</record>
<record id="seq_filenumber" model="ir.sequence">
<field name="name">file</field>
<field name="code">other.mastername</field>
<field name="prefix">F</field>
<field name="padding">4</field>
</record>
</data>
</openerp>
Avatar
Discard
Author

Dear Prakash, u said, " In 'ir.sequence.type' object 'code' is unique so it allow one sequcence for one class". i understand the meaning. but i cant assign 'other.mastername' to the field 'dcb', because i dont know how to.. so i changed type of field of 'dcb' from 'char' to many2one and defined sequencing there in the class and modified the code in xml file. eventhough i got the result, but i want to know the method to achieve the result without changing the field type from char to many2one... hep me......,

Hi Ullas, No need to change datatype many2one field. In the module if you are using any other master data and does not contain any sequence. Then create sequence for that master data and call sequence in your object.

Hi Ullas, I updated the answer with possible solution pls check the same.

Thanks, Prakash..
i tried the method 2, its very simple and working as i expected. Now i understand the meaning of 'code' in ir.sequence and its uniqueness, thanks for correct direction and help.

On Thu, Sep 11, 2014 at 1:15 PM, Prakash <prakash-jain-sunarctechnologies-com@mail.odoo.com> wrote:

Hi Ullas, I updated the answer with possible solution pls check the same.



Sent by OpenERP S.A. using Odoo about Forum Post False



--
ULLAS
Best Answer

Hi everyone I'm getting the same problem the fields incremented following the other.

Any help please

Avatar
Discard
Best Answer

Ullas,

Over ride create method.

sequence_required=self.pool.get('ir.sequence').next_by_code(cr, uid, 'your sequence code'). Assign this value to your fields. I hope this will solve your problem. Good Luck

Avatar
Discard
Author

Dear Samba,. thanks for your quick reply. i wrote like this, and removed default values... def create(self, cr, uid, values, context=None): values['filen'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') values['dcb'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') return super(easy_filedcb, self).create(cr, uid, values, context=context) then the problem changed like this,.. 'file' = D0019 'dcb'=D0020 if i create one more entry, 'file'=D0021 'dcb'=D0022 what to do now...? how to solve this...?

Ullas,

Change your code like this.
***************************************************************************
 def create(self, cr, uid, values, context=None):
       seq_required=self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') 
       values['filen'] =seq_required 
       values['dcb'] =seq_required
       return super(easy_filedcb, self).create(cr, uid, values, context=context)

**********************************************************************************


On Sun, Sep 7, 2014 at 11:50 PM, Ullas A <ullasaei@mail.odoo.com> wrote:

Dear Samba,. thanks for your quick reply. i wrote like this, and removed default values... def create(self, cr, uid, values, context=None): values['filen'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') values['dcb'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') return super(easy_filedcb, self).create(cr, uid, values, context=context) then the problem changed like this,.. 'file' = D0019 'dcb'=D0020 if i create one more entry, 'file'=D0021 'dcb'=D0022 what to do now...? how to solve this...?

--
Ullas A
Sent by Odoo Inc. using Odoo about Forum Post False

Samba, i changed the code as u said, but the fields are getting incremented simultaneously....not as i  expected..
example,.
if the field 'file' getting the value D1000, at the same time the field 'dcb' also getting the value D1000...like this..
i need the field to be incremented independently..
if i set the filed 'file' 1000, and the field 'dcb' set to 2000 then, on next creation, the field 'file' need to become 1001, and the 'dcb' becomes 2001.
so, what will i do...?

On Mon, Sep 8, 2014 at 11:07 AM, Samba Odoo <sambaodoo@gmail.com> wrote:
Ullas,

Change your code like this.
***************************************************************************
 def create(self, cr, uid, values, context=None):
       seq_required=self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') 
       values['filen'] =seq_required 
       values['dcb'] =seq_required
       return super(easy_filedcb, self).create(cr, uid, values, context=context)

**********************************************************************************


On Sun, Sep 7, 2014 at 11:50 PM, Ullas A <ullasaei@mail.odoo.com> wrote:

Dear Samba,. thanks for your quick reply. i wrote like this, and removed default values... def create(self, cr, uid, values, context=None): values['filen'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') values['dcb'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'easy.filedcb') return super(easy_filedcb, self).create(cr, uid, values, context=context) then the problem changed like this,.. 'file' = D0019 'dcb'=D0020 if i create one more entry, 'file'=D0021 'dcb'=D0022 what to do now...? how to solve this...?

--
Ullas A
Sent by Odoo Inc. using Odoo about Forum Post False

--
samba
Sent by OpenERP S.A. using Odoo about Forum Post False



--
ULLAS
Best Answer

Actually you shouldn't write Create Method twice... because it will be exactly overriding it again..

So your code should  be like this.....

def create(self, cr, uid, vals, context=None):
           if vals.get('file','/')=='/':
                   vals['file'] = self.pool.get('ir.sequence').get(cr, uid, 'easy.filedcb') or '/'

           if vals.get('dcb','/')=='/':
                   vals['dcb'] = self.pool.get('ir.sequence').get(cr, uid, 'easy.filedcb') or '/'
            return super(easy_filedcb, self).create(cr, uid, vals, context=context)

Avatar
Discard
Author

i tried this code, but did,t work as i expected... output: the field 'file' increases like D0001, and at the same tile the field 'dcb' get the value D0002, like this each time am getting the fields incremented following the other.

U have to use two different sequence for those different fields.hi

Sent from Yahoo! Mail on Android



From: Ullas A <ullasaei@mail.odoo.com>;
To: deep <deepa4lok@yahoo.com>;
Subject: Re: False
Sent: Wed, Sep 10, 2014 5:30:45 PM

i tried this code, but did,t work as i expected... output: the field 'file' increases like D0001, and at the same tile the field 'dcb' get the value D0002, like this each time am getting the fields incremented following the other.

--
Ullas A
Sent by Odoo Inc. using Odoo about Forum Post False