Hi,
I had added a auto-incremented field in the customer form and the supplier. My problem is when I add a new customer automatically the supplier_code is incremented: in the res_partner table I had 2 fields(row) code_client and code_supplier when I add a new customer or a new supplier the code_cleint or the code_supplier is incremented even that I had not add a supplier.
My code is as follow:
python file:
class snc_specify(osv.osv):
_name='res.partner'
_inherit='res.partner'
_columns={
# 'max-mont':fields.float('Credit Maximum',required=True,digits_compute=dp.get_precision('deci3')),
'code_tva' : fields.char('Code TVA',translate=True,size=50),
'code_client' : fields.char('Code Client', size=64),
'code_supplier' : fields.char('Code Fournisseur', size=64),
}
_sql_constraints = [
('name_uniq', 'unique(code_client, company_id)', 'Number of client must be unique!'),
('name_uniq', 'unique(code_supplier, company_id)', 'Number of supplier must be unique!'),
]
def create_cl(self, cr, uid, vals, context=None):
context = context or {}
if not vals.get('code_client') and self._needscode(cr, uid, vals=vals,
context=context):
vals['code_client'] = self.pool.get('ir.sequence')\
.next_by_code(cr, uid, 'res.partner.customer')
return super(snc_specify, self).create_cl(cr, uid, vals, context)
def create_fr(self, cr, uid, vals, context=None):
context = context or {}
if not vals.get('code_supplier') and self._needscode(cr, uid, vals=vals,
context=context):
vals['code_supplier'] = self.pool.get('ir.sequence')\
.next_by_code(cr, uid, 'res.partner.supplier')
return super(snc_specify, self).create_fr(cr, uid, vals, context)
def copy_cl(self, cr, uid, id, default=None, context=None):
default = default or {}
if self._needscode(cr, uid, id=id, context=context):
default['code_client'] = self.pool.get('ir.sequence')\
.next_by_code(cr, uid, 'res.partner.customer',
context=context)
return super(snc_specify, self).copy_cl(cr, uid, id, default,
context=context)
def copy_fr(self, cr, uid, id, default=None, context=None):
default = default or {}
if self._needscode(cr, uid, id=id, context=context):
default['code_supplier'] = self.pool.get('ir.sequence')\
.next_by_code(cr, uid, 'res.partner.supplier',
context=context)
return super(snc_specify, self).copy_fr(cr, uid, id, default,
context=context)
_defaults = {
'code_client': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'res.partner.customer'),
'code_supplier': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'res.partner.supplier'),
}
sequence file:
<openerp>
<data noupdate="1">
<!-- Incrementation code -->
<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">CL</field>
<field name="padding">5</field>
<field name="company_id" eval="False"/>
</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">FR</field>
<field name="padding">5</field>
<field name="company_id" eval="False"/>
</record>
</data>
</openerp>
Help me please.