Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
2766 Переглядів

Hi all, I need to inherit parent class attributes and functions to  a child class but to create a child entry, i have to create first the parent reference and child attribut (here: amount and is_active).

I would like to automatically create the parent object and  child from on form. ie a form with name, code, amount and is_active

We put all required attributes and asked odoo to create parent and child references.

Any suggestion please ?

Best regards

PS: I'm using odoo15

class ParentModel(models.Model):
_description = "Parent "
_name = "generic.parent"
name = fields.Char("Name", required=True)
code = fields.Char("Code", default="/", required=True)


class ChildModel(models.Model):
_description = "Child Model"
_inherits = {'generic.parent': 'parent_id'}
_name = "child.name"
amount = fields.Float("amount", default=0.0)
is_active = fields.Boolean("Is Active ?", default=False, required=True)
parent_id = fields.Many2one('generic.parent', string='Parent ID', ondelete='cascade')


Аватар
Відмінити

Read the concept of Odoo Inheritance: https://goo.gl/4Zyc9d

Найкраща відповідь

Inheritance in odoo models is not like the abstraction of other python frameworks such as Django and etc. The closest solution is for ParentClass to inherit from AbstractModel like:

class ParentModel(models.AbstractModel):
    _name = "generic.parent"
    name = fields.Char("Name", required=True)
    code = fields.Char("Code", default="/", required=True)


class ChildModel(models.Model):
  _inherit = 'generic.parent'
    amount = fields.Float("amount", default=0.0)
    is_active = fields.Boolean("Is Active ?", default=False, required=True)


Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
жовт. 22
3086
1
вер. 22
3177
1
серп. 22
3309
1
груд. 23
2534
0
вер. 23
1081