This question has been flagged
2 Replies
4080 Views

Dear
I need in the Employee module to perform a search for a field in a table that has the following relationship:

class AiHrEmployee (models.Model):
_inherit = ['hr.employee']

collaborations_ids = fields.One2many ('hr.employee.collaboration.line', 'employee_id', "Collaboration activities")

class AiCollaborationActivityLine (models.Model):
_name = "hr.employee.collaboration.line"

employee_id = fields.Many2one ('hr.employee', 'Employee')
country_id = fields.Many2one ('res.country', 'Place of collaboration')
activity = fields.Char (string = "Activity of collaboration", size = 80)
time = fields.Integer (string = "Time", help = "Time of collaboration")

Country class:
_name = "res.country"
name = fields.Char ()

In the Employee view I want to do the search to show all the employees that have had collaboration in a certain country (country) that I enter.
For example:
Add Custom Filter
country
contains
cuba

I work with Odoo 11.0

I would appreciate any help in this respect.

Thanks you for advance!

Best regards,
Claudio


Avatar
Discard
Best Answer


Yes Possible, all you need is the following

Step 1: In the Object: AiCollaborationActivityLine

define _rec_name = 'country_id'  -- this set Name property for your custom object, which will be easier to perform default search.


Step 2: In the Object Hr.Employee.

Search View (XML) add field for collaborations_ids == Thus user can search directly


Same kind of features are also available in standard objects like Stock-Picking, Invoice -- Do refer for more ideas


Avatar
Discard
Author Best Answer

Dear deep, thank you very much!

I also just received another solution variant sent by Jorge Tuñez:

<record id="ai_rh_gedic_studies_search" model="ir.ui.view">
<field name="name">ai.rh.gedic.studies.search</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_filter"/>
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<field name="collaborations_ids" string="Activity of collaboration" filter_domain="[('collaborations_ids.country_id.name','ilike',self)]">
</field>
</xpath>

</field>
</record>
Avatar
Discard