Dedicated tree for attachments, some view tweaks and renaming task

object
This commit is contained in:
Valentin Chemiere 2015-02-26 18:14:09 +01:00
parent afa5dc454a
commit 8d38f72cfb
7 changed files with 70 additions and 15 deletions

View File

@ -27,8 +27,9 @@ class IrAttachment(models.Model):
_inherit = 'ir.attachment'
sync_date = fields.Datetime()
parse_state = fields.Selection([
state = fields.Selection([
('pending', 'Pending'),
('failed', 'Failed'),
('done', 'Done'),
], readonly=True, required=True, default='pending')
state_message = fields.Text()

View File

@ -8,11 +8,50 @@
<field name="arch" type="xml">
<field name="url" position="after">
<field name="sync_date"/>
<field name="parse_state"/>
<field name="state"/>
<field name="state_message"/>
</field>
</field>
</record>
<record id="view_external_attachment_tree" model="ir.ui.view">
<field name="model">ir.attachment</field>
<field name="arch" type="xml">
<tree string="Attachments" >
<field name="name"/>
<field name="datas_fname"/>
<field name="res_model"/>
<field name="res_id"/>
<field name="type"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="create_uid"/>
<field name="create_date"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="action_attachment" model="ir.actions.act_window">
<field name="name">Attachments</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">ir.attachment</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="view_id" eval="False"/>
</record>
<record id="ir_attachment_view1" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_external_attachment_tree"/>
<field name="act_window_id" ref="action_attachment"/>
</record>
<menuitem id="menu_ir_attachment"
parent="menu_file_exchange"
sequence="20"
action="action_attachment"/>
</data>
</openerp>

View File

@ -34,6 +34,7 @@ class Location(models.Model):
port = fields.Integer()
login = fields.Char()
password = fields.Char()
task_ids = fields.One2many('external.file.task', 'location_id')
def _get_protocol(self):

View File

@ -14,7 +14,17 @@
<field name="address" colspan="2"/>
<field name="port" colspan="2"/>
<field name="login" colspan="4"/>
<field name="password" colspan="4"/>
<field name="password" password="1" colspan="4"/>
<separator string="Tasks" colspan="4"/>
<field name="task_ids" colspan="4" nolabel="1">
<tree>
<field name="name"/>
<field name="method"/>
<field name="filename"/>
<field name="filepath"/>
<button name="run" type="object" string="Run"/>
</tree>
</field>
</group>
</sheet>
</form>
@ -28,9 +38,7 @@
<field name="name" select="1"/>
<field name="protocol"/>
<field name="address"/>
<field name="port"/>
<field name="login"/>
<field name="password"/>
</tree>
</field>
</record>

View File

@ -26,7 +26,7 @@ from abstract_task import AbstractTask
class Task(models.Model):
_name = 'ir.location.task'
_name = 'external.file.task'
_description = 'Description'
name = fields.Char()

View File

@ -3,7 +3,7 @@
<data>
<record id="view_task_form" model="ir.ui.view">
<field name="model">ir.location.task</field>
<field name="model">external.file.task</field>
<field name="arch" type="xml">
<form string="Tasks" version="7.0">
<sheet>
@ -22,7 +22,7 @@
</record>
<record id="view_task_tree" model="ir.ui.view">
<field name="model">ir.location.task</field>
<field name="model">external.file.task</field>
<field name="arch" type="xml">
<tree string="Tasks" >
<field name="name" select="1"/>
@ -36,12 +36,12 @@
<record id="action_task" model="ir.actions.act_window">
<field name="name">Tasks</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">ir.location.task</field>
<field name="res_model">external.file.task</field>
<field name="view_type">form</field>
<field name="view_id" eval="False"/>
</record>
<menuitem id="menu_ir_location_task"
<menuitem id="menu_external_file_task"
parent="menu_file_exchange"
sequence="20"
action="action_task"/>

View File

@ -23,6 +23,7 @@ from ..abstract_task import AbstractTask
from base64 import b64decode
import ftputil
import ftputil.session
from ftputil.error import FTPIOError
import logging
_logger = logging.getLogger(__name__)
@ -132,16 +133,21 @@ class FtpExportTask(FtpTask):
raise Exception("%s already exists" % target_name)
def _handle_new_target(self, ftp_conn, target_name, filedata):
with ftp_conn.open(target_name, mode='wb') as fileobj:
fileobj.write(filedata)
_logger.info('wrote %s, size %d', target_name, len(filedata))
# return file_id
try:
with ftp_conn.open(target_name, mode='wb') as fileobj:
fileobj.write(filedata)
_logger.info('wrote %s, size %d', target_name, len(filedata))
self.attachment_id.state = 'done'
except FTPIOError:
self.attachment_id.state = 'failed'
self.attachment_id.state_message = (
'The directory doesn\'t exist or had insufficient rights')
def _target_name(self, ftp_conn, upload_directory, filename):
return upload_directory + '/' + filename
def _upload_file(self, host, port, user, pwd, path, filename, filedata):
upload_directory = path
upload_directory = path or './'
port_session_factory = ftputil.session.session_factory(port=port)
with ftputil.FTPHost(host, user, pwd,
session_factory=port_session_factory) as ftp_conn: