Browse Source

Convert models to v8 api

pull/103/head
Sandy Carter 10 years ago
parent
commit
c50c83cd87
  1. 125
      partner_relations/model/res_partner_relation.py
  2. 89
      partner_relations/model/res_partner_relation_all.py
  3. 47
      partner_relations/model/res_partner_relation_type.py

125
partner_relations/model/res_partner_relation.py

@ -41,6 +41,47 @@ class ResPartnerRelation(models.Model):
_description = 'Partner relation'
_order = 'active desc, date_start desc, date_end desc'
def _get_computed_fields(
self, cr, uid, ids, field_names, arg, context=None):
'''Return a dictionary of dictionaries, with for every partner for
ids, the computed values.'''
def get_values(self, dummy_field_names, dummy_arg, context=None):
'''Get computed values for record'''
values = {}
on_right_partner = self._on_right_partner(self.right_partner_id.id)
# type_selection_id
values['type_selection_id'] = (
((self.type_id.id) * 10) + (on_right_partner and 1 or 0))
# partner_id_display
values['partner_id_display'] = (
self.left_partner_id.id
if on_right_partner
else self.right_partner_id.id
)
return values
return dict([
(i.id, get_values(i, field_names, arg, context=context))
for i in self.browse(cr, uid, ids, context=context)
])
_columns = {
'type_selection_id': osv.fields.function(
_get_computed_fields,
multi="computed_fields",
fnct_inv=lambda *args: None,
type='many2one', obj='res.partner.relation.type.selection',
string='Type',
),
'partner_id_display': osv.fields.function(
_get_computed_fields,
multi="computed_fields",
fnct_inv=lambda *args: None,
type='many2one', obj='res.partner',
string='Partner'
),
}
left_contact_type = fields.Selection(
lambda s: s.env['res.partner.relation.type']._get_partner_types(),
'Left Partner Type',
@ -61,6 +102,33 @@ class ResPartnerRelation(models.Model):
compute='_get_partner_type_any',
)
left_partner_id = fields.Many2one(
'res.partner',
string='Source Partner',
required=True,
auto_join=True,
ondelete='cascade',
)
right_partner_id = fields.Many2one(
'res.partner',
string='Destination Partner',
required=True,
auto_join=True,
ondelete='cascade',
)
type_id = fields.Many2one(
'res.partner.relation.type',
string='Type',
required=True,
auto_join=True,
)
date_start = fields.Date('Starting date')
date_end = fields.Date('Ending date')
active = fields.Boolean('Active', default=True)
@api.one
@api.depends('left_partner_id', 'right_partner_id')
def _get_partner_type_any(self):
@ -112,30 +180,6 @@ class ResPartnerRelation(models.Model):
del vals['contact_type']
return vals
def _get_computed_fields(
self, cr, uid, ids, field_names, arg, context=None):
'''Return a dictionary of dictionaries, with for every partner for
ids, the computed values.'''
def get_values(self, dummy_field_names, dummy_arg, context=None):
'''Get computed values for record'''
values = {}
on_right_partner = self._on_right_partner(self.right_partner_id.id)
# type_selection_id
values['type_selection_id'] = (
((self.type_id.id) * 10) + (on_right_partner and 1 or 0))
# partner_id_display
values['partner_id_display'] = (
self.left_partner_id.id
if on_right_partner
else self.right_partner_id.id
)
return values
return dict([
(i.id, get_values(i, field_names, arg, context=context))
for i in self.browse(cr, uid, ids, context=context)
])
@api.multi
def write(self, vals):
"""Override write to correct values, before being stored."""
@ -188,39 +232,6 @@ class ResPartnerRelation(models.Model):
result['domain']['partner_id_display'] = partner_domain
return result
_columns = {
'left_partner_id': osv.fields.many2one(
'res.partner', string='Left partner', required=True,
auto_join=True, ondelete='cascade'),
'right_partner_id': osv.fields.many2one(
'res.partner', string='Right partner', required=True,
auto_join=True, ondelete='cascade'),
'type_id': osv.fields.many2one(
'res.partner.relation.type', string='Type', required=True,
auto_join=True),
'date_start': osv.fields.date('Starting date'),
'date_end': osv.fields.date('Ending date'),
'type_selection_id': osv.fields.function(
_get_computed_fields,
multi="computed_fields",
fnct_inv=lambda *args: None,
type='many2one', obj='res.partner.relation.type.selection',
string='Type',
),
'partner_id_display': osv.fields.function(
_get_computed_fields,
multi="computed_fields",
fnct_inv=lambda *args: None,
type='many2one', obj='res.partner',
string='Partner'
),
'active': osv.fields.boolean('Active'),
}
_defaults = {
'active': True,
}
@api.one
@api.constrains('date_start', 'date_end')
def _check_dates(self):

89
partner_relations/model/res_partner_relation_all.py

