[英]Counting Rows of one2many field odoo
How can I count the rows of a one2many field and output the current row count?如何计算 one2many 字段的行数和 output 当前行数?
This is how it should work.For example:这就是它应该如何工作。例如:
1 ------column1------------ 1 ------第 1 列------------
2 ------column2------------ 2 ------第 2 列------------
3 ------column3------------ 3 ------第 3 列------------
4 ------Column4------------ 4 ------第4列------------
etc.. ETC..
I have made an automated action for this, but it does not work as intended:我为此做了一个自动操作,但它没有按预期工作:
The automated action refers to the model of the one2many field and is triggered when a record is created.自动动作是指one2many字段的model,在创建记录时触发。 The following Python code is executed:
执行以下 Python 代码:
for line in record.picking_id.move_line_ids_without_package:
for rec in str(record.x_studio_position):
record['x_studio_position'] = len(record.picking_id.move_line_ids_without_package)
What happens is the following for eg 4 columns例如 4 列会发生以下情况
4 ------column1------------ 4 ------第 1 列------------
4 ------column2------------ 4 ------第 2 列------------
4------column3------------ 4------第 3 列------------
4 ------column4------------ 4 ------第4列------------
It will write the total number in each row instead of the current column number.它将在每一行中写入总数而不是当前列号。
You set the position to the number of lines in the field move_line_ids_without_package
, it will be the same for all lines.您将 position 设置为
move_line_ids_without_package
字段中的行数,所有行都相同。
You can use enumerate
to get the line sequence您可以使用
enumerate
来获取行序列
Example:例子:
for index, line in enumerate(record.picking_id.move_line_ids_without_package):
line['x_studio_position'] = index + 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.