Browse Source

More changes as pwer requests.

pull/197/head
Richard deMeester 9 years ago
parent
commit
72258b857a
  1. 2
      partner_contact_in_several_companies/models/__init__.py
  2. 23
      partner_contact_in_several_companies/models/ir_actions.py
  3. 36
      partner_contact_in_several_companies/models/res_partner.py

2
partner_contact_in_several_companies/models/__init__.py

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import multi_contact
from . import res_partner, ir_actions

23
partner_contact_in_several_companies/models/ir_actions.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api
class IRActionsWindow(models.Model):
_inherit = 'ir.actions.act_window'
@api.multi
def read(self, fields=None, context=None, load='_classic_read'):
actions = super(IRActionsWindow, self).read(fields=fields, load=load)
for action in actions:
if action.get('res_model', '') == 'res.partner':
# By default, only show standalone contact
action_context = action.get('context', '{}') or '{}'
if 'search_show_all_positions' not in action_context:
action['context'] = action_context.replace(
'{',
("{'search_show_all_positions': "
"{'is_set': True, 'set_value': False},"),
1)
return actions

36
partner_contact_in_several_companies/models/multi_contact.py → partner_contact_in_several_companies/models/res_partner.py

@ -8,12 +8,13 @@ from openerp.osv import expression
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
contact_type = fields.Selection([('standalone', _('Standalone Contact')),
('attached',
_('Attached to existing Contact')),
contact_type = fields.Selection(
[('standalone', _('Standalone Contact')),
('attached', _('Attached to existing Contact')),
], ],
compute='_get_contact_type', compute='_get_contact_type',
required=True, select=1, store=True)
required=True, select=1, store=True,
default='standalone')
contact_id = fields.Many2one('res.partner', string='Main Contact', contact_id = fields.Many2one('res.partner', string='Main Contact',
domain=[('is_company', '=', False), domain=[('is_company', '=', False),
('contact_type', '=', 'standalone'), ('contact_type', '=', 'standalone'),
@ -27,10 +28,6 @@ class ResPartner(models.Model):
def _get_contact_type(self): def _get_contact_type(self):
self.contact_type = self.contact_id and 'attached' or 'standalone' self.contact_type = self.contact_id and 'attached' or 'standalone'
_defaults = {
'contact_type': 'standalone',
}
def _basecontact_check_context(self, mode): def _basecontact_check_context(self, mode):
""" Remove 'search_show_all_positions' for non-search mode. """ Remove 'search_show_all_positions' for non-search mode.
Keeping it in context can result in unexpected behaviour (ex: reading Keeping it in context can result in unexpected behaviour (ex: reading
@ -70,6 +67,10 @@ class ResPartner(models.Model):
@api.model @api.model
def create(self, vals): def create(self, vals):
""" When creating, use a modified self to alter the context (see
comment in _basecontact_check_context). Also, we need to ensure
that the name on an attached contact is the same as the name on the
contact it is attached to."""
modified_self = self._basecontact_check_context('create') modified_self = self._basecontact_check_context('create')
if not vals.get('name') and vals.get('contact_id'): if not vals.get('name') and vals.get('contact_id'):
vals['name'] = modified_self.browse(vals['contact_id']).name vals['name'] = modified_self.browse(vals['contact_id']).name
@ -158,22 +159,3 @@ class ResPartner(models.Model):
def _onchange_contact_type(self): def _onchange_contact_type(self):
if self.contact_type == 'standalone': if self.contact_type == 'standalone':
self.contact_id = False self.contact_id = False
class IRActionsWindow(models.Model):
_inherit = 'ir.actions.act_window'
@api.multi
def read(self, fields=None, context=None, load='_classic_read'):
actions = super(IRActionsWindow, self).read(fields=fields, load=load)
for action in actions:
if action.get('res_model', '') == 'res.partner':
# By default, only show standalone contact
action_context = action.get('context', '{}') or '{}'
if 'search_show_all_positions' not in action_context:
action['context'] = action_context.replace(
'{',
("{'search_show_all_positions': "
"{'is_set': True, 'set_value': False},"),
1)
return actions
Loading…
Cancel
Save