Skip to Content
Menu
This question has been flagged
1 Reply
11671 Views

While creating a One2many field we required  a inverse name (name of the inverse Many2one field in comodel_name) But Wizard records may refer to regular records or wizard records through many2one fields, but regular records cannot refer to wizard records through a many2one field!!!.

SO How can we create One2many field in a wizard.?

I have done like....

class sales_test_wizard(models.TransientModel):
    _name = 'sales.test.wizard'

    from_date = fields.Date(string="Date From") 
    to_date = fields.Date(string="Date To")  
    name =   fields.Char(string="Name", size=32, required=True)   
    sales_test_report = fields.One2many('sales.register', 'register_wiz_id', string='Sales Test')

class sales_register(models.Model):
    _name = 'sales.register'

    name = fields.Char('Order Reference')  
   date_order = fields.Datetime('Date') 
   partner_id = fields.Many2one('res.partner', 'Customer')
  amount_total = fields.Float(string='Total')
  register_wiz_id = fields.Many2one('sales.test.wizard','Register Wizard ID')


Am getting an error like : AssertionError: Many2One relationships from non-transient Model to TransientModel are forbidden

Can anyone please find me a solution for this...

Avatar
Discard

Hello, you're found any solution related to this problem?

Best Answer

Hey Undan,

FYI, One2many fields are never stored in database so we use a Many2one relation which stores a reference of One2many field in the database.

Also, Transient Model is never stores the values of fields in the database. You cannot use a relationship by this way, Instead you should use both the models as Transient. (keeping a single view)

Hope this helps you.

Thanks!

Avatar
Discard

OK, Than any alternative to achieve this one?

Hello Undan,

First can you share why you want to use field of TransientModel and if you want to use field you need to change class from class sales_test_wizard(models.TransientModel) to class sales_test_wizard(models.Model).

Regards,

Aktiv Software

Ok, thanks.