Javascript 如何在xml中获取当前公司。奥多14
我在“account.payment.register”模型中添加了一个字段(类型char)Javascript 如何在xml中获取当前公司。奥多14,javascript,python,xml,odoo,Javascript,Python,Xml,Odoo,我在“account.payment.register”模型中添加了一个字段(类型char) <field name="inherit_id" ref="account.view_account_payment_register_form"/> <field name="arch" type="xml"> <xpath expr="//group/fiel
<field name="inherit_id" ref="account.view_account_payment_register_form"/>
<field name="arch" type="xml">
<xpath expr="//group/field[@name='communication']" position="after">
<field name="company" attrs="{'invisible': [('journal_type', '=', 'cash')], 'required': [('journal_type', '=', 'bank')]}"/>
</xpath>
</field>
</field>
我想根据以下条件在“公司”字段中添加默认值:
- 如果是“出站”付款,则公司必须获得当前公司
- 如果是“入站”付款,公司将获得一个空字段。 我可以用xml代码完成吗?需要帮忙吗? 谢谢
[('company\u id','=',user.company\u id.id)您可以使用onchange api和compute company字段。如果您使用默认company\u id字段,则必须删除相关的属性
@api.onchange('payment_type')
def default_get_company(self):
for record in self:
if record.payment_type == 'outbound':
record.company = self.env.company.id
# if its char field then self.env.company.name
else:
record.company = ''
只需在company变量中添加默认属性。我只想为“payment\u type”设置此值:“outbound”,
company = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id.id if self.payment_id == 'outbound' else None)