Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
400 Lượt xem

Good evening Odoo community, I have my code from version 17 that I want to migrate to version 18, but I'm encountering an error that you'll see in point 4.

I remind you that it works fine in version 17, except that instead of using tree in version 17, I changed it to list.



1-MODEL FARMER

class Farmers(models.Model):

    _name = 'res.partner'

    _inherit = 'res.partner'

    _description = 'Planteurs'


    plantation_ids = fields.One2many('plantation.plantation', 'partner_id', 'Plantations')

    farmer = fields.Boolean('Planteur')

    myp_id = fields.Many2one('plantation.myp', string="Mode Reglement", )

    struct_id = fields.Many2one('planting.payroll.structure', string="Structure Salariale",)

    type_id = fields.Many2one('type.farmer', string="Type Planteur",)

    group_id = fields.Many2one('group.group', required=True, string="Groupe Tarification Planteur",)

    birthday = fields.Date(string='Date Immatriculation', required=False)

    number_aprocmac = fields.Char(string='Numero identification aprocmac', required=False)

    code_farmer = fields.Char(string='Code Planteur', required=True, index=True)

    prime_id = fields.Many2one('prime.prime', string="Groupe",required=False)


   


2-MODEL PLANTAPLANTATION 

# Plantations


class Plantation(models.Model):

    _name = 'plantation.plantation'

    _description = 'Plantations'

    _inherit = ['mail.thread', 'mail.activity.mixin']


    name = fields.Char('Identification plantation',required=True)

    number_geo = fields.Char('Numero Géolocalise')

    partner_id = fields.Many2one("res.partner", string="Planteur", required=False,ondelete="cascade", domain=[('farmer', '=', True)])

    frequency_id = fields.Many2one('frequency.payroll', string="Frequence de paie", required=True)

    area = fields.Char(string='Superficie',required=False)

    locality_id = fields.Many2one("locality.locality","Région",required=False)

    sector_id = fields.Many2one("sector.sector","Département",required=False)

    village_id = fields.Many2one("farmer.village","Village",required=False)

    date = fields.Char("Date Immatriculation",required=False)

    code_farmer = fields.Char(string='Code Planteur', required=False)



3-VIEWS FORM FARMER



<record id="plantation_res_partner_inherit" model="ir.ui.view">

            <field name="name">plantation.res.partner.inherit</field>

            <field name="model">res.partner</field>

            <field name="inherit_id" ref="base.view_partner_form"/>

            <field name="arch" type="xml">

                 <sheet>

                    <group>

                        <field name="farmer" invisible="1" string="Est un Planteur ?"/>

                       <field name="struct_id" required ="farmer == True"/>

            <field name="group_id" required="1"/>

            <field name="type_id" required = "farmer == True" options="{'no_create': True}"/>

                    </group>

                    <group>

                        <field name="myp_id" required = "farmer == True "/>

            <field name="number_aprocmac"/>

                         <field name="code_farmer"/>

<!--                        <field name="prime_id"/>-->

                    </group>

                </sheet>

<notebook position="inside">

                    <page string="Plantations">

                        <field name="plantation_ids">

​<list string="Plantations" editable="bottom">

​                                <field name="name" />

​                                <field name="village_id"  />

​                                <field name="frequency_id" />

​                                <field name="date" />

​                                <field name="area"/>

                            </list>

                        </field>

                    </page>

                </notebook>



            </field>

        </record>





4-ERROR


odoo.tools.convert.ParseError: while parsing file:/d:/odoo18/server/odoo/addons_bekoin/fond_de_tasse/views/partner.xml:14

Erreur lors de la validation de la vue :


                                <field name="currency_id" invisible="1"/>

                                <field name="total_invoiced" widget="monetary" options="{'currency_field': 'currency_id'}"/>

                            </span>

                            <span class="o_stat_text">Invoiced</span>

                        </div>


Le champ "village_id" n'existe pas dans le modèle "res.partner"


View error context:

{'file': 'd:\\odoo18\\server\\odoo\\addons_bekoin\\fond_de_tasse\\views\\partner.xml',

'line': 20,

'name': 'plantation.res.partner.inherit',

'view': ir.ui.view(2158,),

'view.model': 'res.partner',

'view.parent': ir.ui.view(126,),

'xmlid': 'plantation_res_partner_inherit'}



The above server error caused the following client error:

RPC_ERROR: Odoo Server Error

    RPC_ERROR

        at makeErrorFromResponse (http://localhost:8069/web/assets/6b047a9/web.assets_web.min.js:3148:163)

        at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/6b047a9/web.assets_web.min.js:3153:13)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You're seeing this error:


Le champ "village_id" n'existe pas dans le modèle "res.partner"


This means that Odoo is trying to validate the field village_id on the res.partner model, even though you meant it to refer to the plantation_ids One2many list, whose target model does include village_id.


Why It Worked in Odoo 17 but Fails in Odoo 18

In Odoo 18, there are stricter XML view validations. Specifically:


When you define <field name="plantation_ids"> and nest a <list>, Odoo expects the nested fields like village_id to exist only in the target model (plantation.plantation).


If Odoo mistakenly thinks the list content belongs to the parent model (res.partner), it will raise an error.


How to Fix It

Ensure your <field name="plantation_ids"> is a proper One2many with a nested list (not tree), and avoid indentation/formatting that may confuse the XML parser.


Update this part of your view like so:


xml

Copy

Edit

<field name="plantation_ids" mode="tree" context="{'default_partner_id': active_id}">

    <tree editable="bottom">

        <field name="name"/>

        <field name="village_id"/>

        <field name="frequency_id"/>

        <field name="date"/>

        <field name="area"/>

    </tree>

</field>

Or, if you want to use <list>, ensure Odoo 18 understands it as a valid container:


xml

Copy

Edit

<field name="plantation_ids">

    <tree string="Plantations" editable="bottom">

        <field name="name"/>

        <field name="village_id"/>

        <field name="frequency_id"/>

        <field name="date"/>

        <field name="area"/>

    </tree>

</field>


Do not use <list> directly — in standard Odoo XML views, use <tree> for list-style sub-record display.


If You Need Help Migrating More Code


I'd be happy to assist further or even help optimize your module for Odoo 18.


You can contact me directly at  – sagar@yalabs in at Yandtradhigham, we specialize in custom Odoo solutions and enterprise migrations.


Let me know if you also want a checklist for Odoo 18 migration, guidance on One2many field usage, or help setting up a developer debug environment for smoother error tracking.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 6 25
1651
0
thg 2 25
706
1
thg 11 24
1523
1
thg 11 24
888
0
thg 11 24
1230