跳至内容
菜单
此问题已终结
1 回复
5207 查看

I have two binary fields. In the sale order line tree view, I have a button to open my wizard. I chose and save file and it's perfectly saved in my label_file field of the selected sale order line.

The problem is that when I open the wizard I want to see it as a saved file, but it's not generated and only bytes are in the path.

first

Class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    label_file = fields.Binary('Saved Label')


second

class OrderLineLabel(models.TransientModel):
    _name = 'order.line.label'


label_file_show = fields.Binary('Label file')


@api.multi
def write_label_vals(self):
    self.ensure_one()
    sale_order_line = self.env['sale.order.line'].browse(self.env.context.get('active_ids'))
    vals = {

        'label_file': self.label_file,

    }
    sale_order_line.write(vals)


api.model
def default_get(self, fields):
    res = super(OrderLineLabel, self).default_get(fields)
    order_line_id = self.env['sale.order.line'].browse(self.env.context.get('active_ids'))

    status, headers, content = binary_content(model='sale.order.line', field='label_file', id=order_line_id.id,filename='test',download=True)
    #tried like this
    res['label_file_show'] = content

    #or just like this
    res['label_file_show'] = order_line_id.label_file

    return res
形象
丢弃
最佳答案

Hello Grf,


You can use the context attribute to pass the binary file into the wizard.


Try to use the context in in the action of your wizard.


Use the context like this :


sale_order_line_id = self.env['sale.order.line'].browse(self.env.context.get('active_id'))

  return {

            'name': _('Order Line Label'),

            'view_type': 'form',

            'view_mode': 'tree,form',

            'res_model': 'order.line.label',

            'view_id': view_order_line_label,

            'type': 'ir.actions.act_window',

            'context': {

                'default_label_file_show': sale_order_line_id.label_file

            }

        }

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

形象
丢弃
相关帖文 回复 查看 活动
2
12月 23
25338
1
3月 15
3402
0
3月 15
3902
2
1月 24
12699
1
3月 15
4133