Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3879 Widoki

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>
Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
4
lut 25
2740
1
sie 24
2246
2
lis 24
3401
3
paź 23
14926
2
lut 23
2521