Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2839 Widoki

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?


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
kwi 24
8906
0
mar 16
3068
3
lip 25
8646
1
maj 25
937
0
sty 24
1673