创建一个动态向导,其中包含下载pdf文件的链接

时间:2016-02-19 11:07:42

标签: openerp

我正在尝试创建一个报告按钮:

  • 查看:account_payment.view_payment_order_form
  • 型号:payment.order

会计 - >付款 - >建议付款单 - > FORM

我的目标是获取每行'line_ids'并打开一个向导,其中填充了每行'line_ids'的下载链接。

目前我正在尝试创建一个没有运气的动态向导。我不知道是否可以这样做。

感谢您的回答。

1 个答案:

答案 0 :(得分:0)

向导模型:

class my_wizard(osv.TransientModel):
    _name = 'my_wizard'

    _columns = {
        'line_ids': fields.one2many('payment.order', 'Payment order'),
    }

呼叫向导(在“payment.order”模式中):

def call_wizard(self, cr, uid, ids, context):

        my_wizard_form_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment', 'my_wizard_form')[1]

        lines = []
        for line in self.browse(cr, uid, ids, context).line_ids:
            lines.append([0, 0, {'line_id': line.id}])

        #To create records dyamically   
        ctx={'default_line_ids': lines} 

        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'my_wizard',
            'views': [(my_wizard_form_id, 'form')],
            'view_id': my_wizard_form_id,
            'target': 'new',
            'context': ctx,
        }

向导视图:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="my_wizard_form" model="ir.ui.view">
            <field name="name">my_wizard.form</field>
            <field name="model">my_wizard</field>
            <field name="type">form</field>
            <field name="arch" type="xml" >
                <form>
                    <field name="line_ids" widget="one2many_list">
                                <tree editable="bottom">
                                    <field name="id"/>
                                    <!-- define "download" function in "payment.line"
                                    <button name='download' type='object' string='download' />
                                </tree>
                    </field>
                        <field name='' />
                    </group>
                </form>
            </field>
        </record>

        <record id="action_my_wizard_form" model="ir.actions.act_window">
            <field name="name"></field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">my_wizard</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="target">new</field>
        </record>
    </data>
</openerp>

按钮调用向导(payment_order视图):

<button name='call_wizard' type="object" string="WIZARD"  />

您应该在payment.line模型中创建download方法。

def download(self, cr, uid, ids, context):
     #To open an URL
     '''return {
        "type": "ir.actions.act_url",
        "url": "LINK TO PDF",
        "target": "self",
    }
    '''

    #To generate a report
    datas = {
        'ids': ids,
        'model': 'dossier',
        'form': self.read(cr, uid, ids[0], context=context)
    }

    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'my_report',
        'datas': datas,
        'nodestroy': True
    }

我希望这会有用。