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/53/head
Thibault Francois 7 years ago
parent
commit
51e1c1e346
  1. 1
      beesdoo_base/__init__.py
  2. 2
      beesdoo_base/__openerp__.py
  3. 18
      beesdoo_base/models/partner.py
  4. 8
      beesdoo_base/report/beescard.xml
  5. 8
      beesdoo_base/tools/__init__.py
  6. 8
      beesdoo_base/views/partner.xml
  7. 2
      beesdoo_pos/models/beesdoo_pos.py
  8. 2
      partner_firstname/__init__.py
  9. 24
      partner_firstname/__openerp__.py
  10. 1
      partner_firstname/models/__init__.py
  11. 53
      partner_firstname/models/partner.py
  12. 17
      partner_firstname/views/res_partner.xml

1
beesdoo_base/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import models import models
import wizard import wizard
import tools
import controllers import controllers

2
beesdoo_base/__openerp__.py

@ -15,7 +15,7 @@
'category': 'Project Management', 'category': 'Project Management',
'version': '0.1', 'version': '0.1',
'depends': ['point_of_sale', 'purchase', 'report', 'portal'],
'depends': ['point_of_sale', 'purchase', 'report', 'portal', 'partner_firstname'],
'data': [ 'data': [
'security/groups.xml', 'security/groups.xml',

18
beesdoo_base/models/partner.py

@ -7,8 +7,6 @@ class Partner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
first_name = fields.Char('First Name')
last_name = fields.Char('Last Name')
eater = fields.Selection([('eater', 'Eater'), ('worker_eater', 'Worker and Eater')], string="Eater/Worker") eater = fields.Selection([('eater', 'Eater'), ('worker_eater', 'Worker and Eater')], string="Eater/Worker")
child_eater_ids = fields.One2many("res.partner", "parent_eater_id", domain=[('customer', '=', True), child_eater_ids = fields.One2many("res.partner", "parent_eater_id", domain=[('customer', '=', True),
('eater', '=', 'eater')]) ('eater', '=', 'eater')])
@ -23,10 +21,6 @@ class Partner(models.Model):
cooperator_type = fields.Selection([('share_a', 'Share A'), ('share_b', 'Share B'), ('share_c', 'Share C')], store=True, compute=None) cooperator_type = fields.Selection([('share_a', 'Share A'), ('share_b', 'Share B'), ('share_c', 'Share C')], store=True, compute=None)
@api.onchange('first_name', 'last_name')
def _on_change_name(self):
self.name = concat_names(self.first_name, self.last_name)
@api.one @api.one
@api.depends('parent_eater_id', 'parent_eater_id.barcode', 'eater', 'member_card_ids') @api.depends('parent_eater_id', 'parent_eater_id.barcode', 'eater', 'member_card_ids')
def _get_bar_code(self): def _get_bar_code(self):
@ -83,18 +77,12 @@ class Partner(models.Model):
card_data['barcode'] = barcode card_data['barcode'] = barcode
self.env['member.card'].create(card_data) self.env['member.card'].create(card_data)
@api.noguess
def _auto_init(self, cr, context=None):
res = super(Partner, self)._auto_init(cr, context=context)
cr.execute("UPDATE res_partner set last_name = name where last_name IS NULL")
return res
@api.multi @api.multi
def _new_eater(self, surname, name, email): def _new_eater(self, surname, name, email):
partner_data = { partner_data = {
'name' : surname + " "+ name,
'last_name' : name,
'first_name' : surname,
'lastname' : name,
'firstname' : surname,
'is_customer' : True, 'is_customer' : True,
'eater' : 'eater', 'eater' : 'eater',
'parent_eater_id' : self.id, 'parent_eater_id' : self.id,

8
beesdoo_base/report/beescard.xml

@ -59,17 +59,17 @@
<td <td
style="vertical-align:top;width:7.72cm;height: 6.87cm;position: relative;"> style="vertical-align:top;width:7.72cm;height: 6.87cm;position: relative;">
<p style="text-align: left;padding-top: 0.2cm;font-size: 1.2em;"> <p style="text-align: left;padding-top: 0.2cm;font-size: 1.2em;">
<span t-raw="partner.first_name and partner.first_name[:30] or ''" style="font-family:Roboto-Regular" />
<span t-raw="partner.firstname and partner.firstname[:30] or ''" style="font-family:Roboto-Regular" />
<br /> <br />
<span t-raw="partner.last_name and partner.last_name[:26] or ''" style="font-family:Roboto-Bold;" />
<span t-raw="partner.lastname and partner.lastname[:26] or ''" style="font-family:Roboto-Bold;" />
<br /> <br />
</p> </p>
<p style="text-align: left;padding-top: 0.2cm;font-size: 1em;"> <p style="text-align: left;padding-top: 0.2cm;font-size: 1em;">
<t t-if="partner.parent_eater_id and partner.eater == 'eater'"> <t t-if="partner.parent_eater_id and partner.eater == 'eater'">
<!--fix here --> <!--fix here -->
<span t-raw="partner.parent_eater_id.first_name and partner.parent_eater_id.first_name[:30] or ''" style="font-family:Roboto-Regular;" />
<span t-raw="partner.parent_eater_id.last_name and partner.parent_eater_id.last_name[:26] or ''" style="font-family:Roboto-Regular;" />
<span t-raw="partner.parent_eater_id.firstname and partner.parent_eater_id.firstname[:30] or ''" style="font-family:Roboto-Regular;" />
<span t-raw="partner.parent_eater_id.lastname and partner.parent_eater_id.lastname[:26] or ''" style="font-family:Roboto-Regular;" />
</t> </t>
<t t-if="partner.parent_eater_id and partner.parent_eater_id.cooperator_type == 'share_b'"> <t t-if="partner.parent_eater_id and partner.parent_eater_id.cooperator_type == 'share_b'">

8
beesdoo_base/tools/__init__.py

@ -1,8 +0,0 @@
# -*- coding: utf-8 -*-
def concat_names(*args):
"""
Concatenate only args that are not empty
@param args: a list of string
"""
return ' '.join(filter(bool, args))

8
beesdoo_base/views/partner.xml

@ -19,14 +19,6 @@
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="point_of_sale.view_partner_property_form" /> <field name="inherit_id" ref="point_of_sale.view_partner_property_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="name" position="replace">
<field name="name" class="oe_read_only" />
<field name="first_name" placeholder="First Name"
class="oe_edit_only"
attrs="{'invisible' : [('company_type', '=', 'company')]}" />
<field name="last_name" placeholder="Last Name"
class="oe_edit_only" default_focus="1" />
</field>
<field name="type" position="before"> <field name="type" position="before">
<field name="cooperator_type" /> <field name="cooperator_type" />
</field> </field>

2
beesdoo_pos/models/beesdoo_pos.py

@ -75,5 +75,3 @@ class BeescoopPosPartner(models.Model):
def get_eater(self): def get_eater(self):
eater1, eater2, eater3 = self._get_eater() eater1, eater2, eater3 = self._get_eater()
return eater1, eater2, eater3 return eater1, eater2, eater3
last_name = fields.Char('Last Name', required=True, default="/")

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