Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
In a v8 installation with analytic accounting feature, I have been asked to show on the analytic account form view (analytic.view_account_analytic_account_form) a link to the related project.
On the server side I have to browse the project model searching a project having as analytic account the current one, I suppose something like (I use the limit=1 since the relation between project and analytic_account is an o2o):
project = self.env['project.project'].search([('analytic_account_id', '=', self.id)], limit=1)
How could I pass this value to the view, in order to show a link?
Should I use a context? and how?
you can make new many2one computed field and reuse your code, that you posted in the question, inside the compute function for a new many2one field.
project_id = fields.Many2one(comodel_name="project.project", string="Project", compute="_compute_project_id")
self.project_id = self.env['project.project'].search([('analytic_account_id', '=', self.id)], limit=1) #I simply copied your code here
<field name="project_id" />
you can make new one2many field, connecting to the project and in the inverse_name parameter, put the analytic_account_id, so it'll be automatically find it's other end. It should work, if as you stated the relation is one2one in the practice, and you can then force this field to display as a link, instead of a table, by explicitly putting widget="many2one" in the xml definition of view.
project_id_s = fields.One2many(comodel_name="project.project", inverse_name="analytic_account_id", string="Project")
<field name="project_id_s" widget="many2one" />
There may be more options, but one of the two should work for you I think.
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
|Asked: 2/26/16, 4:41 AM|
|Seen: 720 times|
|Last updated: 2/29/16, 6:41 AM|