Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

use composit keys

By
Gabor
on 5/24/16, 9:55 AM 192 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?


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/24/16, 9:55 AM
Seen: 192 times
Last updated: 5/24/16, 10:02 AM