在odoo中添加计数器按钮以将字段值更新为1



我想在报告中添加计数器。我的意思是,每次我单击打印按钮时,报告都必须以+1的增量打印,写成重印1,重印2,重印3等。您对解决这种技术有任何想法吗?如果不可能,我有另一个想法,但我也不知道该怎么做。那就是:在表单中添加一个字段,每次我单击自定义打印按钮时,字段值都会增加 1。更新后的字段将打印在报告中。 我仍然是一个学习的孩子。请举例回复。

我拥有的是: 在此处输入图像描述

<record id="apple_view_form" model="ir.ui.view">
<field name="name">Apple Form</field>
<field name="model">se.apple</field>
<field name="arch" type="xml">
<form>
<header>
<button name="print_report" string="Print Apple" type="object"/>
</header>
<h1 class="dexter">This is Dexter</h1>
<sheet>
<group name="group_top">
<group name="group_left">
<field name="apple_name"/>
</group>
<group name="group_right">
<field name="apple_price"/>
</group>
</group>
<group name="group_bottom">
<field name="apple_description"/>
<field name="apple_remarks"/>
</group>
<templates id="template" xml:space="preserve">
<t t-name="custom_btn">
<button string="Custom Button">Custom Button</button>
</t>
</templates>
</sheet>
</form>
</field>
</record>

就像你建议的那样,你可以在模型中创建一个不可见的字段。然后,继承打印方法并使其递增该不可见字段。由于报表将具有整个可用对象,因此您只需访问报表中的不可见字段。