Skip to Content
Menu
This question has been flagged
2030 Views

Given these classes:

class years(models.Model): 
_name = 'years'
name = fields.Integer(required=True)

For different years I have different categories.

class category(models.Model): 
_name = 'category'
year_id = fields.Many2one('years', required=True, default=get_year)
name = fields.Char(required=True)
class parent(models.Model):
_name = 'parent'
  name = fields.Char(required=True)
year_id = fields.Many2one('years', required=True, default=get_year)
class child(models.Model): 
_name = 'child'
parent_id = fields.Many2one('parent', required=True)
name = fields.Char(required=True)
year_id = fields.Many2one('years', required=True, default=get_year)
category_id = fields.Many2one('category', required=True)
value = fields.Float(required=True)

The data looks like this:

years

id name
1 2015
2 2016

category

id year_id name
1 1 Sample 1
2 1 Sample 2
3 2 Sample 3
4 2 Sample 4

parent:

id name       year_id
1 Parent 1 1

child should be this:

id parent_id name    year_id category_id value
1 1 Child 1 1 1 154.452
1 1 Child 2 1 2 100

instead of that I have this:

id parent_id name      year_id category_id value
1  1         Child 1 1 1 154.452
1 1 Child 2 1 4 100

My question is: How can I "inherit" the year_id in the child record from the parent, and how can I limit the categories in the dropdown list (Many2one) to that specific year?

As I've seen I cannot have a related field parent_id.year_id as during the creation this value is not set so I cannot use a domain restriction of the category to that specific year.


Any idea?


Avatar
Discard
Related Posts Replies Views Activity
2
Apr 24
7623
0
Mar 16
2278
0
Jan 24
378
2
May 23
6768
2
Apr 23
4983