我創建了兩個欄位并在樹狀視圖中定義了它們的視圖。我在欄位視圖中添加了屬性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">/span>stock。 move.line</field>股票。
<field name="inherit_id" ref="stock. view_move_line_tree"/>。
< field name="arch" type="xml">/span>
< 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"/>/span>
</xpath>
</field>/span>
</record>
uj5u.com熱心網友回復:
你需要繼承模型/類的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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/307730.html
標籤:
