Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Add primary phone number to form view #28

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions odoo/addons/base/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,13 @@ def default_get(self, default_fields):
partner_latitude = fields.Float(string='Geo Latitude', digits=(10, 7))
partner_longitude = fields.Float(string='Geo Longitude', digits=(10, 7))
email = fields.Char()
email_formatted = fields.Char(
'Formatted Email', compute='_compute_email_formatted',
email_formatted = fields.Char('Formatted Email', compute='_compute_email_formatted',
help='Format email address "Name <email@domain>"')
phone = fields.Char()
mobile = fields.Char()
primary_phone = fields.Selection(
string="Primary Phone", selection=[("phone", "Phone"), ("mobile", "Mobile")], required=True)
primary_phone_number = fields.Char(string='Primary Phone', compute='_compute_primary_phone_number', readonly=True)
is_company = fields.Boolean(string='Is a Company', default=False,
help="Check if the contact is a company, otherwise it is a person")
industry_id = fields.Many2one('res.partner.industry', 'Industry')
Expand Down Expand Up @@ -242,6 +244,20 @@ def default_get(self, default_fields):
('check_name', "CHECK( (type='contact' AND name IS NOT NULL) or (type!='contact') )", 'Contacts require a name'),
]

@api.depends('primary_phone', 'phone', 'mobile')
def _compute_primary_phone_number(self):
for partner_id in self:
if partner_id.primary_phone:
if partner_id.primary_phone == 'phone':
partner_id.primary_phone_number = "Primary Phone is %s" %partner_id.phone
elif partner_id.primary_phone == 'mobile':
partner_id.primary_phone_number = "Primary Phone is %s" %partner_id.mobile
else:
partner_id.primary_phone_number = ""

if partner_id.primary_phone_number == "Primary Phone is False":
partner_id.primary_phone_number = ""

@api.depends('name', 'user_ids.share', 'image_1920', 'is_company', 'type')
def _compute_avatar_1920(self):
super()._compute_avatar_1920()
Expand Down
4 changes: 2 additions & 2 deletions odoo/addons/base/views/ir_actions_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ env['res.partner'].create({'name': partner_name})
<field name="name">Config Wizard Steps</field>
<field name="arch" type="xml">
<form string="Config Wizard Steps">
<header>
<header>
<button name="action_launch"
states="open" string="Launch"
type="object" icon="fa-cogs" class="oe_highlight"
type="object" icon="fa-cogs" class="oe_highlight"
help="Launch Configuration Wizard"/>
<button name="action_open" states="done"
string="Set as Todo" type="object"
Expand Down
16 changes: 9 additions & 7 deletions odoo/addons/base/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,18 @@
<group>
<field name="function" placeholder="e.g. Sales Director"
attrs="{'invisible': [('is_company','=', True)]}"/>
<field name="phone" widget="phone"/>
<field name="mobile" widget="phone"/>
<field name="phone" widget="phone" attrs="{'required': [('primary_phone','=', 'phone'),('primary_phone_number','=','')]}"/>
<field name="mobile" widget="phone" attrs="{'required': [('primary_phone','=', 'mobile'),('primary_phone_number','=','')]}"/>
<field name="primary_phone" class="oe_edit_only"/>
<field name="primary_phone_number" class="oe_inline" attrs="{'invisible': [('primary_phone_number','=','')]}"
style="color: green"/>
<field name="user_ids" invisible="1"/>
<field name="email" widget="email" context="{'gravatar_image': True}" attrs="{'required': [('user_ids','!=', [])]}"/>
<field name="email" widget="email" context="{'gravatar_image': True}" attrs="{'required': [('user_ids','!=',[])]}"/>
<field name="website" string="Website" widget="url" placeholder="e.g. https://www.odoo.com"/>
<field name="title" options='{"no_open": True}' placeholder="e.g. Mister"
attrs="{'invisible': [('is_company', '=', True)]}"/>
<field name="title" options='{"no_open": True}' placeholder="e.g. Mister" attrs="{'invisible': [('is_company', '=', True)]}"/>
<field name="active_lang_count" invisible="1"/>
<label for="lang" attrs="{'invisible': [('active_lang_count', '&lt;=', 1)]}"/>
<div class="o_row" attrs="{'invisible': [('active_lang_count', '&lt;=', 1)]}">
<label for="lang" attrs="{'invisible': [('active_lang_count','&lt;=',1)]}"/>
<div class="o_row" attrs="{'invisible': [('active_lang_count','&lt;=',1)]}">
<field name="lang"/>
<button
type="action"
Expand Down