I am implementing a tree view in a tree view to display data. In the job_description model. we have a details_id that links the job description to the job details stored in another table also included below
from odoo import models, fields
class WorkPlan(models.Model):
_name = 'job.description'
_description = 'Job Description'
job_id = fields.Many2one('hr.job', string='Job Position', readonly=True)
job_purpose = fields.Text(string='Job Purpose', required=True)
details_ids = fields.One2many('job.description.details', 'job_description_id', string='Details')
from odoo import models, fields
class JobDescriptionDetails(models.Model):
_name = 'job.description.details'
_description = 'Job Description Details'
key_result_area = fields.Text(string='Key Result Area', required=True)
principal_accountabilities = fields.Text(string='Principal Accountabilities', required=True)
job_description_id = fields.Many2one('job.description', string='Work Plan')
The following is the xml page that handles the logic. When adding information. I don’t have a problem, it is saving and when I go to check on a particular job it is showing. However when I restart the server the when I go to the record it is showing that it has data but the table is blank. More information included below.
The xml file that handles the view
<odoo>
<data>
<record id="view_job_description_details_tree" model="ir.ui.view">
<field name="name">job.description.details.tree</field>
<field name="model">job.description.details</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="key_result_area"/>
<field name="principal_accountabilities"/>
</tree>
</field>
</record>
<record id="view_job_description_tree" model="ir.ui.view">
<field name="name">job.description.form</field>
<field name="model">job.description</field>
<field name="arch" type="xml">
<tree>
<field name="job_id"/>
<field name="job_purpose"/>
<field name="details_ids" widget="one2many_list" options="{'no_create': True}">
<tree string="Details" editable="bottom" view_id="view_work_plan_goals_tree"/>
</field>
</tree>
</field>
</record>
</data>
Below is how it is coming up when i restart the server
after server restart
Below when I click on any of the headers after restart
after clicking either add line or the headers
I tried computing the details_id fields using the following code but it makes the data in the details_ids table to disappear completely
class JobDescription(models.Model):
_name = 'job.description'
_description = 'Job Description'
job_id = fields.Many2one('hr.job', string='Job Position', readonly=True)
job_purpose = fields.Text(string='Job Purpose', required=True)
details_ids = fields.One2many('job.description.details', 'job_description_id', string='Details', compute='_compute_details_ids')
@api.depends('job_id')
def _compute_details_ids(self):
for record in self:
if record.job_id:
record.details_ids = self.env['job.description.details'].search([('job_description_id', '=', record.job_id.id)])
else:
record.details_ids = self.env['job.description.details']
def read(self, fields=None, load='_classic_read'):
result = super(JobDescription, self).read(fields, load)
self._compute_details_ids()
return result
HelpDesk Jhpiego is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.