Reputation: 405
I want to display a custom field in many2one field in odoo but only in a particular view, the sales order view. These are my models
class SalesPartnerBankInherit(models.Model):
_inherit = 'res.partner.bank'
display_on_sales = fields.Boolean(string='Display On Sales Quotation '
'Report', readonly=False)
location = fields.Char()
I want to display the location field in my many2one field in sales order.
class CustomSalesInherit(models.Model):
_inherit = 'sale.order'
quotation = fields.Text(string='Quotation Title', readonly=False,
compute='_compute_quotation_title',
location = fields.Many2one('res.partner.bank', domain=[('location', '!=', None)],
string='Bank Account Location')
Upvotes: 1
Views: 364
Reputation: 14768
I don't really see where the real connection between bank accounts and sales orders are in your case, but a second field should work. But first you should rename the Many2one field to res.partner.bank
.
class CustomSalesInherit(models.Model):
_inherit = 'sale.order'
# i've added display_on_sales to the domain
# because the field names makes sense for using it here
partner_bank_id = fields.Many2one(
comodel_name='res.partner.bank',
domain=[('location', '!=', None), ('display_on_sales', '=', True)],
string='Bank Account Location')
# related field to location
location = fields.Char(related="partner_bank_id.location")
Upvotes: 1