1

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:

  • if it is an 'outbound' payment , then Company must get the current company .
  • if it is an 'inbound' payment , Company get an empty field. Can I do it with xml code ? Any help please ? Thanks.
Ing
  • 551
  • 7
  • 20

3 Answers3

2

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 = ''
Yagami
  • 305
  • 2
  • 14
  • can you help? https://stackoverflow.com/questions/68066061/what-is-the-file-path-of-account-aged-payable-model-and-how-to-edit-aged-payable – Manan Jun 21 '21 at 10:13
0

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.

Khay Leng
  • 391
  • 5
  • 8
-1

YOu can use Mentioned below

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

Lakshminarayanan
  • 320
  • 4
  • 18