@ -19,7 +19,7 @@
#
##############################################################################
from openerp import osv, models, fields, api
from openerp import models, fields, api
from openerp.tools import drop_view_if_exists
from .res_partner_relation_type_selection import \
ResPartnerRelationTypeSelection
@ -44,11 +44,55 @@ class ResPartnerRelationAll(models.AbstractModel):
return super(ResPartnerRelationAll, self)._auto_init(
cr, context=context)
_columns = {
'my_field': ....
}
my_field = fields...
'''
this_partner_id = fields.Many2one(
'res.partner',
string='Current Partner',
required=True,
)
other_partner_id = fields.Many2one(
'res.partner',
string='Other Partner',
required=True,
)
type_id = fields.Many2one(
'res.partner.relation.type',
string='Relation Type',
required=True,
)
type_selection_id = fields.Many2one(
'res.partner.relation.type.selection',
string='Relation Type',
required=True,
)
relation_id = fields.Many2one(
'res.partner.relation',
'Relation',
readonly=True,
)
record_type = fields.Selection(
ResPartnerRelationTypeSelection._RECORD_TYPES,
'Record Type',
readonly=True,
)
contact_type = fields.Selection(
lambda s: s.env['res.partner.relation.type']._get_partner_types(),
'Partner Type',
default=lambda self: self._get_default_contact_type()
)
date_start = fields.Date('Starting date')
date_end = fields.Date('Ending date')
active = fields.Boolean('Active', default=True)
def _auto_init(self, cr, context=None):
drop_view_if_exists(cr, self._table)
additional_view_fields = ','.join(self._additional_view_fields)
@ -99,32 +143,6 @@ class ResPartnerRelationAll(models.AbstractModel):
"""Get the record on which this record is overlaid"""
return self.env[self._overlays].browse(self.id / PADDING)
contact_type = fields.Selection(
lambda s: s.env['res.partner.relation.type']._get_partner_types(),
'Partner Type',
default=lambda self: self._get_default_contact_type()
)
_columns = {
'record_type': osv.fields.selection(
ResPartnerRelationTypeSelection._RECORD_TYPES, 'Record type',
readonly=True),
'relation_id': osv.fields.many2one(
'res.partner.relation', 'Relation', readonly=True),
'type_id': osv.fields.many2one(
'res.partner.relation.type', 'Relation type', readonly=True),
'type_selection_id': osv.fields.many2one(
'res.partner.relation.type.selection', 'Relation type',
),
'this_partner_id': osv.fields.many2one(
'res.partner', 'Current partner', readonly=True),
'other_partner_id': osv.fields.many2one(
'res.partner', 'Other partner'),
'date_start': osv.fields.date('Starting date'),
'date_end': osv.fields.date('Ending date'),
}
active = fields.Boolean('Active', default=True)
def _get_default_contact_type(self):
partner_id = self._context.get('default_this_partner_id')
if partner_id:
@ -132,14 +150,15 @@ class ResPartnerRelationAll(models.AbstractModel):
return get_partner_type(partner)
return False
def name_get(self, cr, uid, ids, context=None):
return dict([
(this.id, '%s %s %s' % (
@api.multi
def name_get(self):
return {
this.id: '%s %s %s' % (
this.this_partner_id.name,
this.type_selection_id.name_get()[0][1],
this.other_partner_id.name,
))
for this in self.browse(cr, uid, ids, context=context)])
)
for this in self.browse(cr, uid, ids, context=context)}
@api.one
def write(self, vals):

47
partner_relations/model/res_partner_relation_type.py

@ -20,8 +20,7 @@
#
##############################################################################
from openerp.osv import fields
from openerp import models, api, _
from openerp import models, fields, api, _
class ResPartnerRelationType(models.Model):
@ -30,24 +29,38 @@ class ResPartnerRelationType(models.Model):
_description = 'Partner Relation Type'
_order = 'name'
name = fields.Char(
'Name',
size=128,
required=True,
translate=True,
)
name_inverse = fields.Char(
'Inverse name',
size=128,
required=True,
translate=True,
)
contact_type_left = fields.Selection(
'_get_partner_types',
'Left partner type',
)
contact_type_right = fields.Selection(
'_get_partner_types',
'Right partner type',
)
partner_category_left = fields.Many2one(
'res.partner.category',
'Left partner category',
)
partner_category_right = fields.Many2one(
'res.partner.category',
'Right partner category',
)
@api.model
def _get_partner_types(self):
return [
('c', _('Company')),
('p', _('Person')),
]
_columns = {
'name': fields.char(
'Name', size=128, required=True, translate=True),
'name_inverse': fields.char(
'Inverse name', size=128, required=True, translate=True),
'contact_type_left': fields.selection(
_get_partner_types, 'Left partner type'),
'contact_type_right': fields.selection(
_get_partner_types, 'Right partner type'),
'partner_category_left': fields.many2one(
'res.partner.category', 'Left partner category'),
'partner_category_right': fields.many2one(
'res.partner.category', 'Right partner category'),
}
Loading…
Cancel
Save