Ing
Ing

Reputation: 611

How to get the current company in xml. Odoo 14

I added a field (type char) in 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:

Upvotes: 1

Views: 2850

Answers (3)

Khay Leng
Khay Leng

Reputation: 451


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.

Upvotes: 0

Yagami
Yagami

Reputation: 315

You can use onchange api and compute company field. If you are using default company_id field then you have to remove attribute 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 = ''

Upvotes: 2

Lakshminarayanan
Lakshminarayanan

Reputation: 320

YOu can use Mentioned below

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

Upvotes: -1

Related Questions