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

i want to get help from seniors here. i have created 3 models 1 parent 2 child, please see below for one2many fields i used here, is it correct or anything i have to modify and have some standard of Odoo. removed some fields to minimize the code to mention here. seeking guide and expert opinion.


class DoneeRegister(models.Model):

_name = 'donee.register

_description = 'Donee Registration'


name = fields.Char(string='Donee Name')

donee_type_id = fields.Many2one('donee.types', string='Type')

contact_no = fields.Char(string='Mobile No.')

address = fields.Char(string='Address')

is_active = fields.Boolean(string='Active?')

donee_ids = fields.One2many('donee\\\.family\\\.members',\\\ 'donee_id',\\\ string="Donee\\\ Family"\\\)

donee_rel_ids\\\ =\\\ fields\\\.One2many\\\('donee\\\.relatives',\\\ 'donee_rel_id',string="Donee\\\ Relative"\\\)



class\\\\ DoneeFamily\\\\(models\\\\.Model\\\\):

_name\\\ =\\\ 'donee.family.members'

_description = 'Donee Family Members'


name = fields.Char(string='Family Member Name')

donee_id = fields.Maony2one('donee.register', 'id', string='Donee', ondelete='cascade', required=True)

contact_no = fields.Char(string='Mobile No.')



class DoneeRelatives(models.Model):

_name = 'donee.relatives'

_description = 'Donee Relatives'


name = fields.Char(string='Relative Name')

donee_rel_id = fields.Maony2one('donee.register', 'id', string='Donee', ondelete='cascade', required=True)

contact_no = fields.Char(string='Mobile No.')

address = fields.Char(string='Address')


regards

Avatar
Discard
Best Answer

Hi,

The `donee_ids` and `donee_rel_ids` fields in the parent class could be made more explicit by providing them with more descriptive names that clearly indicate their purpose or the kind of data they hold. This can improve the readability and maintainability of the code. For example:

- `donee_ids` could be renamed to something like `family_member_ids` based on the context.
- `donee_rel_ids` could be renamed to `relative_ids`.

By choosing more descriptive names, it becomes easier for developers (including yourself) to understand the purpose and usage of these fields when working with the code.

Try:
```python
family_member_ids = fields.One2many('donee.family.members', 'donee_id', string="Family Members")
relative_ids = fields.One2many('donee.relatives', 'donee_rel_id', string="Relatives")

Hope it helps

Avatar
Discard
Author

thanks very much for your inputs and guide.

regards

Related Posts Replies Views Activity
1
Jan 24
1765
1
Dec 22
2659
1
May 25
2132
1
Apr 25
3210
1
Apr 25
4016