跳至內容
選單
此問題已被標幟
2824 瀏覽次數

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?


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
4月 24
8895
0
3月 16
3054
3
7月 25
8628
1
5月 25
922
0
1月 24
1657