Odoo 视图继承:如何修改帐户付款表单中付款日志字段的域
Odoo View inheritance: how to modify the domain for the Payment Journal field in the Account Payment form
我有一个自定义的 Odoo 模块,其中包括记录付款。为此,我使用了会计模块中的付款表格。
我想允许用户根据 account.journal
实体上的标志过滤“付款日志”下拉列表中的选项,因此我按如下方式扩展了该实体:
class AccountJournal(models.Model):
_inherit = 'account.journal'
available_as_payment_method = fields.Boolean(string='Available as payment method')
...并在用于编辑付款日志的视图中添加了字段:
<field name="available_as_booking_payment_method"/>
此功能按预期工作并且该字段存在于数据库中。
最后我扩展了付款表格:
<record model="ir.ui.view" id="payment_form_update_form">
<field name="name">payment_form_update</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_form" />
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='journal_id']" position="attributes">
<attribute name="domain">[('available_as_booking_payment_method', '=', True)]</attribute>
<!-- <attribute name="invisible">1</attribute> -->
</xpath>
</field>
</record>
出于某种原因,如果我修改域属性,它不会应用。屏幕截图显示了 Odoo 调试弹出窗口中的现有域 - 这在我的视图或默认视图中保持不变。
如果我应用 invisible
标志,该字段就会消失,所以我知道视图和 xpath 是正确的。
感谢您就未应用域的原因提供帮助。
提前致谢
因为journal_id在.py文件中有域定义,你也可以尝试覆盖.py文件中的域,像这样:
journal_id = fields.Many2one(domain=[('available_as_booking_payment_method', '=', True),('type', 'in', ('bank', 'cash'))])
希望这个回答对您有所帮助。
我有一个自定义的 Odoo 模块,其中包括记录付款。为此,我使用了会计模块中的付款表格。
我想允许用户根据 account.journal
实体上的标志过滤“付款日志”下拉列表中的选项,因此我按如下方式扩展了该实体:
class AccountJournal(models.Model):
_inherit = 'account.journal'
available_as_payment_method = fields.Boolean(string='Available as payment method')
...并在用于编辑付款日志的视图中添加了字段:
<field name="available_as_booking_payment_method"/>
此功能按预期工作并且该字段存在于数据库中。
最后我扩展了付款表格:
<record model="ir.ui.view" id="payment_form_update_form">
<field name="name">payment_form_update</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_form" />
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='journal_id']" position="attributes">
<attribute name="domain">[('available_as_booking_payment_method', '=', True)]</attribute>
<!-- <attribute name="invisible">1</attribute> -->
</xpath>
</field>
</record>
出于某种原因,如果我修改域属性,它不会应用。屏幕截图显示了 Odoo 调试弹出窗口中的现有域 - 这在我的视图或默认视图中保持不变。
如果我应用 invisible
标志,该字段就会消失,所以我知道视图和 xpath 是正确的。
感谢您就未应用域的原因提供帮助。
提前致谢
因为journal_id在.py文件中有域定义,你也可以尝试覆盖.py文件中的域,像这样:
journal_id = fields.Many2one(domain=[('available_as_booking_payment_method', '=', True),('type', 'in', ('bank', 'cash'))])
希望这个回答对您有所帮助。