域过滤器没有'没有效果(odoo12)



我尝试这样做:当创建发票时,如果客户是"x〃;某些期刊必须限制在";注册支付";形成

这是我的.py型号

from odoo import api, fields, models

class AccountPayment(models.Model):
_inherit = "account.payment"
_description = "Restrict Journals"
partner_id_check = fields.Integer(compute="_compute_value")
restriction_value = fields.Boolean(related="journal_id.restriction")
@api.onchange("partner_id")
def _compute_value(self):
if self.partner_id.name == "Generic":
self.partner_id_check = 1
else:
self.partner_id_check = 0

class AccountJournal(models.Model):
_inherit = "account.journal"
_description = ""
restriction = fields.Boolean(string="Generic Restriction")

这是我的.xml文件

<record id="account_journal_view_form" model="ir.ui.view">
<field name="name">account.journal.view.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet//field[@name='type']" position="before">
<field name="restriction"/>
</xpath>
</field>
</record>
<record id="payment_invoice_form" model="ir.ui.view">
<field name="name">payment.invoice.form</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_invoice_form"/>
<field name="priority" eval="16"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='journal_id']" position="attributes">
<attribute name="domain">
[('restriction_value','=',True),('partner_id_check','=',1)]
</attribute>
</xpath>
</field>
</record>

问题是,来自xpath的域不起作用。我没有任何错误,但它没有效果。如果打开开发者模式并获取字段,域就在那里,xpath是正确的,我认为域语法不正确。我试了所有的东西,但似乎不起作用

谢谢你的回答,但不起作用,但我最终用一个onchange解决了它,没有这两个字段:

class AccountPayment(models.Model):
_inherit = "account.payment"
@api.onchange('journal_id')
def _onchange_journal(self):
if self.partner_id.name == "Generic":
return {'domain': {'journal_id': [('restriction', '=', False), ('type', 'in', ('bank', 'cash'))]}}
else:
return {'domain': {'journal_id': [('type', 'in', ('bank', 'cash'))]}}
class AccountJournal(models.Model):
_inherit = "account.journal"
_description = ""
restriction = fields.Boolean(string="Generic Restriction")

这是xml

<record id="account_journal_view_form" model="ir.ui.view">
<field name="name">account.journal.view.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet//field[@name='type']" position="before">
<field name="restriction"/>
</xpath>
</field>
</record>

当我第一次运行这个时,它没有";否则";在代码的末尾,我从基本模型帐户中得到了一个错误。后来我发现,当条件不满足时,有必要返回域。

最后,这个答案的鳕鱼效果很好。

partner_id_check = fields.Integer(compute="_compute_value", store=True)
restriction_value = fields.Boolean(related="journal_id.restriction", store=True)

相关内容

  • 没有找到相关文章

最新更新