Remove maintenance related fields

This commit is contained in:
Sergi Almacellas Abellana 2014-11-20 18:14:39 +01:00
parent 86205884f6
commit 108176b7b9
6 changed files with 7 additions and 125 deletions

View File

@ -1,2 +1,4 @@
* Remove maintenance related fields
Version 3.4.0 - 2014-11-13
* Initial release

View File

@ -7,5 +7,4 @@ from .work import *
def register():
Pool.register(
Project,
Maintenance,
module='asset_work_project', type_='model')

View File

@ -5,11 +5,3 @@ msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:work.project,asset:"
msgid "Asset"
msgstr "Actiu"
msgctxt "field:work.project,asset_maintenances:"
msgid "Maintenances"
msgstr "Manteniments"
msgctxt "field:work.project,category:"
msgid "Category"
msgstr "Categoría"

View File

@ -5,11 +5,3 @@ msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:work.project,asset:"
msgid "Asset"
msgstr "Activo"
msgctxt "field:work.project,asset_maintenances:"
msgid "Maintenances"
msgstr "Mantenimentos"
msgctxt "field:work.project,category:"
msgid "Category"
msgstr "Categoría"

View File

@ -2,12 +2,9 @@
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/label[@name='maintenance']" position="before">
<xpath expr="/form/label[@name='start_date']" position="before">
<label name="asset"/>
<field name="asset"/>
</xpath>
<xpath expr="/form/field[@name='maintenance']" position="after">
<label name="category"/>
<field name="category"/>
<newline/>
</xpath>
</data>

106
work.py
View File

@ -1,10 +1,9 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import ModelSQL, fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Bool, Eval
from trytond.model import fields
from trytond.pool import PoolMeta
__all___ = ['Project', 'Maintenance']
__all___ = ['Project']
__metaclass__ = PoolMeta
@ -12,102 +11,3 @@ class Project:
__name__ = 'work.project'
asset = fields.Many2One('asset', 'Asset', required=True,
select=True)
asset_maintenances = fields.One2Many('asset.maintenance', 'reference',
'Maintenances', size=1)
category = fields.Function(fields.Many2One('asset.maintenance.category',
'Category',
states={
'required': Bool(Eval('maintenance')),
'invisible': ~Bool(Eval('maintenance')),
},
depends=['maintenance']),
'get_maintenance', setter='set_maintenance',
searcher='search_maintenance')
date_planned = fields.Function(fields.Date('Planned Date',
states={
'invisible': ~Bool(Eval('maintenance')),
},
depends=['maintenance']),
'get_maintenance', setter='set_maintenance',
searcher='search_maintenance')
date_start = fields.Function(fields.Date('Start Date',
states={
'invisible': ~Bool(Eval('maintenance')),
},
depends=['maintenance']),
'get_maintenance', setter='set_maintenance',
searcher='search_maintenance')
date_done = fields.Function(fields.Date('Done Date',
states={
'invisible': ~Bool(Eval('maintenance')),
},
depends=['maintenance']),
'get_maintenance', setter='set_maintenance',
searcher='search_maintenance')
date_next = fields.Function(fields.Date('Next maintenance',
states={
'invisible': ~Bool(Eval('maintenance')),
},
depends=['maintenance']),
'get_maintenance', setter='set_maintenance',
searcher='search_maintenance')
@classmethod
def get_maintenance(cls, projects, names):
pool = Pool()
Maintenance = pool.get('asset.maintenance')
res = {}
for name in names:
res[name] = dict((m.id, None) for m in projects)
for maintenance in Maintenance.search([
('reference', 'in', [str(m) for m in projects]),
]):
project = maintenance.reference.id
for name in names:
value = getattr(maintenance, name)
if isinstance(value, ModelSQL):
value = value.id
res[name][project] = value
return res
@classmethod
def set_maintenance(cls, projects, name, value):
pool = Pool()
Maintenance = pool.get('asset.maintenance')
to_write = []
to_create = []
for project in projects:
if not project.maintenance:
continue
if not project.asset_maintenances:
to_create.append(project.asset_maintenance_vals(
{name: value}))
else:
to_write.extend(project.asset_maintenances)
if to_create:
Maintenance.create(to_create)
if to_write:
Maintenance.write(to_write, {
name: value,
})
@classmethod
def search_maintenance(cls, name, clause):
return [('asset_maintenances.%s' % name,) + tuple(clause[1:])]
def asset_maintenance_vals(self, vals):
'Returns the values for the work maintenance to be created for self'
vals['reference'] = str(self)
vals['asset'] = self.asset.id
return vals
class Maintenance:
__name__ = 'asset.maintenance'
@classmethod
def _get_reference(cls):
references = super(Maintenance, cls)._get_reference()
references.append('work.project')
return references