【问题标题】:How to get the current company in xml. Odoo 14如何在xml中获取当前公司。奥多 14
【发布时间】:2021-03-30 19:25:24
【问题描述】:

我在模型“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>

我想根据这些条件在“公司”字段中添加默认值:

  • 如果是“对外”付款,则 Company 必须获取当前公司。
  • 如果是“入站”付款,公司会得到一个空白字段。 我可以用xml代码来做吗?请问有什么帮助吗? 谢谢。

【问题讨论】:

    标签: javascript python xml odoo


    【解决方案1】:

    您可以使用 onchange api 和计算公司字段。如果您使用默认的 company_id 字段,则必须删除属性 related

    @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 = ''
    

    【讨论】:

    【解决方案2】:

    你可以使用下面提到的

    [('company_id','=',user.company_id.id)

    【讨论】:

    • 我只想为'payment_type'设置这个值:'outbound',
    【解决方案3】:
    
    company = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id.id if self.payment_id == 'outbound' else None)
    
    

    只需在 company 变量中添加 default 属性即可。

    【讨论】:

      猜你喜欢
      • 2021-08-31
      • 2022-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多