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.

0

Increment sequence by 3

By
Tajjajt
on 4/22/13, 12:50 PM 1,923 views

I create this sequence:

sequence.py

    def create(self, cr, uid, vals, context={}):
        vals['code'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner')
        res = super(client_sequence, self).create(cr, uid, vals, context)
        return res

    _columns = {
        'code': fields.char('Code client', size=64, readonly=True),
}
    _defaults = {
        'code': lambda obj, cr, uid, context: '/',
    }

sequence.xml

<record model="ir.sequence.type" id="seqe_type_res_partner">
    <field name="name">Client code</field>
    <field name="code">res.partner</field>
</record>
<record model="ir.sequence" id="seqe_res_partner">
    <field name="name">client code</field>
    <field name="code">res.partner</field>
    <field name="prefix">CLT</field>
    <field name="padding">5</field>
    <field name="number_increment">1</field>
</record>

But the code is incremented by 3 instead of 1?? any help?

1
Atchuthan
On 7/1/13, 3:07 AM

The sequence is loaded with 001 by using _defaults and then when you use ORM create method, the sequence goes to 002 and then for your super client sequence the sequence is incremented once again so 003.

If you remove the 'code' in _defaults, the n number of times the window refreshes the value is not incremented by sequence.

In my case, I was trying to auto-generate account number using sequence and i tried using create and _defaults, so whenever the page is loaded it provides 70000001 and when the save button is clicked it goes to 70000002. so my records of account number generated were only even numbers.

0

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 4/22/13, 12:54 PM

Your

<field name="number_increment">1</field>

Must be

<field name="number_increment">3</field>

Or try this code:

def create(self, cr, uid, vals, context={}):
        vals['code'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'seqe_res_partner', context=None)
        res = super(client_sequence, self).create(cr, uid, vals, context)
        return res

No Francesco, I want to increment the code by 1 but I have this result : CLT/00001, CLT00003, CLT/00006...I don't no why??

Tajjajt
on 4/22/13, 1:12 PM

Are you sure you are calling the right sequence?

Francesco OpenCode
on 4/22/13, 1:17 PM

Here the code in front of you.. did I call the right sequence?

Tajjajt
on 4/22/13, 1:25 PM

I've updated my answer...try the new code.

Francesco OpenCode
on 4/22/13, 1:28 PM

have this erreur :

    AttributeError: 'ir.sequence' object has no attribute 'next_by_code'
Tajjajt
on 4/22/13, 1:48 PM

I dont understand your modification, I think if I'm missing calling the right sequence I would not have the correct prefix and padding...

Tajjajt
on 4/22/13, 1:51 PM

If you go in the settings menu and select the sequence can you see the increment value setted with 1?

Francesco OpenCode
on 4/22/13, 1:53 PM

yes the increment value = 1

Tajjajt
on 4/22/13, 2:43 PM

I modify this value to 2 but still have the increment by 3 ?!!!!!

Tajjajt
on 4/22/13, 2:46 PM

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

1 follower(s)

Stats

Asked: 4/22/13, 12:50 PM
Seen: 1923 times
Last updated: 3/16/15, 8:10 AM