class account_invoice_serial(models.Model):
_name = 'account.invoice.serial'
_description = "Product serial numbers"
_order = 'name'
name = fields.Char('Serial Number',track_visibility='always')
line_id = fields.Many2one('account.invoice.line',)
product_id = fields.Many2one('product.product', string='Product',)
class account_invoice_line(models.Model):
_inherit = 'account.invoice.line'
serial_number_ids = fields.One2many(comodel_name='account.invoice.serial', inverse_name='line_id', string='Serial numbers', readonly=False, copy=False)
<record id="invoice_form" model="ir.ui.view">
<field name="name">account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form" />
<field name="arch" type="xml"> <xpath expr="//tree/field[@name='name']" position="after"> <field name="serial_number_ids" widget="One2many_list" options="{'no_create': True, 'no_create_edit': True }" />
</xpath>
</field>
</record>
I want to display a list of "names", instead I get a list of record ids. Are there a better widget to use?
This is my current work-a-round:
class account_invoice_line(models.Model):
_inherit = 'account.invoice.line'
serial_number_ids = fields.One2many(comodel_name='account.invoice.serial', inverse_name='line_id', string='Serial numbers', readonly=False, copy=False)
def _serial_numbers(self):
self.serial_numbers = ', '.join([s.name for s in self.serial_number_ids])
serial_numbers = fields.Char('Serial Numbers',compute="_serial_numbers",readonly=True)
This is my current solution: class account_invoice_line(models.Model): _inherit = 'account.invoice.line' serial_number_ids = fields.One2many(comodel_name='account.invoice.serial', inverse_name='line_id', string='Serial numbers', readonly=False, copy=False) def _serial_numbers(self): self.serial_numbers = ', '.join([s.name for s in self.serial_number_ids]) serial_numbers = fields.Char('Serial Numbers',compute="_serial_numbers",readonly=True)
in this xml attribute widget="One2many_list" 'O' must be small like this widget="one2many_list"
Based on little R&D, there is nothing like this widget in the tree view. There is one widget called "many2many_tags" can be used in the tree view but I am not sure it can be used for one2many field. You can give it a try.