Odoo Help

0

Why this code increment twice my fields

By
CHABANI
on 7/17/13, 8:46 AM 823 views

Sequence can be generated.the number is appearing automatically But it is generated at create new record and then it is also changed while saving the record. So sequence is generated as doubled as follows: C00002, C00004, C00006,..... How can I solve this sequence generated by one by one?

My .py file:

from osv import fields, osv

class res_partner(osv.osv):
    _inherit = 'res.partner'
    _name = 'res.partner'

    _columns = {
        'n_client' : fields.char('Client Number', size=64, readonly=True),
        'n_supplier' : fields.char('Supplier Number', size=64, readonly=True),
    }
    _sql_constraints = [
        ('name_uniq_1', 'unique(n_client)', 'Number of client must be unique!'),
        ('n_supplier_uniq', 'unique(n_supplier)', 'Number of supplier must be unique!'),        
    ]
_defaults = {
        'n_client': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'res.partner.customer'),
        'n_supplier': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'res.partner.supplier'),
    }

my Xml file:

 <record model="ir.sequence.type" id="seq_type_res_partner">
        <field name="name">number_client_sequence</field>
        <field name="code">res.partner.customer</field>
    </record>
    <record model="ir.sequence" id="seq_res_partner">
        <field name="name">number_client_sequence</field>
        <field name="code">res.partner.customer</field>
        <field name="prefix">C</field>
        <field name="padding">5</field>
    </record>
    <record model="ir.sequence.type" id="seq_type_res_supplier">
        <field name="name">number_supplier_sequence</field>
        <field name="code">res.partner.supplier</field>
    </record>
    <record model="ir.sequence" id="seq_res_supplier">
        <field name="name">number_supplier_sequence</field>
        <field name="code">res.partner.supplier</field>
        <field name="prefix">S</field>
        <field name="padding">5</field>
    </record>

<record id="view_mutante_form" model="ir.ui.view">
        <field name="name">res.partner.form.inherit</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form" />
        <field name="arch" type="xml">
    <xpath expr="/form/sheet/group/group/label[@for='street']" position="before">
        <field name="n_client" attrs="{'invisible':[('customer','!=',True)]}"/>
        <field name="n_supplier" attrs="{'invisible':[('supplier','!=',True)]}"/>
    </xpath>
    </field>
</record>

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 7/17/13, 8:46 AM
Seen: 823 times
Last updated: 3/16/15, 8:10 AM