Added fields.related field type
bzr revid: hda@tinyerp.com-20080918112857-4ixoi25qv33lum32
This commit is contained in:
parent
c8298ab59f
commit
9abaa999e9
|
@ -125,7 +125,7 @@ def _lang_get(self, cr, uid, context={}):
|
|||
ids = obj.search(cr, uid, [], context=context)
|
||||
res = obj.read(cr, uid, ids, ['code', 'name'], context)
|
||||
return [(r['code'], r['name']) for r in res]
|
||||
|
||||
|
||||
|
||||
class res_partner(osv.osv):
|
||||
_description='Partner'
|
||||
|
@ -153,6 +153,8 @@ class res_partner(osv.osv):
|
|||
'active': fields.boolean('Active'),
|
||||
'customer': fields.boolean('Customer'),
|
||||
'supplier': fields.boolean('Supplier'),
|
||||
'city':fields.related('address','city',type='char', string='City'),
|
||||
'country':fields.related('address','country_id','name',type='char', string='Country'),
|
||||
}
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
|
@ -166,7 +168,7 @@ class res_partner(osv.osv):
|
|||
name = self.read(cr, uid, [id], ['name'])[0]['name']
|
||||
default.update({'name': name+' (copy)'})
|
||||
return super(res_partner, self).copy(cr, uid, id, default, context)
|
||||
|
||||
|
||||
def _check_ean_key(self, cr, uid, ids):
|
||||
for partner_o in pooler.get_pool(cr.dbname).get('res.partner').read(cr, uid, ids, ['ean13',]):
|
||||
thisean=partner_o['ean13']
|
||||
|
@ -192,10 +194,10 @@ class res_partner(osv.osv):
|
|||
rec_name = 'ref'
|
||||
else:
|
||||
rec_name = 'name'
|
||||
|
||||
|
||||
res = [(r['id'], r[rec_name]) for r in self.read(cr, uid, ids, [rec_name], context)]
|
||||
return res
|
||||
|
||||
|
||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
|
||||
if not args:
|
||||
args=[]
|
||||
|
@ -229,12 +231,12 @@ class res_partner(osv.osv):
|
|||
})
|
||||
ids = ids[16:]
|
||||
return True
|
||||
|
||||
|
||||
def address_get(self, cr, uid, ids, adr_pref=['default']):
|
||||
cr.execute('select type,id from res_partner_address where partner_id in ('+','.join(map(str,ids))+')')
|
||||
res = cr.fetchall()
|
||||
adr = dict(res)
|
||||
# get the id of the (first) default address if there is one,
|
||||
# get the id of the (first) default address if there is one,
|
||||
# otherwise get the id of the first address in the list
|
||||
if res:
|
||||
default_address = adr.get('default', res[0][1])
|
||||
|
@ -244,11 +246,11 @@ class res_partner(osv.osv):
|
|||
for a in adr_pref:
|
||||
result[a] = adr.get(a, default_address)
|
||||
return result
|
||||
|
||||
|
||||
def gen_next_ref(self, cr, uid, ids):
|
||||
if len(ids) != 1:
|
||||
return True
|
||||
|
||||
|
||||
# compute the next number ref
|
||||
cr.execute("select ref from res_partner where ref is not null order by char_length(ref) desc, ref desc limit 1")
|
||||
res = cr.dictfetchall()
|
||||
|
@ -322,7 +324,7 @@ class res_partner_address(osv.osv):
|
|||
ids = self.search(cr, user, [('partner_id',operator,name)], limit=limit, context=context)
|
||||
else:
|
||||
ids = self.search(cr, user, [('zip','=',name)] + args, limit=limit, context=context)
|
||||
if not ids:
|
||||
if not ids:
|
||||
ids = self.search(cr, user, [('city',operator,name)] + args, limit=limit, context=context)
|
||||
if name:
|
||||
ids += self.search(cr, user, [('name',operator,name)] + args, limit=limit, context=context)
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<openerp>
|
||||
<data>
|
||||
<menuitem icon="terp-partner" id="menu_base_partner" name="Partners" sequence="0"/>
|
||||
|
||||
|
||||
<menuitem id="menu_base_config" name="Configuration" parent="menu_base_partner" sequence="1"/>
|
||||
|
||||
|
||||
<!--
|
||||
================================
|
||||
Function
|
||||
|
@ -39,7 +39,7 @@
|
|||
<field name="view_type">form</field>
|
||||
</record>
|
||||
<menuitem action="action_partner_function_form" id="menu_partner_function_form" parent="base.menu_base_config"/>
|
||||
|
||||
|
||||
<!--
|
||||
=====================
|
||||
Partner Address
|
||||
|
@ -66,7 +66,7 @@
|
|||
<field name="view_type">tree</field>
|
||||
<field name="view_id" ref="view_partner_address_tree"/>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_partner_address_form1" model="ir.ui.view">
|
||||
<field name="name">res.partner.address.form1</field>
|
||||
<field name="model">res.partner.address</field>
|
||||
|
@ -116,7 +116,7 @@
|
|||
<field name="act_window_id" ref="action_partner_address_form"/>
|
||||
</record>
|
||||
<menuitem action="action_partner_address_form" id="menu_partner_address_form" parent="base.menu_base_partner"/>
|
||||
|
||||
|
||||
<!--
|
||||
=========================================
|
||||
the short form used in the partner form
|
||||
|
@ -149,7 +149,7 @@
|
|||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!--
|
||||
=======================
|
||||
Partner Titles
|
||||
|
@ -174,7 +174,7 @@
|
|||
<field name="view_type">form</field>
|
||||
</record>
|
||||
<menuitem action="action_partner_title" id="menu_partner_title" parent="base.menu_base_config"/>
|
||||
|
||||
|
||||
<!--
|
||||
=======================
|
||||
Partner
|
||||
|
@ -188,6 +188,8 @@
|
|||
<field name="arch" type="xml">
|
||||
<tree string="Partners">
|
||||
<field name="name"/>
|
||||
<field name="city"/>
|
||||
<field name="country"/>
|
||||
<field name="title" string="Type"/>
|
||||
<field name="ref"/>
|
||||
<field name="address" string="# of Contacts"/>
|
||||
|
@ -208,6 +210,8 @@
|
|||
<field domain="[('domain', '=', 'partner')]" name="title"/>
|
||||
<field name="lang" select="2"/>
|
||||
<field name="supplier" select="2"/>
|
||||
<field name="city" select="2" />
|
||||
<field name="country" select="2" />
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="General">
|
||||
|
@ -261,7 +265,7 @@
|
|||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="action_partner_form" model="ir.actions.act_window">
|
||||
<field name="name">Partners</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
|
@ -281,9 +285,9 @@
|
|||
<field name="act_window_id" ref="action_partner_form"/>
|
||||
</record>
|
||||
<menuitem
|
||||
action="action_partner_form"
|
||||
id="menu_partner_form"
|
||||
parent="base.menu_base_partner"
|
||||
action="action_partner_form"
|
||||
id="menu_partner_form"
|
||||
parent="base.menu_base_partner"
|
||||
sequence="2"/>
|
||||
|
||||
<record id="action_partner_customer_form" model="ir.actions.act_window">
|
||||
|
@ -336,7 +340,7 @@
|
|||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="view_payterm_form"/>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_partner_bank_type_form" model="ir.ui.view">
|
||||
<field name="name">res.partner.bank.type.form</field>
|
||||
<field name="model">res.partner.bank.type</field>
|
||||
|
@ -348,7 +352,7 @@
|
|||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_partner_bank_type_tree" model="ir.ui.view">
|
||||
<field name="name">res.partner.bank.type.tree</field>
|
||||
<field name="model">res.partner.bank.type</field>
|
||||
|
@ -360,8 +364,8 @@
|
|||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
|
||||
<record id="view_partner_bank_form" model="ir.ui.view">
|
||||
<field name="name">res.partner.bank.form</field>
|
||||
<field name="model">res.partner.bank</field>
|
||||
|
@ -400,7 +404,7 @@
|
|||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!--
|
||||
======================
|
||||
Company Architecture
|
||||
|
@ -434,7 +438,7 @@
|
|||
<field eval="'ir.actions.act_window,'+str(action2)" name="value"/>
|
||||
<field eval="True" name="object"/>
|
||||
</record>
|
||||
|
||||
|
||||
<!--
|
||||
======================
|
||||
Categories
|
||||
|
|
|
@ -631,6 +631,79 @@ class function(_column):
|
|||
if self._fnct_inv:
|
||||
self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Related fields
|
||||
# ---------------------------------------------------------
|
||||
|
||||
class related(function):
|
||||
|
||||
def _fnct_search(self, cr, uid, ids, obj=None, name=None, context=None):
|
||||
print "_fnct_search >>>",ids,obj,name
|
||||
return self._fnct_search(obj, cr, uid, obj, name, args)
|
||||
|
||||
def _fnct_read(self,obj,cr, uid, ids, field_name, args, context=None):
|
||||
relation=obj._name
|
||||
res={}
|
||||
for data in obj.browse(cr,uid,ids):
|
||||
t_data=data
|
||||
relation=obj._name
|
||||
for i in range(0,len(args)-1):
|
||||
field_detail=self._field_get(cr,uid,relation,args[i])
|
||||
relation=field_detail[0]
|
||||
if field_detail[1]=='one2many':
|
||||
if t_data[args[i]]:
|
||||
t_data=t_data[args[i]][0]
|
||||
else:
|
||||
t_data=False
|
||||
break
|
||||
elif field_detail[1]=='many2one':
|
||||
if t_data[args[i]]:
|
||||
t_data=t_data[args[i]]
|
||||
else:
|
||||
t_data=False
|
||||
break
|
||||
if t_data:
|
||||
res[data.id]=t_data[args[len(args)-1]]
|
||||
else:
|
||||
res[data.id]=t_data
|
||||
return res
|
||||
|
||||
# def _fnct_write(self,obj, cr, uid, ids, name, value, args, context=None):
|
||||
# print "_fnct_write>>>",ids,name,value,args
|
||||
# if type(ids)!=type([]):
|
||||
# ids=[ids]
|
||||
# for data in obj.browse(cr,uid,ids):
|
||||
# t_data=data
|
||||
# relation=obj._name
|
||||
# for i in range(0,len(args)-1):
|
||||
# field_detail=self._field_get(cr,uid,relation,args[i])
|
||||
# relation=field_detail[0]
|
||||
# if field_detail[1]=='one2many':
|
||||
# if t_data[args[i]]:
|
||||
# t_data=t_data[args[i]][0]
|
||||
# else:
|
||||
# t_data=False
|
||||
# break
|
||||
# elif field_detail[1]=='many2one':
|
||||
# if t_data[args[i]]:
|
||||
# t_data=t_data[args[i]]
|
||||
# else:
|
||||
# t_data=False
|
||||
# break
|
||||
# if t_data:
|
||||
# query="UPDATE",relation.replace('.','_'),"set",args[len(args)-1],"=",value," where id=",t_data.id
|
||||
# print query
|
||||
# cr.execute(query)
|
||||
## return obj.write(cr,uid,data.id,{args[len(args)-1]:value})
|
||||
# return True
|
||||
|
||||
def __init__(self,*arg,**args):
|
||||
function.__init__(self,self._fnct_read, arg, self._fnct_write, fnct_inv_arg=arg,method=True, fnct_search=self._fnct_search,**args)
|
||||
|
||||
def _field_get(self, cr, uid, model_name, prop):
|
||||
cr.execute('SELECT relation,ttype FROM ir_model_fields WHERE name=%s AND model=%s', (prop, model_name))
|
||||
res = cr.fetchone()
|
||||
return res
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Serialized fields
|
||||
|
|
Loading…
Reference in New Issue