[FIX] base_contact: Assign a partner only if there is a location on the address for...
authorStephane Wirtel <stw@openerp.com>
Wed, 14 Dec 2011 12:40:41 +0000 (13:40 +0100)
committerStephane Wirtel <stw@openerp.com>
Wed, 14 Dec 2011 12:40:41 +0000 (13:40 +0100)
[IMP] base_contact: Add a view for the location

bzr revid: stw@openerp.com-20111214124041-jsnqzmu83zjbrjzf

addons/base_contact/base_contact.py
addons/base_contact/base_contact_view.xml

index 891e143..35168db 100644 (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
 
index 554a058..137fead 100644 (file)
 
     <!-- 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>
                 <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>