栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

odoo12-路由获取附件信息

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

odoo12-路由获取附件信息

  • 获取到该产品对应的产品图片以及附件(图片格式的)数据(即在ir.attachment模型中对应的id 然后拼接成url)
  • (‘index_content’, ‘=’, ‘image’):表示附件类型仅为图片的
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')
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/317431.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号