其他分享
首页 > 其他分享> > odoo12-路由获取附件信息

odoo12-路由获取附件信息

作者:互联网

class DdFzyq(http.Controller):

    @http.route('/sale_quoted', type='http', auth='none', methods=['POST', 'GET'], csrf=False, cors="*")
    def FzyqSaleQuoted(self, **kwargs):
        sale_quoted_id = kwargs.get('id', False)  # 报价单id
        data = {}
        result = []
        sale_quoted_obj = request.env['dd.sale.quoted']
        search_obj = sale_quoted_obj.search([('id', '=', int(sale_quoted_id))])
        result.append({
            'partner_name': search_obj.partner_id.name,
            'partner_user': search_obj.partner_id.child_ids.name,
            'partner_street': search_obj.partner_id._display_address(without_company=True),
            'partner_tel': search_obj.partner_id.phone,
            'partner_email': search_obj.partner_id.email,
        })
        line_ids = search_obj.info_line_ids
        if line_ids:
            result_list = []
            for index, line in enumerate(line_ids):
                product_images = line.product_images
                image_url = []
                if product_images:
                    image_ids = product_images.mapped('id')
                    for image_id in image_ids:
                        image_url.append(request.httprequest.host_url + 'web/image/' + str(image_id) + '/45x45')
                else:
                    image_url.append(request.httprequest.host_url + 'web/image?model=product.product&id=' + str(line.product_id.id) + '&field=image_medium')
                    ir_attachment_obj = request.env['ir.attachment']
                    image_fj_ids = ir_attachment_obj.sudo().search([('res_id', '=', line.product_id.product_tmpl_id.id), ('res_field', '=', None), ('index_content', '=', 'image')]).ids
                    for image_id in image_fj_ids:
                        image_url.append(request.httprequest.host_url + 'web/image/' + str(image_id) + '/45x45')
                result_list.append({
                    'index': index + 1,
                    'name': line.product_id.name,
                    'qty': line.product_qty,
                    'tax_id': line.tax_id.amount,
                    'image_url': image_url,
                    'amount_total': line.amount_total,
                    'remark': line.remark,
                    'description': line.product_id.description,
                })
        else:
            data['code'] = 400
            data['result'] = '该报价单无明细行产品,请添加明细行产品'
            return json.dumps(data, ensure_ascii=False, ).encode('utf-8')
        data['code'] = 200
        data['result'] = result
        data['line'] = result_list
        return json.dumps(data, ensure_ascii=False, ).encode('utf-8')

标签:product,obj,image,odoo12,ids,附件,line,id,路由
来源: https://blog.csdn.net/boy_rookie/article/details/120696093