When creating a new contact, I would like to set "Customer" to True and "supplier" to False if the contact is "Individual" and vice versa: if the contact is Company : Set "customer" to False and "supplier" to True.
I've tried to make some changes in xml file so far but nothing happns..
<field name="supplier">{[('is_company','=', True)],'default_customer': 0,'default_supplier': 1} </field>
Any suggestions?
Thank you in advance
Hereafter my .py
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
import time
import datetime
from datetime import datetime, date, time
from openerp import api
class mypartner_custom(osv.osv):
_inherit = 'res.partner'
_columns = {
'plafond_credit' : fields.float(string = 'Plafond Crédit',digits=(6,2)),
'cin' : fields.char(string = 'CIN', size=15),
}
mypartner_custom()
@api.onchange('is_company')
def change_company_type(self):
if self.is_company == True:
self.customer = False
self.supplier = True
else :
self.customer = True
self.supplier = False
Use the onchange method :
@api.onchange('company_type')
def change_company_type(self):
if self.company_type == 'person':
self.customer = True
self.supplier = False
else :
self.customer = True
self.supplier = True
Don't forget about the default values as this method is executed only when company_type value is changed..
You are using the old api so use this method instead :
def onchange_company_type(self, cr, uid, ids, company_type, context=None):
return {'value': {'customer': False, 'supplier': True}} if company_type=='person' else {'value': {'customer': True, 'supplier': False}}
And in the company_type field in xml file add this attribute
on_change="onchange_company_type(company_type)"
Override the create method, check the corresponding values, and set like you want:
def create(self, cr, uid, vals, context=None):
if vals['contact'] == "Individual":
vals['customer'] = True
vals['supplier'] = False
elif vals['contact'] == "Company":
vals['customer'] = False
vals['supplier'] = True
return super(res_partner, self).create(cr, uid, vals, context=context)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.