From 7cda3b45ae96f5b1938cff5cd21794aad07173fe Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Wed, 27 Jan 2010 07:57:08 +0100 Subject: [PATCH] [IMP] improvement document change bzr revid: fp@tinyerp.com-20100127065708-kshxwqe92hjfok70 --- addons/document/document.py | 7 +- addons/document/document_view.xml | 23 ++- addons/document_change/document_change.py | 143 +++++++++++------- .../document_change/document_change_view.xml | 88 ++++++++--- .../document_change_workflow.xml | 77 ---------- .../document_phase_workflow.xml | 10 +- 6 files changed, 188 insertions(+), 160 deletions(-) diff --git a/addons/document/document.py b/addons/document/document.py index e11b2bea9c1..c8308265e4d 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -129,12 +129,15 @@ class document_file(osv.osv): if len(res): return False return True + def copy(self, cr, uid, id, default=None, context=None): if not default: default ={} - name = self.read(cr, uid, [id])[0]['name'] - default.update({'name': name+ " (copy)"}) + if 'name' not in default: + name = self.read(cr, uid, [id])[0]['name'] + default.update({'name': name+ " (copy)"}) return super(document_file,self).copy(cr,uid,id,default,context) + def write(self, cr, uid, ids, vals, context=None): res=self.search(cr,uid,[('id','in',ids)]) if not len(res): diff --git a/addons/document/document_view.xml b/addons/document/document_view.xml index ac14f372729..ab156cf1feb 100644 --- a/addons/document/document_view.xml +++ b/addons/document/document_view.xml @@ -128,13 +128,27 @@ + Directories ir.actions.act_window document.directory form tree,form + + + + tree + + + + + + form + + + + @@ -145,7 +159,7 @@ Directorie's Structure document.directory tree - + [('ressource_parent_type_id','=',False),('parent_id','=',False)] + + diff --git a/addons/document_change/document_change.py b/addons/document_change/document_change.py index c4b7c1152fa..7d6c614482c 100644 --- a/addons/document_change/document_change.py +++ b/addons/document_change/document_change.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # ############################################################################## + import tools from osv import fields, osv import os @@ -26,6 +27,7 @@ import netsvc from tools.translate import _ import time import datetime +import base64 class document_directory(osv.osv): _inherit = 'document.directory' @@ -54,7 +56,8 @@ class document_change_type(osv.osv): _columns = { 'name': fields.char("Document Type", size=64,required=True), 'phase_type_ids': fields.many2many('document.change.process.phase.type','document_type_phase_type_rel','document_type_id','phase_type_id','Phase Type'), - 'directory_id' :fields.many2one('document.directory','Pending Directory'), + 'directory_id' :fields.many2one('document.directory','Historic Directory'), + 'filename' :fields.char('Filename', size=128), 'template_document_id':fields.many2one('ir.attachment','Template Document') } document_change_type() @@ -88,14 +91,15 @@ class document_change_process_phase(osv.osv): 'type': fields.selection([('control_required', 'Control Required'),('no_control', 'No Control')], 'Type'), 'date_control': fields.date('Control Date', select=True), 'phase_type_id':fields.many2one('document.change.process.phase.type','Phase Type'), + 'directory_id': fields.related('process_id', 'structure_id', relation='document.directory', type="many2one", string='Directory'), 'state': fields.selection([('draft', 'Draft'),('in_process', 'Started'),('to_validate', 'To Validate'),('done', 'Done')], 'State',readonly=True), - 'phase_document_ids':fields.one2many('ir.attachment','process_phase_id','Documents'), + 'phase_document_ids':fields.many2many('ir.attachment','document_change_phase_document', 'phase_id','document_id', 'Documents'), } _defaults = { - 'state': lambda *a: 'draft', - 'update_document': lambda *a:'at_endPhase', - 'type':lambda *a: 'no_control', - } + 'state': lambda *a: 'draft', + 'update_document': lambda *a:'at_endPhase', + 'type':lambda *a: 'control_required', + } def do_draft(self, cr, uid, ids, *args): self.write(cr, uid, ids, {'state':'draft'}) return True @@ -106,6 +110,12 @@ class document_change_process_phase(osv.osv): def do_start(self, cr, uid, ids, *args): self.write(cr, uid, ids, {'state':'in_process'}) + todo = [] + for phase in self.browse(cr, uid, ids): + for doc in phase.phase_document_ids: + if doc.state in ('draft','in_production'): + todo.append(doc.id) + self.pool.get('ir.attachment').button_request(cr, uid, todo) return True def do_done(self, cr, uid, ids, *args): @@ -242,24 +252,47 @@ class document_change_process(osv.osv): document_obj = self.pool.get('ir.attachment') new_doc_ids = [] for process in self.browse(cr, uid, ids): - if process.process_model_id: - directory_ids = directory_obj.search(cr, uid, [('parent_id','child_of',process.structure_id and process.structure_id.id)]) - for phase_type_id in process.process_model_id.phase_type_ids: - for document_type_id in phase_type_id.document_type_ids: - document_ids = document_obj.search(cr, uid, [ - ('parent_id','in',directory_ids), - ('change_type_id','=',document_type_id.id)]) - new_doc_ids = [] - for document_id in document_ids: - vals = {} - new_doc_ids.append(document_obj.copy(cr, uid, document_id, vals)) - phase_value = { - 'name' : '%s-%s' %(phase_type_id.name, process.name), - 'phase_type_id': phase_type_id.id, - 'process_id': process.id, - 'phase_document_ids': [(6,0,new_doc_ids)] - } - phase_obj.create(cr, uid, phase_value) + if not process.process_model_id: + raise osv.except_osv(_('Error !'), _('You must select a process model !')) + directory_ids = directory_obj.search(cr, uid, [('parent_id','child_of',process.structure_id and process.structure_id.id)]) + for phase_type_id in process.process_model_id.phase_type_ids: + new_doc_ids = [] + for document_type_id in phase_type_id.document_type_ids: + print 'Creating', phase_type_id.name, document_type_id.name + document_ids = document_obj.search(cr, uid, [ + ('parent_id','in',directory_ids), + ('change_type_id','=',document_type_id.id) + ]) + for document_id in document_ids: + print 'Found Some...' + vals = {} + new_doc_ids.append(document_obj.copy(cr, uid, document_id, vals)) + if not document_ids: + if document_type_id.template_document_id: + print 'Copy' + new_doc_ids.append(document_obj.copy(cr, uid, document_type_id.template_document_id.id, { + 'name': document_type_id.template_document_id.name, + 'datas_fname': document_type_id.template_document_id.datas_fname, + 'parent_id': process.structure_id.id, + 'change_type_id': document_type_id.id + })) + else: + print 'Create' + new_doc_ids.append(document_obj.create(cr, uid, { + 'name': document_type_id.filename, + 'datas_fname': document_type_id.filename, + 'parent_id': process.structure_id.id, + 'change_type_id': document_type_id.id + })) + + phase_value = { + 'name' : '%s-%s' %(phase_type_id.name, process.name), + 'sequence': phase_type_id.sequence, + 'phase_type_id': phase_type_id.id, + 'process_id': process.id, + 'phase_document_ids': [(6,0,new_doc_ids)] + } + phase_obj.create(cr, uid, phase_value) return True @@ -271,10 +304,9 @@ class document_file(osv.osv): 'change_type_id':fields.many2one('document.change.type','Document Type'), 'state': fields.selection([('draft','To Create'),('in_production', 'In Production'), ('change_request', 'Change Requested'),('change_propose', 'Change Proposed'), ('to_update', 'To Update'), ('cancel', 'Cancel')], 'State'), 'style': fields.selection([('run','Run'),('setup','Setup'),('pma','PMA'),('pmp','PMP')],'Document Style'), - 'target_document_id': fields.many2one('ir.attachment', 'Target Document'), - 'target':fields.binary('Target'), - 'process_phase_id' :fields.many2one('document.change.process.phase','Process Phase'), - 'progress': fields.float('Progress'), #TODO : functio field: calculate progress + 'target':fields.binary('New Document'), + 'process_phase_id':fields.many2many('document.change.process.phase','document_change_phase_document', 'document_id','phase_id', 'Phases'), + 'progress': fields.float('Progress'), 'change_process_id': fields.related('process_phase_id', 'process_id', type='many2one', relation='document.change.process', string='Change Process'), } _defaults = { @@ -306,51 +338,56 @@ class document_file(osv.osv): return False return True - def do_change_request(self, cr, uid, ids, context={}): + def button_request(self, cr, uid, ids, context={}): self.write(cr, uid, ids, {'state':'change_request'},context=context) return True - def do_change_propose(self, cr, uid, ids, context={}): + def button_propose(self, cr, uid, ids, context={}): + for attach in self.browse(cr, uid, ids, context=context): + if not attach.target: + raise osv.except_osv(_('Error !'), _('You must provide a target content')) self.write(cr, uid, ids, {'state':'change_propose'},context=context) return True - def do_to_update(self, cr, uid, ids, context={}): + def button_validate(self, cr, uid, ids, context={}): for attach in self.browse(cr, uid, ids, context=context): - if attach.change_type_id.directory_id.id: - attach_ids = self.pool.get('ir.attachment').search(cr,uid, [('id', '=',attach.target_document_id.id)]) - read_data=self.read(cr,uid, attach_ids,['datas','datas_fname']) - self.write(cr, uid, attach_ids, {'state':'to_update','datas':attach.datas,'datas_fname':attach.datas_fname},context=context) - res={} - for data in read_data: - t=datetime.datetime.now() - file_name=data['datas_fname'].split('.') - new_name=str(file_name[0]+'.old'+time.strftime("%y%m%d")+'.'+file_name[1]) - res['name']=attach.name - res['datas']=data['datas'] - res['datas_fname']=new_name - res['parent_id']=attach.change_type_id.directory_id.id - old_id = self.create(cr, uid, res) - self.write(cr, uid, ids, {'state':'to_update'},context=context) + if not attach.target: + raise osv.except_osv(_('Error !'), _('You must provide a target content')) + if (not attach.change_type_id) or not (attach.change_type_id.directory_id.id): + raise osv.except_osv(_('Configuration Error !'), _('No history directory associated to the document type.')) + self.copy(cr, uid, [attach.id], { + 'target': False, + 'parent_id': attach.change_type_id.directory_id.id, + 'name': time.strftime('%Y%m%d-%H%M-')+attach.name, + 'datas_fname': time.strftime('%Y%m%d-%H%M-')+attach.datas_fname, + 'state': 'in_production' + }, + context=context) + self.write(cr, uid, [attach.id], { + 'target': False, + 'datas': base64.encodestring(attach.target), + 'state': 'in_production' + }) return True def do_production(self, cr, uid, ids, context={}): return self.write(cr, uid, ids, {'state':'in_production'},context=context) def write(self, cr, uid, ids, data, context={}): + result = super(document_file,self).write(cr,uid,ids,data,context=context) for d in self.browse(cr, uid, ids, context=context): if d.state=='draft' and d.datas: super(document_file,self).write(cr,uid,[d.id], {'state':'in_production'},context=context) - result = super(document_file,self).write(cr,uid,ids,data,context=context) + if (not d.datas) and (d.state=='in_production'): + super(document_file,self).write(cr,uid,[d.id], + {'state':'draft'},context=context) return True - def do_draft(self, cr, uid, ids, context={}): + def button_cancel(self, cr, uid, ids, context={}): return self.write(cr, uid, ids, {'state':'draft'},context=context) - def do_cancel(self, cr, uid, ids, context={}): - return self.write(cr, uid, ids, {'state':'cancel'},context=context) - - def test_change_request(self, cr, uid, ids, context=None): - return all(bool(attch.target_document_id) != False for attch in self.browse(cr, uid, ids, context=context)) + def button_draft(self, cr, uid, ids, context={}): + return self.write(cr, uid, ids, {'state':'draft'},context=context) document_file() diff --git a/addons/document_change/document_change_view.xml b/addons/document_change/document_change_view.xml index dfd60ba7565..430bc37c743 100644 --- a/addons/document_change/document_change_view.xml +++ b/addons/document_change/document_change_view.xml @@ -51,7 +51,7 @@ Directory Structure tree [('parent_id','=',False)] - + @@ -73,9 +73,9 @@
- + @@ -260,18 +260,17 @@ - + -