Browse Source

Remove the company on record.lifespan

The company was mandatory and prevented to use the module for models without
company_id.  Also, there is currently no use case for a different configuration
for different companies.  It simplifies the setup too.

If a use case exists for a different setup per company, it can be reintroduced
later with a optional company_id.
pull/409/head
Guewen Baconnier 10 years ago
parent
commit
c834aea434
  1. 2
      record_archiver/__openerp__.py
  2. 2
      record_archiver/models/__init__.py
  3. 30
      record_archiver/models/company.py
  4. 9
      record_archiver/models/record_lifespan.py
  5. 70
      record_archiver/models/res_config.py
  6. 50
      record_archiver/views/record_lifespan_view.xml
  7. 60
      record_archiver/views/res_config.xml

2
record_archiver/__openerp__.py

@ -37,7 +37,7 @@ Lifespan is defined per record per company.
'complexity': "easy", # easy, normal, expert 'complexity': "easy", # easy, normal, expert
'depends': ['base'], 'depends': ['base'],
'website': 'www.camptocamp.com', 'website': 'www.camptocamp.com',
'data': ['views/res_config.xml',
'data': ['views/record_lifespan_view.xml',
'data/cron.xml'], 'data/cron.xml'],
'test': [], 'test': [],
'installable': True, 'installable': True,

2
record_archiver/models/__init__.py

@ -1,4 +1,2 @@
from . import company
from . import ir_model from . import ir_model
from . import res_config
from . import record_lifespan from . import record_lifespan

30
record_archiver/models/company.py

@ -1,30 +0,0 @@
# -*- coding: utf-8 -*-
#
# Author: Yannick Vaucher
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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 openerp.osv import orm, fields
class Company(orm.Model):
_inherit = 'res.company'
_columns = {
'record_lifespan_ids': fields.one2many(
'record.lifespan',
'company_id',
string="Record Lifespans"),
}

9
record_archiver/models/record_lifespan.py

@ -57,16 +57,9 @@ class RecordLifespan(orm.Model):
required=True, required=True,
help="Number of month after which the records will be set to " help="Number of month after which the records will be set to "
"inactive based on their write date"), "inactive based on their write date"),
'company_id': fields.many2one(
'res.company',
string="Company",
ondelete="cascade",
required=True),
} }
_sql_constraints = [ _sql_constraints = [
('model_uniq', 'unique(model_id, company_id)',
"A model can only have 1 lifespan per company"),
('months_gt_0', 'check (months > 0)', ('months_gt_0', 'check (months > 0)',
"Months must be a value greater than 0"), "Months must be a value greater than 0"),
] ]
@ -90,7 +83,7 @@ class RecordLifespan(orm.Model):
""" """
model = self.pool[lifespan.model] model = self.pool[lifespan.model]
domain = [('write_date', '<', expiration_date), domain = [('write_date', '<', expiration_date),
('company_id', '=', lifespan.company_id.id)]
]
if 'state' in model._columns: if 'state' in model._columns:
domain += [('state', 'in', ('done', 'cancel'))] domain += [('state', 'in', ('done', 'cancel'))]
return domain return domain

70
record_archiver/models/res_config.py

@ -1,70 +0,0 @@
# -*- coding: utf-8 -*-
#
# Author: Yannick Vaucher
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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/>.
#
import logging
from openerp.osv import orm, fields
_logger = logging.getLogger(__name__)
class RecordArchiverConfigSettings(orm.TransientModel):
_name = 'record.archiver.config.settings'
_inherit = 'res.config.settings'
_columns = {
'company_id': fields.many2one('res.company', 'Company', required=True),
'record_lifespan_ids': fields.related(
'company_id', 'record_lifespan_ids',
string='Record Lifespans',
type='one2many',
relation='record.lifespan'),
}
def _default_company(self, cr, uid, context=None):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
return user.company_id.id
_defaults = {
'company_id': _default_company,
}
def create(self, cr, uid, values, context=None):
_super = super(RecordArchiverConfigSettings, self)
rec_id = _super.create(cr, uid, values, context=context)
# Hack: to avoid some nasty bug, related fields are not written upon
# record creation.
# Hence we write on those fields here.
vals = {}
for fname, field in self._columns.iteritems():
if isinstance(field, fields.related) and fname in values:
vals[fname] = values[fname]
self.write(cr, uid, [rec_id], vals, context=context)
return id
def onchange_company_id(self, cr, uid, ids, company_id, context=None):
# update related fields
if not company_id:
return {'value': {}}
company = self.pool.get('res.company'
).browse(cr, uid, company_id, context=context)
lifespan_ids = [l.id for l in company.record_lifespan_ids]
values = {
'record_lifespan_ids': lifespan_ids,
}
return {'value': values}

50
record_archiver/views/record_lifespan_view.xml

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_record_lifespan_tree" model="ir.ui.view">
<field name="name">record.lifespan.tree</field>
<field name="model">record.lifespan</field>
<field name="arch" type="xml">
<tree string="Records Archiver Lifespans" editable="bottom">
<field name="model_id"/>
<field name="months"/>
</tree>
</field>
</record>
<record id="view_record_lifespan_search" model="ir.ui.view">
<field name="name">record.lifespan.search</field>
<field name="model">record.lifespan</field>
<field name="arch" type="xml">
<search string="Records Archiver Lifespans">
<field name="model_id"/>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_record_lifespan_view">
<field name="name">Records Archiver Lifespans</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">record.lifespan</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
<field name="search_view_id" ref="view_record_lifespan_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to define a new lifespan for a type of records.
</p><p>
Every record of model with a lifespan will be set to inactive
after the the defined months are elapsed. The lifespan is
based on the last write on a record.
</p>
</field>
</record>
<menuitem id="menu_record_lifespan_config"
parent="base.menu_config"
sequence="20"
action="action_record_lifespan_view"/>
</data>
</openerp>

60
record_archiver/views/res_config.xml

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_record_archiver_config_settings" model="ir.ui.view">
<field name="name">record archiver settings</field>
<field name="model">record.archiver.config.settings</field>
<field name="arch" type="xml">
<form string="Configure Records Archiver" version="7.0" class="oe_form_configuration">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
or
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<group groups="base.group_multi_company">
<div>
<div>
<label for="company_id" string="Select Company"/>
<field name="company_id"
widget="selection"
on_change="onchange_company_id(company_id, context)"
class="oe_inline"/>
</div>
</div>
</group>
<separator string="Record lifespan"/>
All following type of record will be harvested by the cron
based on write_date. If a record has made his time, it will be
deactivated.
<group>
<div>
<div>
<field name="record_lifespan_ids" class="oe_inline">
<tree editable="bottom">
<field name="model_id"/>
<field name="months"/>
</tree>
</field>
</div>
</div>
</group>
</form>
</field>
</record>
<record id="action_record_archiver_config" model="ir.actions.act_window">
<field name="name">Configure Records Archiver</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">record.archiver.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
<menuitem id="menu_record_archiver__config" name="Records Archiver"
parent="base.menu_config"
sequence="70" action="action_record_archiver_config"/>
</data>
</openerp>
Loading…
Cancel
Save