odoo

odoo12 产品的评论功能

2020-01-09  本文已影响0人  隔壁小红馆

在odoo12 公司的需求上,有一个是对产品的评论功能,由此记录一下。

图片.png
<t t-call="portal.message_thread">
  <t t-set="object" t-value="product"/>
  <t t-set="disable_composer" t-value="0/> #也可不写此行,默认是0,即可评论
</t>

这里的t-value="product" 中的product是一个必须的对象,根据需求即可更改。
因为根据需求,没有购买此产品的人不能评论此产品,所以还要根据是否购买来展示评论功能。
即:

<t t-call="portal.message_thread">
  <t t-set="object" t-value="product"/>
  <t t-set="disable_composer" t-value="1"/>
</t>

这里的t-set="disable_composer"中,0 是可以评论的,默认值0,1就是不能评论,即这里的 t-value="1",不能评论,只能查看历史评论


图片.png
<t t-set="attributes" t-value="product._get_product_order_sale(product)"/>
<t t-if="len(attributes)">
   <t t-call="portal.message_thread">
    <t t-set="object" t-value="product"/>
   </t>
</t>
<t t-else="">
  <t t-call="portal.message_thread">
    <t t-set="object" t-value="product"/>
  <t t-set="disable_composer" t-value="1"/>
</t>
class ProductTemplate(models.Model):
    _inherit = 'product.template'
    
    def _get_product_order_sale(self, product):
        attributes = []
        partner_ids = self.env['sale.order'].sudo().search([('partner_id', '=', self.env.user.partner_id.id)])
        for partner in partner_ids:
            for order in partner.order_line:
                if order.product_id.name == product.name:
                    attributes.append(order.product_id.name)
        return attributes
上一篇 下一篇

猜你喜欢

热点阅读