Odoo 12. Как получить ссылку из двоичного поля - PullRequest
0 голосов
/ 22 апреля 2020

Как получить ссылку на имя файла? Я получаю текст: (

class UploadFile(models.TransientModel):
    _name = 'upload.file'

    product_attribute_value_id = fields.Many2one('product.at[![enter image description here][1]][1]tribute.value', string='Attribute Value',
                                             required=True, ondelete='cascade', index=True)
    product_id = fields.Many2one('product.template', string='Product', required=True)
    file = fields.Binary(string="Upload file")
    file_name = fields.Char("File Name")

    @api.multi
    @api.onchange('product_attribute_value_id', 'product_id')
    def onchange_data_product(self):
        if not self.product_attribute_value_id or not self.product_id:
            return

        r = open('D:\picture\pdff.pdf', "rb").read()
        # base64.b64encode(r).decode('utf-8')
        self.file = base64.b64encode(r)

<record id="upload_file_form" model="ir.ui.view">
    <field name="name">upload.file.wizard</field>
    <field name="model">upload.file</field>
    <field name="arch" type="xml">
        <form string="Upload attributes file">
            <group>
                <field name="product_id" string="Product"/>
                <field name="product_attribute_value_id"/>
                <field name="file" widget="binary" filename="file_name" string="Binary"/>
                <field name="file_name" invisible="1"/>
            </group>
            <footer>
                <button name="save_file" string="Save" type="object" class="btn-primary"/>
                <button string="Cancel" class="btn-secondary" special="cancel"/>
            </footer>
        </form>
    </field>
</record>

Это форма мастера. Когда пользователь меняет два поля product_attribute_value_id и product_id, я хочу увидеть ссылку на pdf.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...