From 08d64e1e8b4d19b3452dacb5623f457f10d21ff5 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 1 Jul 2015 10:43:37 +0200 Subject: [PATCH] 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. --- record_archiver/__openerp__.py | 2 +- record_archiver/models/__init__.py | 2 - record_archiver/models/company.py | 30 -------- record_archiver/models/record_lifespan.py | 9 +-- record_archiver/models/res_config.py | 70 ------------------- .../views/record_lifespan_view.xml | 50 +++++++++++++ record_archiver/views/res_config.xml | 60 ---------------- 7 files changed, 52 insertions(+), 171 deletions(-) delete mode 100644 record_archiver/models/company.py delete mode 100644 record_archiver/models/res_config.py create mode 100644 record_archiver/views/record_lifespan_view.xml delete mode 100644 record_archiver/views/res_config.xml diff --git a/record_archiver/__openerp__.py b/record_archiver/__openerp__.py index 2ac5c486b..e24ae22f6 100644 --- a/record_archiver/__openerp__.py +++ b/record_archiver/__openerp__.py @@ -37,7 +37,7 @@ Lifespan is defined per record per company. 'complexity': "easy", # easy, normal, expert 'depends': ['base'], 'website': 'www.camptocamp.com', - 'data': ['views/res_config.xml', + 'data': ['views/record_lifespan_view.xml', 'data/cron.xml'], 'test': [], 'installable': True, diff --git a/record_archiver/models/__init__.py b/record_archiver/models/__init__.py index 8637ee398..a48e87b41 100644 --- a/record_archiver/models/__init__.py +++ b/record_archiver/models/__init__.py @@ -1,4 +1,2 @@ -from . import company from . import ir_model -from . import res_config from . import record_lifespan diff --git a/record_archiver/models/company.py b/record_archiver/models/company.py deleted file mode 100644 index cf6a9c361..000000000 --- a/record_archiver/models/company.py +++ /dev/null @@ -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 . -# -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"), - } diff --git a/record_archiver/models/record_lifespan.py b/record_archiver/models/record_lifespan.py index 66cd222c4..510742cd4 100644 --- a/record_archiver/models/record_lifespan.py +++ b/record_archiver/models/record_lifespan.py @@ -57,16 +57,9 @@ class RecordLifespan(orm.Model): required=True, help="Number of month after which the records will be set to " "inactive based on their write date"), - 'company_id': fields.many2one( - 'res.company', - string="Company", - ondelete="cascade", - required=True), } _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 must be a value greater than 0"), ] @@ -90,7 +83,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: domain += [('state', 'in', ('done', 'cancel'))] return domain diff --git a/record_archiver/models/res_config.py b/record_archiver/models/res_config.py deleted file mode 100644 index 3ca7f4b9c..000000000 --- a/record_archiver/models/res_config.py +++ /dev/null @@ -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 . -# -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} diff --git a/record_archiver/views/record_lifespan_view.xml b/record_archiver/views/record_lifespan_view.xml new file mode 100644 index 000000000..45d69a31c --- /dev/null +++ b/record_archiver/views/record_lifespan_view.xml @@ -0,0 +1,50 @@ + + + + + + record.lifespan.tree + record.lifespan + + + + + + + + + + record.lifespan.search + record.lifespan + + + + + + + + + Records Archiver Lifespans + ir.actions.act_window + record.lifespan + form + tree + + +

+ Click to define a new lifespan for a type of records. +

+ 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. +

+
+
+ + + +
+
diff --git a/record_archiver/views/res_config.xml b/record_archiver/views/res_config.xml deleted file mode 100644 index 83d85306d..000000000 --- a/record_archiver/views/res_config.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - record archiver settings - record.archiver.config.settings - -
-
-
- - -
-
-
-
-
- - 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. - -
-
- - - - - - -
-
-
- -
-
- - - Configure Records Archiver - ir.actions.act_window - record.archiver.config.settings - form - inline - - - - -
-