我刚刚意识到用户不能像One2many
字段那样通过接口对Many2many
字段进行排序。在
在标准的One2many
字段中,可以看到comodel及其字段的树视图。如果您单击One2many
的字段名(列的名称),它的树状视图将根据您单击的字段自动排序(如果该字段存储在数据库中),您将看到一个小箭头图标。在
但是在标准的Many2many
字段中,如果您单击任何列的名称(字段存储在数据库中并不重要),它什么也不做,您不能对其树视图排序。在
事实上,如果在Many2many
中打开XML树属性default_order
似乎不起作用。在
唯一仍然有效的是_order
如果我将其添加到com模型的Python定义中。在
例如:
我有一个指向Many2many
的字段。我不会告诉字段打开任何特定视图,因此默认情况下会加载以下树视图:
<record model="ir.ui.view" id="account_treasury_forecast_invoice_tree_view">
<field name="name">account.treasury.forecast.invoice.tree</field>
<field name="model">account.treasury.forecast.invoice</field>
<field name="arch" type="xml">
<tree string="Invoices" widget="many2many">
<field name="date_due" />
<field name="invoice_id" />
<field name="partner_id"/>
<field name="journal_id" />
<field name="base_amount" sum="Total Base" />
<field name="tax_amount" sum="Total Taxes" />
<field name="total_amount" sum="Total" />
<field name="residual_amount" sum="Total Residual" />
<field name="state" />
</tree>
</field>
</record>
我已经意识到,如果在Many2many
字段中打开以下视图,default_order
什么也做不了。在
至少_order
起作用:
class AccountTreasuryForecastInvoice(models.Model):
_name = 'account.treasury.forecast.invoice'
_description = 'Treasury Forecast Invoice'
_order = 'date_due'
但问题是接口不允许用户按它的任何字段排序,我希望允许他们有时按date_due
排序,有时按invoice_id
排序。我该怎么办?您在Many2many
字段中是否遇到相同的问题?在
目前没有回答
相关问题 更多 >
编程相关推荐