【问题标题】:Display sum of numbers in the groups in odoo-12在odoo-12中显示组中的数字总和
【发布时间】:2021-09-12 08:06:47
【问题描述】:

我创建了两个字段并在树视图中定义了它们的视图。我将属性 sum 添加到字段视图以显示总和,但它仅适用于树视图,不适用于组。我怎样才能在组中显示总和?

这是python部分:

quantity_in = fields.Float('Quantity In', compute='get_qty_in')
quantity_out = fields.Float('Quantity Out', compute='get_qty_in')

这是字段视图的 xml 部分:

<record id="stock_move_inherit_view" model="ir.ui.view">
  <field name="name">stock.move.inherit.view</field>
  <field name="model">stock.move.line</field>
  <field name="inherit_id" ref="stock.view_move_line_tree"/>
  <field name="arch" type="xml">
    <xpath expr="//field[@name='qty_done']" position="before">
      <field name="quantity_in" sum="Total In Quantity"/>
      <field name="quantity_out" sum="Total Out Quantity"/>
      <field name="quantity_total"/>
    </xpath>
  </field>
</record>

【问题讨论】:

    标签: python xml odoo-12


    【解决方案1】:

    需要继承模型/类的read_group方法: 例如你的字段名是quantity_in

    class Your_class_name(models.Model):
        # ...        
        @api.model 
        def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
            res = super(your_class, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
            if 'quantity_in' in fields:
                for line in res:
                    if '__domain' in line:
                        lines = self.search(line['__domain'])
                        in_quantity = 0.0
                        for record in lines:
                            in_quantity += record.quantity_in
                        line['quantity_in'] = in_quantity
            return res
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-25
      • 2020-06-25
      • 1970-01-01
      相关资源
      最近更新 更多