Skip to Content
Menu
This question has been flagged
1 Reply
3055 Views

Hello,

I have to create new custom_module that add fields to the hr_employees view.

One of the fields I have to view, is the private mobile number of the employee, which is exist now in the related res_partner model.

How can I get it in the new custom module? 


I tried to write like taht, but got the error:

Field `mobile` does not exist


model.py file:  

from odoo import models, fields, api


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

    mobile = fields.Char(related='address_home_id.phone'related_sudo=False,
                         string="Private Mobile"groups="hr.group_hr_user")

views.xml file: 

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="view_employee_form_custom_inherit" model="ir.ui.view" >
            <field name="name">hr.employee.custom.form.inherit</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@name='personal_information']" position="inside">
                    <group string="Phone">
                        <field name="phone" class="o_force_ltr" groups="hr.group_hr_user" string="Phone"/>
                        <field name="mobile" class="o_force_ltr" groups="hr.group_hr_user" string="Mobile"/>
                    </group>
                </group>
            </xpath>
        </field>
    </record>
</data>
Avatar
Discard
Best Answer

Hi,

So whats the issue that you are facing ? new field wont be able to add to the employee form view? or you are looking to get the value of the mobile number from the partner(linked to the user) ?


If the case is the first one, make sure that the module is installed, python files are called in the init and xml file is added in the manifest, once these are done the newly added field will be visible in the user interface.


If the case is the second one, ie, you need to get the mobile number value from partner, you can try with the related field in odoo: related='user_id.partner_id.mobile'


1. https://www.youtube.com/watch?v=z1Tx7EGkPy0

2. Related Field: https://www.youtube.com/watch?v=pD6byjEvIx8


Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 24
430
2
Nov 24
763
3
Oct 23
13197
2
Feb 23
1229
1
Dec 22
1371