[FIX] base_contact: Assign a partner only if there is a location on the address for the creation

[IMP] base_contact: Add a view for the location

bzr revid: stw@openerp.com-20111214124041-jsnqzmu83zjbrjzf
This commit is contained in:
Stephane Wirtel 2011-12-14 13:40:41 +01:00
parent 12b454b1f6
commit c56e16ec65
2 changed files with 21 additions and 18 deletions

View File

@ -121,18 +121,6 @@ class res_partner_address(osv.osv):
_name = 'res.partner.address'
_inherits = { 'res.partner.location' : 'location_id' }
def _get_use_existing_address(self, cr, uid, ids, fieldnames, args, context=None):
result = dict.fromkeys(ids, 0)
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = 0
return result
def _set_use_existing_address(self, cr, uid, ids, field, value, arg, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
return True
_columns = {
'location_id' : fields.many2one('res.partner.location', 'Location'),
'location2_id' : fields.many2one('res.partner.location', 'Location'),
@ -146,9 +134,6 @@ class res_partner_address(osv.osv):
'date_stop': fields.date('Date Stop', help="Last date of job"),
'state': fields.selection([('past', 'Past'),('current', 'Current')], \
'State', required=True, help="Status of Address"),
'use_existing_address' : fields.function(_get_use_existing_address, type="boolean",
fnct_inv=_set_use_existing_address,
string='Use Existing Address'),
}
def name_get(self, cr, uid, ids, context=None):
@ -169,7 +154,7 @@ class res_partner_address(osv.osv):
def create(self, cr, uid, values, context=None):
record_id = super(res_partner_address, self).create(cr, uid, values, context=context)
record = self.browse(cr, uid, record_id, context=context)
if not record.partner_id:
if not record.partner_id and record.location2_id and record.location2_id.partner_id:
record.write({'partner_id' : record.location2_id.partner_id.id}, context=context)
return record_id

View File

@ -242,6 +242,25 @@
<!-- Views for Addresses -->
<record model="ir.ui.view" id="view_partner_location_tree">
<field name="name">res.partner.location.tree</field>
<field name="model">res.partner.location</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Locations">
<field name="type" />
<field name="street"/>
<field name="street2"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id" />
<field name="state_id"/>
<field name="phone"/>
<field name="fax"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_partner_address_form_inherited0">
<field name='name'>res.partner.address.form.inherited0</field>
<field name='model'>res.partner.address</field>
@ -257,12 +276,11 @@
<group colspan="6" col="2">
<field name="title" />
<field name="contact_id" />
<field name="contact_firstname" />
<field name="contact_name" />
</group>
</field>
<field name="partner_id" position="replace">
<field name='partner_id' select='1'/>
<!-- <field name="location_id" domain="[('partner_id', '=', partner_id)]"/> -->
<field name='type' select='2' invisible="1"/>
<field name="function" />
</field>