[IMP] res_partner : name field is now optional for addresses.

The name_get has been updated accordingly : if an address has no name, we now show parent_name, res_partner.type.
The contact template shows the name when it exists, and the parent_name if it does not. This should produce cleaner reports.

Though the name field is no longer required on the res.partner model,
"required" attribute in views and an sql contraint enforce that all contacts have a name.
This commit is contained in:
Tanguy Charlier
2015-09-25 14:06:29 +02:00
parent 0ead074211
commit fe4c9bb3a9
4 changed files with 19 additions and 8 deletions
+6 -1
View File
@@ -6,7 +6,12 @@
--<span class="text-muted" t-esc="name"/>--
</div>
<div t-if="'name' in fields">
<span itemprop="name" t-esc="name"/>
<t t-if="object.name">
<span itemprop="name" t-esc="name"/>
</t>
<t t-if="not object.name and object.parent_name">
<span itemprop="name" t-esc="object.parent_name"/>
</t>
<t t-if="options.get('country_image') and 'country_id' in fields and object.country_id and object.country_id.image">
<span t-field="object.country_id.image" t-field-options='{"widget": "image", "class": "country_flag"}'/>
</t>
+8 -2
View File
@@ -207,7 +207,7 @@ class res_partner(osv.Model, format_address):
_order = "display_name"
_columns = {
'name': fields.char('Name', required=True, select=True),
'name': fields.char('Name', select=True),
'display_name': fields.function(_display_name, type='char', string='Name', store=_display_name_store_triggers, select=True),
'date': fields.date('Date', select=1),
'title': fields.many2one('res.partner.title', 'Title'),
@@ -342,6 +342,10 @@ class res_partner(osv.Model, format_address):
(osv.osv._check_recursion, 'You cannot create recursive Partner hierarchies.', ['parent_id']),
]
_sql_constraints = [
('check_name', "CHECK( (type='contact' AND name IS NOT NULL) or (type!='contact') )", 'Contacts require a name.'),
]
@api.one
def copy(self, default=None):
default = dict(default or {})
@@ -578,8 +582,10 @@ class res_partner(osv.Model, format_address):
ids = [ids]
res = []
for record in self.browse(cr, uid, ids, context=context):
name = record.name
name = record.name or ''
if record.parent_id and not record.is_company:
if not name and record.type in ['invoice', 'delivery', 'other']:
name = dict(self.fields_get(cr, uid, context=context)['type']['selection'])[record.type]
name = "%s, %s" % (record.parent_name, name)
if context.get('show_address_only'):
name = self._display_address(cr, uid, record, without_company=True, context=context)
+3 -3
View File
@@ -78,7 +78,7 @@
<div class="oe_title">
<field name="company_type" options="{'horizontal': true}" class="oe_edit_only" widget="radio"/>
<h1>
<field name="name" default_focus="1" placeholder="Name" />
<field name="name" default_focus="1" placeholder="Name" attrs="{'required' : [('type', '=', 'contact')]}"/>
</h1>
<field name="parent_id"
placeholder="Company"
@@ -157,7 +157,7 @@
on_change="on_change_company_type(company_type)"
options="{'horizontal': true}"/>
<h1>
<field name="name" default_focus="1" placeholder="Name" required="1"/>
<field name="name" default_focus="1" placeholder="Name" attrs="{'required' : [('type', '=', 'contact')]}"/>
</h1>
<div class="o_row">
<field name="parent_id"
@@ -285,7 +285,7 @@
</div>
</group>
<group>
<field name="name" string="Contact Name"/>
<field name="name" string="Contact Name" attrs="{'required' : [('type', '=', 'contact')]}"/>
<field name="title" placeholder="e.g. Mr."
attrs="{'invisible': [('type','&lt;&gt;', 'contact')]}"/>
<field name="function" placeholder="e.g. Sales Director"
+2 -2
View File
@@ -137,7 +137,7 @@
<field name="image" widget='image' class="oe_avatar" options='{"preview_image": "image_medium"}'/>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<h1><field name="name" required="1"/></h1>
<field name="email" invisible="1"/>
<label for="login" class="oe_edit_only" string="Email Address"/>
<h2>
@@ -179,7 +179,7 @@
<field name="image" widget='image' class="oe_avatar" options='{"preview_image": "image_medium"}'/>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<h1><field name="name" required="1"/></h1>
<field name="email" invisible="1"/>
<label for="login" class="oe_edit_only" string="Email Address"/>
<h2><field name="login" on_change="on_change_login(login)"/></h2>