summaryrefslogtreecommitdiff
path: root/addons/document_ftp/wizard
diff options
context:
space:
mode:
authorHarry (OpenERP) <hmo@tinyerp.com>2010-06-12 08:02:36 +0530
committerHarry (OpenERP) <hmo@tinyerp.com>2010-06-12 08:02:36 +0530
commita9c60d6bdc4c729e159d9613077967a0c19448a2 (patch)
treea406ef0b215d5438acd5826b2dbff89baa6f906e /addons/document_ftp/wizard
parent4e978de7bd1828e9481f9419a4842f755b2bc2c5 (diff)
[IMP] document_ftp
* Browse FTP Wizard * Auto Directory Configuration Wizard bzr revid: hmo@tinyerp.com-20100612023236-h54w0256v89irxgh
Diffstat (limited to 'addons/document_ftp/wizard')
-rw-r--r--addons/document_ftp/wizard/__init__.py24
-rw-r--r--addons/document_ftp/wizard/document_configuration.py121
-rw-r--r--addons/document_ftp/wizard/document_configuration_view.xml50
-rw-r--r--addons/document_ftp/wizard/ftp_browse.py53
-rw-r--r--addons/document_ftp/wizard/ftp_browse_view.xml40
5 files changed, 288 insertions, 0 deletions
diff --git a/addons/document_ftp/wizard/__init__.py b/addons/document_ftp/wizard/__init__.py
new file mode 100644
index 00000000000..22971249113
--- /dev/null
+++ b/addons/document_ftp/wizard/__init__.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# 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 ftp_browse
+import document_configuration
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document_ftp/wizard/document_configuration.py b/addons/document_ftp/wizard/document_configuration.py
new file mode 100644
index 00000000000..e7966c2e3a4
--- /dev/null
+++ b/addons/document_ftp/wizard/document_configuration.py
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# 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 osv import osv, fields
+from document_ftp import ftpserver
+class document_configuration(osv.osv_memory):
+
+ _name='document.configuration'
+ _description = 'Auto Directory Configuration'
+ _inherit = 'res.config'
+
+ _columns = {
+ 'sale_order' : fields.boolean('Sale Order', help="Auto directory configuration for Sale Orders and Quotation with report."),
+ 'product' : fields.boolean('Product', help="Auto directory configuration for Products."),
+ 'project': fields.boolean('Project', help="Auto directory configuration for Projects."),
+ }
+
+
+ def execute(self, cr, uid, ids, context=None):
+ conf_id = ids and ids[0] or False
+ conf = self.browse(cr, uid, conf_id, context)
+ dir_pool = self.pool.get('document.directory')
+ data_pool = self.pool.get('ir.model.data')
+ model_pool = self.pool.get('ir.model')
+ content_pool = self.pool.get('document.directory.content')
+ if conf.sale_order and self.pool.get('sale.order'):
+ # Sale order
+ dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_all')
+ if dir_data_id:
+ sale_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
+ else:
+ sale_dir_id = data_pool.create(cr, uid, {'name': 'Sale Orders'})
+ mid = model_pool.search(cr, uid, [('model','=','sale.order')])
+ dir_pool.write(cr, uid, [sale_dir_id], {
+ 'type':'ressource',
+ 'ressource_type_id': mid[0],
+ 'domain': '[]',
+ })
+ # Qutation
+ dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_quote')
+ if dir_data_id:
+ quta_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
+ else:
+ quta_dir_id = data_pool.create(cr, uid, {'name': 'Sale Quotations'})
+
+ dir_pool.write(cr, uid, [quta_dir_id], {
+ 'type':'ressource',
+ 'ressource_type_id': mid[0],
+ 'domain': "[('state','=','draft')]",
+ })
+ # Sale Order Report
+ order_report_data_id = data_pool._get_id(cr, uid, 'sale', 'report_sale_order')
+ if order_report_data_id:
+ order_report_id = data_pool.browse(cr, uid, order_report_data_id, context=context).res_id
+
+ content_pool.create(cr, uid, {
+ 'name': "Print Order",
+ 'suffix': "_print",
+ 'report_id': order_report_id,
+ 'extension': '.pdf',
+ 'include_name': 1,
+ 'directory_id': sale_dir_id,
+ })
+
+ content_pool.create(cr, uid, {
+ 'name': "Print Qutation",
+ 'suffix': "_print",
+ 'report_id': order_report_id,
+ 'extension': '.pdf',
+ 'include_name': 1,
+ 'directory_id': quta_dir_id,
+ })
+
+
+ if conf.product and self.pool.get('product.product'):
+ # Product
+ dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_product')
+ if dir_data_id:
+ product_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
+ else:
+ product_dir_id = data_pool.create(cr, uid, {'name': 'Products'})
+
+ mid = model_pool.search(cr, uid, [('model','=','product.product')])
+ dir_pool.write(cr, uid, [product_dir_id], {
+ 'type':'ressource',
+ 'ressource_type_id': mid[0],
+ })
+
+ if conf.project and self.pool.get('account.analytic.account'):
+ # Project
+ dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_project')
+ if dir_data_id:
+ project_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
+ else:
+ project_dir_id = data_pool.create(cr, uid, {'name': 'Projects'})
+
+ mid = model_pool.search(cr, uid, [('model','=','account.analytic.account')])
+ dir_pool.write(cr, uid, [project_dir_id], {
+ 'type':'ressource',
+ 'ressource_type_id': mid[0],
+ 'domain': '[]',
+ 'ressource_tree': 1
+ })
+document_configuration()
diff --git a/addons/document_ftp/wizard/document_configuration_view.xml b/addons/document_ftp/wizard/document_configuration_view.xml
new file mode 100644
index 00000000000..c6f40deb429
--- /dev/null
+++ b/addons/document_ftp/wizard/document_configuration_view.xml
@@ -0,0 +1,50 @@
+<openerp>
+ <data>
+ <record id="view_auto_config_form" model="ir.ui.view">
+ <field name="name">Auto Configure Directory</field>
+ <field name="model">document.configuration</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="base.res_config_view_base"/>
+ <field name="arch" type="xml">
+ <data>
+ <form position="attributes">
+ <attribute name="string">Auto Configure</attribute>
+ </form>
+ <separator string="title" position="attributes">
+ <attribute name="string">Resource Directory Configuration </attribute>
+ </separator>
+ <xpath expr="//label[@string='description']" position="attributes">
+ <attribute name="string">Choose the following Resouces to auto directory configuration.</attribute>
+ </xpath>
+ <xpath expr='//separator[@string="vsep"]' position='attributes'>
+ <attribute name='rowspan'>12</attribute>
+ <attribute name='string'></attribute>
+ </xpath>
+ <group string="res_config_contents" position="replace">
+ <group col="6" colspan="4">
+ <field name="sale_order"/>
+ <field name="product"/>
+ <field name="project"/>
+ </group>
+ </group>
+ <xpath expr="//button[@name='action_skip']" position="replace"/>
+ </data>
+ </field>
+ </record>
+
+ <record id="action_config_auto_directory" model="ir.actions.act_window">
+ <field name="name">Auto Configure Directory</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">document.configuration</field>
+ <field name="view_id" ref="view_auto_config_form"/>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+
+ <record model="ir.actions.todo" id="config_auto_directory">
+ <field name="action_id" ref="action_config_auto_directory"/>
+ <field name="groups_id" eval="[(6,0,[ref('base.group_extended')])]"/>
+ </record>
+ </data>
+</openerp>
diff --git a/addons/document_ftp/wizard/ftp_browse.py b/addons/document_ftp/wizard/ftp_browse.py
new file mode 100644
index 00000000000..06c9766997b
--- /dev/null
+++ b/addons/document_ftp/wizard/ftp_browse.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# 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 osv import osv, fields
+from tools.translate import _
+
+from document_ftp import ftpserver
+class document_ftp_browse(osv.osv_memory):
+ _name = 'document.ftp.browse'
+ _description = 'Document FTP Browse'
+
+ _columns = {
+ 'url' : fields.char('FTP Server', size=64, required=True),
+ }
+
+ def default_get(self, cr, uid, fields, context=None):
+ res = {}
+ if 'url' in fields:
+ user_pool = self.pool.get('res.users')
+ current_user = user_pool.browse(cr, uid, uid, context=context)
+ res['url'] = '%s@%s:%d'%(current_user.login, ftpserver.HOST, ftpserver.PORT)
+ return res
+
+ def browse_ftp(self, cr, uid, ids, context):
+ data_id = ids and ids[0] or False
+ data = self.browse(cr, uid, data_id, context)
+ ftp_url = 'ftp://'
+ final_url = ftp_url + data.url
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url':final_url,
+ 'target': 'new'
+ }
+document_ftp_browse()
+
diff --git a/addons/document_ftp/wizard/ftp_browse_view.xml b/addons/document_ftp/wizard/ftp_browse_view.xml
new file mode 100644
index 00000000000..a32f93e096f
--- /dev/null
+++ b/addons/document_ftp/wizard/ftp_browse_view.xml
@@ -0,0 +1,40 @@
+<openerp>
+ <data>
+
+ <record id="ftp_browse_form" model="ir.ui.view">
+ <field name="name">Document FTP Browse</field>
+ <field name="model">document.ftp.browse</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form string="Browse Document">
+ <separator string="Browse Document" colspan="4"/>
+ <field name="url" widget="url" colspan="4"/>
+ <separator colspan="4"/>
+ <group col="4" colspan="4">
+ <label string="" colspan="2"/>
+ <button special="cancel" string="Cancel" icon="gtk-cancel"/>
+ <button name="browse_ftp" string="Browse" type="object" icon="gtk-ok"/>
+ </group>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_ftp_browse" model="ir.actions.act_window">
+ <field name="name">Document Browse</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">document.ftp.browse</field>
+ <field name="view_id" ref="ftp_browse_form"/>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+
+ <menuitem
+ name="Shared Repository (FTP)"
+ action="action_ftp_browse"
+ id="menu_document_browse"
+ icon="STOCK_EXECUTE"
+ parent="document.menu_document_doc" sequence="1"/>
+
+</data>
+</openerp>