Browse Source

[REM] partner_firstname

pull/128/head
Elouan Le Bars 5 years ago
committed by Rémy Taymans
parent
commit
4c2d119103
  1. 1
      partner_firstname/__init__.py
  2. 25
      partner_firstname/__manifest__.py
  3. 1
      partner_firstname/models/__init__.py
  4. 36
      partner_firstname/models/partner.py
  5. 17
      partner_firstname/views/res_partner.xml

1
partner_firstname/__init__.py

@ -1 +0,0 @@
from . import models

25
partner_firstname/__manifest__.py

@ -1,25 +0,0 @@
{
'name': "Beescoop Base Module",
'summary': """
Module that simply add a firstname on the module res.partner
replace the community module from the same name for the beescoop
""",
'description': """
""",
'author': "Beescoop - Cellule IT",
'website': "https://github.com/beescoop/Obeesdoo",
'category': 'Contact',
'version': '1.0',
'depends': ['base'],
'data': [
'views/res_partner.xml',
],
'installable': True
}

1
partner_firstname/models/__init__.py

@ -1 +0,0 @@
from . import partner

36
partner_firstname/models/partner.py

@ -1,36 +0,0 @@
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
def concat_names(*args):
"""
Concatenate only args that are not empty
@param args: a list of string
"""
return ' '.join(filter(bool, args))
class Partner(models.Model):
_inherit = 'res.partner'
firstname = fields.Char('First Name')
lastname = fields.Char('Last Name', required=True, default="/")
name = fields.Char(compute='_get_name', inverse='_set_name', store=True, string="Full Name")
@api.depends('firstname', 'lastname')
def _get_name(self):
for rec in self:
rec.name = concat_names(rec.firstname, rec.lastname)
def _set_name(self):
"""
This allow to handle the case of code that write directly on the name at creation
Should never happen but in case it happen write on the lastname
If there is no firstname lastname and name are the same
"""
for rec in self:
if not rec.firstname:
rec.lastname = rec.name
#Compatibility with old name use in beedoo
last_name = fields.Char(related='lastname', string="Last Name (Legacy)")
first_name = fields.Char(related='firstname', string="Frist Name (Legacy)")

17
partner_firstname/views/res_partner.xml

@ -1,17 +0,0 @@
<odoo>
<record model="ir.ui.view" id="beesdoo_partner_name_form_view">
<field name="name">beesdoo.partner.form.view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="name" position="replace">
<field name="name" class="oe_read_only" />
<field name="firstname" placeholder="First Name"
class="oe_edit_only"
attrs="{'invisible' : [('company_type', '=', 'company')]}" />
<field name="lastname" placeholder="Last Name"
class="oe_edit_only" default_focus="1" />
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save