[英]How to get the current company in xml. Odoo 14
I added a field (type char) in model 'account.payment.register',我在 model 'account.payment.register' 中添加了一个字段(字符类型),
<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>
I want to add default value in field 'Company' according to these conditions:我想根据这些条件在“公司”字段中添加默认值:
You can use onchange api and compute company field.您可以使用onchange api和计算公司字段。 If you are using default company_id field then you have to remove attribute related .如果您使用默认的company_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 = ''
YOu can use Mentioned below您可以使用下面提到的
[('company_id','=',user.company_id.id) [('company_id','=',user.company_id.id)
company = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id.id if self.payment_id == 'outbound' else None)
Just add default attribute in the company variable.只需在公司变量中添加默认属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.