Browse Source

Merge pull request #200 from eLBati/fix_bug_154

FIX when partner_contact_birthdate and partner_relations are installa…
pull/209/head
Pedro M. Baeza 9 years ago
parent
commit
0ad410e1df
  1. 2
      partner_contact_birthdate/tests/__init__.py
  2. 27
      partner_contact_birthdate/tests/test_delete.py
  3. 5
      partner_firstname/__openerp__.py
  4. 9
      partner_firstname/tests/__init__.py
  5. 38
      partner_firstname/tests/test_delete.py
  6. 11
      partner_relations/__openerp__.py
  7. 39
      partner_relations/model/res_partner.py
  8. 2
      partner_relations/model/res_partner_relation_type_selection.py
  9. 1
      partner_relations/tests/test_partner_relations.py

2
partner_contact_birthdate/tests/__init__.py

@ -16,4 +16,4 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import test_birthdate
from . import test_birthdate, test_delete

27
partner_contact_birthdate/tests/test_delete.py

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# © 2015 Grupo ESOC
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class CompanyCase(TransactionCase):
model = "res.partner"
context = {"default_is_company": True}
def test_computing_after_unlink(self):
"""Test what happens if recomputed after unlinking.
This test might seem useless, but really this happens when module
``partner_relations`` is installed.
See https://github.com/OCA/partner-contact/issues/154.
"""
data = {"name": u"Söme name", "birthdate": "2015-09-28"}
record = self.env[self.model].with_context(**self.context).create(data)
record.unlink()
record.recompute()
class PersonCase(CompanyCase):
context = {"default_is_company": False}

5
partner_firstname/__openerp__.py

@ -21,12 +21,13 @@
{
'name': 'Partner first name and last name',
'summary': "Split first name and last name for non company partners",
'version': '8.0.2.0.1',
'version': '8.0.2.1.0',
'author': "Camptocamp, Grupo ESOC, Odoo Community Association (OCA)",
"license": "AGPL-3",
'maintainer': 'Camptocamp, Acsone',
'category': 'Extra Tools',
'website': 'http://www.camptocamp.com, http://www.acsone.eu',
'website':
'http://www.camptocamp.com, http://www.acsone.eu, http://grupoesoc.es',
'depends': ['base'],
'data': [
'views/res_partner.xml',

9
partner_firstname/tests/__init__.py

@ -29,4 +29,11 @@
#
##############################################################################
from . import test_create, test_defaults, test_empty, test_name, test_onchange
from . import (
test_create,
test_delete,
test_defaults,
test_empty,
test_name,
test_onchange
)

38
partner_firstname/tests/test_delete.py

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# © 2015 Grupo ESOC
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
from .base import MailInstalled
class CompanyCase(TransactionCase):
model = "res.partner"
context = {"default_is_company": True}
def test_computing_after_unlink(self):
"""Test what happens if recomputed after unlinking.
This test might seem useless, but really this happens when module
``partner_relations`` is installed.
See https://github.com/OCA/partner-contact/issues/154.
"""
data = {"name": u"Söme name"}
record = self.env[self.model].with_context(**self.context).create(data)
record.unlink()
record.recompute()
class PersonCase(CompanyCase):
context = {"default_is_company": False}
class UserCase(CompanyCase, MailInstalled):
model = "res.users"
context = {"default_login": "user@example.com"}
def test_computing_after_unlink(self):
# Cannot create users if ``mail`` is installed
if not self.mail_installed():
super(UserCase, self).test_computing_after_unlink()

11
partner_relations/__openerp__.py

@ -24,6 +24,7 @@
"author": "Therp BV,Camptocamp,Odoo Community Association (OCA)",
"complexity": "normal",
"category": "Customer Relationship Management",
"license": "AGPL-3",
"depends": [
'base',
],
@ -32,7 +33,6 @@
],
"test": [
"test/test_allow.yml",
# "test/test_disallow.yml",
],
"data": [
"view/res_partner_relation_all.xml",
@ -42,15 +42,6 @@
'view/menu.xml',
'security/ir.model.access.csv',
],
"js": [
],
"css": [
],
"qweb": [
],
"auto_install": False,
"installable": True,
"external_dependencies": {
'python': [],
},
}

39
partner_relations/model/res_partner.py

@ -78,7 +78,8 @@ class ResPartner(models.Model):
if context is None:
context = {}
relation_obj = self.pool.get('res.partner.relation')
context2 = self._update_context(context, ids)
context2 = self.with_partner_relations_context(
cr, uid, ids, context=context).env.context
for value in field_value:
if value[0] == 0:
relation_obj.create(cr, uid, value[2], context=context2)
@ -298,23 +299,23 @@ class ResPartner(models.Model):
cr, uid, args + date_args + active_args, offset=offset,
limit=limit, order=order, context=context, count=count)
def read(
self, cr, uid, ids, fields=None, context=None,
load='_classic_read'):
return super(ResPartner, self).read(
cr, uid, ids, fields=fields,
context=self._update_context(context, ids), load=load)
@api.multi
def read(self, fields=None, load='_classic_read'):
return super(ResPartner, self.with_partner_relations_context())\
.read(fields=fields, load=load)
def write(self, cr, uid, ids, vals, context=None):
return super(ResPartner, self).write(
cr, uid, ids, vals, context=self._update_context(context, ids))
@api.multi
def write(self, vals):
return super(ResPartner, self.with_partner_relations_context())\
.write(vals)
def _update_context(self, context, ids):
if context is None:
context = {}
ids = ids if isinstance(ids, list) else [ids] if ids else []
result = context.copy()
result.setdefault('active_id', ids[0] if ids else None)
result.setdefault('active_ids', ids)
result.setdefault('active_model', self._name)
return result
@api.multi
def with_partner_relations_context(self):
context = dict(self.env.context)
if context.get('active_model', self._name) == self._name:
existing = self.exists()
context.setdefault(
'active_id', existing.ids[0] if existing.ids else None)
context.setdefault('active_ids', existing.ids)
context.setdefault('active_model', self._name)
return self.with_context(context)

2
partner_relations/model/res_partner_relation_type_selection.py

@ -1,4 +1,4 @@
# -*- coding: UTF-8 -*-
# -*- coding: utf-8 -*-
'''
Created on 23 may 2014

1
partner_relations/tests/test_partner_relations.py

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Author: Charbel Jacquin
# Copyright 2015 Camptocamp SA
#

Loading…
Cancel
Save