Odoo Help

2

0
1 Answer
2
Avatar

Sudhir Arya (ERP Harbor Consulting Services) India

--Sudhir Arya (ERP Harbor Consulting Services)--
26747
| 8 9 10
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 

LinkedIn

Blog

Stackoverflow

ERP Harbor Consulting Services

Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Sudhir Arya (ERP Harbor Consulting Services) India
8/3/18, 12:43 AM

You can do this from the onchange of the project and return the domain.

Ex:

api.onchange('project_id')
def onchange_project(self):
    tag_ids = []
    if self.project_id:
        for task in self.project_id.task_ids:
            tag_ids += task.tag_ids.ids
    return {'domain': {'tag_ids': [('id', 'in', tag_ids)]}}
Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
5 Comments
Willmore BattleShipNet Lithuania
8/3/18, 3:49 AM

Thank you. I tried but got error. What can be wrong with that approach?

I have the following code

class InheritedProjectTask(models.Model):

"""docstring"""

_inherit = 'project.task'

@api.onchange('project_id')

def onchange_project(self):

"""docstring"""

tag_ids = []

if self.project_id:

tag_ids += [task.tag_ids.ids for task in self.project_id.task_ids]

return {'domain': {'tag_ids': [('id', 'in', tag_ids)]}}

With this code installed. I open a Project and click "Create" to open a Task creation form (form for new "project.task" model's object). On that form I click on drop-down "Tags" to list possible "Tags" for the project ("possible tags for the project" are all tags that are used on any of the task of the project the task is created for). And then I get error:

> res = self._obj.execute(query, params)

>

> TypeError: not all arguments converted during string formatting

on the console I see the error

> INFO DB odoo.sql_db: bad query: SELECT "project_tags".id FROM "project_tags" WHERE (("project_tags"."id" in (%s,%s,%s,%s,%s,%s,%s,%s)) AND (("project_tags"."id" not in (%s)) OR "project_tags"."id" IS NULL)) ORDER BY "project_tags"."id" limit 8

2018-08-03 10:40:20,476 12978 ERROR DB odoo.http: Exception during JSON request handling.

What did I do wrong in the code?

Sudhir Arya (ERP Harbor Consulting Services) India
8/3/18, 4:22 AM

See my updated code in answer. It should work now.

Willmore BattleShipNet Lithuania
8/3/18, 7:14 AM

Thank You very much for the proposed solution! I would not come to that in near time! :) But after applying it I can see on the "Tags" field (in debug mode when I hover over "Tags" drop down) that effective Domain is id, in,4,5,6,7,8,9,10,11,12,13,14,18,19,20,22,23,24,25,26,27,28,5,4,5,35 . And that is the problem: it doesn't really take tags from just this project's tasks. Tags from other projetcs tasks appear too which is unwanted. How this can be that all tags are included not just those from tasks of the current project?

Sudhir Arya (ERP Harbor Consulting Services) India
8/3/18, 7:21 AM

It will only show all the tags which are used in the tasks of selected project.

Willmore BattleShipNet Lithuania
8/6/18, 2:21 AM

It is really strange. I do the following: 1) Open "Projects". 2) Click "Create" 3) Create a project with a name "Really new project". 4) I open project "Really new project" tasks window. This window is empty as we didn't create any tasks yet. 5) I click "Create" and a form to create new task appears. 6) I enter task title "This is really new task in a really new project" . 7) In the field "Tags" I click with mouse and drop-down appears with text "No results to show" and I enter "1234657890" (this tag name is never used anywhere so it's completely new tag). I click "Create 1234657890" for this tag to be created and it appears in "Tags" field. So far so good. 8) I press "Save" on the task so that the new record is saved. Task is saved and on the form appears a button "Edit". 9) without reloading a page I click "Edit" and click on the "Tags" for drop-down to appear. Drop-down appears and it contains text "No results to show" (this is good because there are no more tags in that project to be selected because we have not created any other tags). I type "qqq" in "Tags" and create this tag, then on the task form I press "Save" to save that task. Then I navigate to any other project (let's say I navigate to **Another project**) and open one of project's tasks just to see it. And then I navigate to the project "Really new project" and press "Edit" and click "Tags" and I see all the tags appear from other project's. Why?

What I have noticed. If I go to any project (project1) and open a task of it then navigate to another project (project2) and click "Create" to create new task for the project2 then on "Tags" there will be only tags from project1 tasks (as we want) it seems that domain works. BUT if I go to any project (project1) and open a task of it then navigate to another project (project2) and click "Edit" to edit a task (of the project2) then on "Tags" there will be ALL TAGS (as if domain was ineffective). How is that possible?

I have noticed (from looking at the console output) that method onchange is called only when I click "Create" on the task. So I have troubles when I want to edit task because onchange is not called and all tags show up :(.

Is there anything else I could add besides onchange to make domain apply all the time.

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now