Browse Source

[ADD] Split firstname feature in a new module and change the name of the field to fit the community module with the same name. This module will shadow partner_firstname and thus remove the cheesy feature

pull/105/head
Thibault Francois 6 years ago
committed by Elouan
parent
commit
b09dc21028
  1. 2
      partner_firstname/__init__.py
  2. 24
      partner_firstname/__openerp__.py
  3. 1
      partner_firstname/models/__init__.py
  4. 53
      partner_firstname/models/partner.py
  5. 17
      partner_firstname/views/res_partner.xml

2
partner_firstname/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import models

24
partner_firstname/__openerp__.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
{
'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',
],
}

1
partner_firstname/models/__init__.py

@ -0,0 +1 @@
import partner

53
partner_firstname/models/partner.py

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api, _
from openerp.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)
@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
def _compatibility_layer(self, vals):
if 'last_name' in vals:
if not 'lastname' in vals:
vals['lastname'] = vals['last_name']
vals.pop('last_name')
if 'first_name' in vals:
if not 'firstname' in vals:
vals['firstname'] = vals['first_name']
vals.pop('first_name')
return vals
@api.multi
def write(self, vals):
return super(Partner, self).write(self._compatibility_layer(vals))
@api.model
def create(self, vals):
return super(Partner, self).create(self._compatibility_layer(vals))

17
partner_firstname/views/res_partner.xml

@ -0,0 +1,17 @@
<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="point_of_sale.view_partner_property_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