Browse Source
Remove the company on record.lifespan
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
7 changed files with 52 additions and 171 deletions
-
2record_archiver/__openerp__.py
-
2record_archiver/models/__init__.py
-
30record_archiver/models/company.py
-
9record_archiver/models/record_lifespan.py
-
70record_archiver/models/res_config.py
-
50record_archiver/views/record_lifespan_view.xml
-
60record_archiver/views/res_config.xml
@ -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 |
@ -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"), |
|
||||
} |
|
@ -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} |
|
@ -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> |
@ -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> |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue