Browse Source

Use a m2o for the models

pull/1381/head
Guewen Baconnier 10 years ago
committed by Artem Kostyuk
parent
commit
d4c053030e
  1. 2
      record_archiver/models/company.py
  2. 23
      record_archiver/models/record_lifespan.py
  3. 8
      record_archiver/models/res_config.py
  4. 4
      record_archiver/views/res_config.xml

2
record_archiver/models/company.py

@ -23,7 +23,7 @@ class Company(orm.Model):
_inherit = 'res.company'
_columns = {
'lifespan_ids': fields.one2many(
'record_lifespan_ids': fields.one2many(
'record.lifespan',
'company_id',
string="Record Lifespans"),

23
record_archiver/models/record_lifespan.py

@ -39,9 +39,18 @@ class RecordLifespan(orm.Model):
_order = 'model'
_columns = {
'model': fields.char(
"Model",
required=True),
'model_id': fields.many2one(
'ir.model',
string='Model',
required=True,
),
'model': fields.related(
'model_id', 'model',
string='Model Name',
type='char',
readonly=True,
store=True,
),
'months': fields.integer(
"Months",
required=True,
@ -55,7 +64,7 @@ class RecordLifespan(orm.Model):
}
_sql_constraints = [
('model_uniq', 'unique(model, company_id)',
('model_uniq', 'unique(model_id, company_id)',
"A model can only have 1 lifespan per company"),
('months_gt_0', 'check (months > 0)',
"Months must be a value greater than 0"),
@ -81,7 +90,7 @@ class RecordLifespan(orm.Model):
model = self.pool[lifespan.model]
domain = [('write_date', '<', expiration_date),
('company_id', '=', lifespan.company_id.id)]
if 'state' in model._columns.keys():
if 'state' in model._columns:
domain += [('state', 'in', ('done', 'cancel'))]
return domain
@ -95,12 +104,12 @@ class RecordLifespan(orm.Model):
"""
today = datetime.today()
model = self.pool[lifespan.model]
model = self.pool.get(lifespan.model)
if not model:
raise orm.except_orm(
_('Error'),
_('Model %s not found') % lifespan.model)
if 'active' not in model._columns.keys():
if 'active' not in model._columns:
raise orm.except_orm(
_('Error'),
_('Model %s has no active field') % lifespan.model)

8
record_archiver/models/res_config.py

@ -29,8 +29,8 @@ class RecordArchiverConfigSettings(orm.TransientModel):
_columns = {
'company_id': fields.many2one('res.company', 'Company', required=True),
'lifespan_ids': fields.related(
'company_id', 'lifespan_ids',
'record_lifespan_ids': fields.related(
'company_id', 'record_lifespan_ids',
string='Record Lifespans',
type='one2many',
relation='record.lifespan'),
@ -63,8 +63,8 @@ class RecordArchiverConfigSettings(orm.TransientModel):
return {'value': {}}
company = self.pool.get('res.company'
).browse(cr, uid, company_id, context=context)
lifespan_ids = [l.id for l in company.lifespan_ids]
lifespan_ids = [l.id for l in company.record_lifespan_ids]
values = {
'lifespan_ids': lifespan_ids,
'record_lifespan_ids': lifespan_ids,
}
return {'value': values}

4
record_archiver/views/res_config.xml

@ -31,9 +31,9 @@
<group>
<div>
<div>
<field name="lifespan_ids" class="oe_inline">
<field name="record_lifespan_ids" class="oe_inline">
<tree editable="bottom">
<field name="model"/>
<field name="model_id"/>
<field name="months"/>
</tree>
</field>

Loading…
Cancel
Save