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

this is a little from the code help me please :

i'm having a problem into my project odoo saying " No inverse field '' found for '_unknown' " this is my code :

    cas_social.xml
<?xml version="1.0" encoding="UTF-8"?>
 <odoo>
    <record model="ir.ui.view" id="cas_social_form_view">
        <field name="name">casocial.form</field>
        <field name="model">association.casocial</field>
        <field name="arch" type="xml">

            <form string="casocial form">
                <sheet>
                    <group string="informations sur le cas social">
                        <group>
                            <field name="name"/>
                            <field name="num_fichier"/>
                            <field name="fiche_date"/>
                            <field name="maj_date"/>
                        </group>
                        <group>
                            <field name="nom_prenom"/>
                            <field name="cin"/>
                            <field name="adresse_act"/>
                            <field name="num_tel"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="famille">

                            <field name="famille_ids" widget="many2many_kanban">
                                <kanban quick_create="false" create="true" delete="true">
                                    <field name="id"/>
                                    <field name="name"/>
                                    <templates>
                                        <t t-name="kanban-box">
                                            <div class="oe_kanban_global_click" style="position: relative">
                                                <a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>
                                                <div class="oe_module_vignette">
                                                    <img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_avatar oe_kanban_avatar_smallbox"/>
                                                    <div class="oe_module_desc">
                                                        <field name="name"/>
                                                    </div>
                                                </div>
                                            </div>
                                        </t>
                                    </templates>
                                </kanban>
                            </field>

                        </page>
                        <page string="Situation du logement">

                            <form string="logement form">
                                <sheet>
                                    <group string="situation du logement">

                                        <group>
                                            <field name="type_log" widget="many2many_tags"/>
                                            <field name="form_exploi" widget="many2many_tags"/>
                                            <field name="nbr_salle"/>

                                        </group>
                                        <group>
                                            <field name="struct_mais"/>
                                            <field name="cond_log" widget="many2many_checkboxes"/>
                                        </group>

                                    </group>
                                    <group string="meubles et installations de base">
                                        <field name="meuble" widget="many2many_checkboxes"/>

                                    </group>
                                    <group string="Propriété">
                                        <field name="moy_transport"/>
                                        <field name="immob_terrain"/>
                                    </group>

                                </sheet>
                            </form>
                        </page>
                        <page string="Budget de la famille">
                            <group string="revenu">
                                <group>
                                    <field name="revenu_ids">
                                        <tree string="les revenus de la famille" editable="bottom">
                                            <field name="name"/>
                                            <field name="fix"/>
                                            <field name="mont_mens"/>

                                        </tree>
                                    </field>
                                </group>
                            </group>
                            <group string="depenses">
                                <group>
                                    <field name="depenses_ids">
                                        <tree string="les depenses de la famille" editable="bottom">
                                            <field name="type_depense_id" widget="many2many-tags"/>
                                            <field name="mont_mens"/>

                                        </tree>
                                    </field>
                                </group>
                            </group>

                        </page>

                    </notebook>
                </sheet>
            </form>

        </field>
    </record>

    <!-- window action -->
    <!--
        The following tag is an action definition for a "window action",
        that is an action opening a view or a set of views
    -->
    <record model="ir.actions.act_window" id="cas_social_list_action">
        <field name="name">Cas social</field>
        <field name="res_model">association.casocial</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_smiling_face">
            </p>
        </field>
    </record>





    <!-- top level menu: no parent -->
    <menuitem id="main_association_menu" name="Association"/>
    <!-- A first level in the left side menu is needed
         before using action= attribute -->
    <menuitem id="association_menu" name="Association"
              parent="main_association_menu" sequence="2"/>
    <!-- the following menuitem should appear *after*
         its parent openacademy_menu and *after* its
         action course_list_action -->
    <menuitem id="cas_social_menu" name="cas social" parent="association_menu"
              action="cas_social_list_action"/>
    <!-- Full id location:
         action="openacademy.course_list_action"
         It is not required when it is the same module -->
    <record model="ir.ui.view" id="revenu_form_view">
        <field name="name">revenu.form</field>
        <field name="model">casocial.revenu</field>
        <field name="arch" type="xml">
            <form string="Revenu Form">
                <sheet>
                    <group>
                        <field name="name"/>
                        <field name="fix"/>
                        <field name="mont_mens"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="revenu_tree_view">
        <field name="name">revenu.tree</field>
        <field name="model">casocial.revenu</field>
        <field name="arch" type="xml">
            <tree string="Revenu Form" create="true">


                <field name="name"/>
                <field name="fix"/>
                <field name="mont_mens"/>


            </tree>
        </field>
    </record>

        <record model="ir.ui.view" id="depense_form_view">
        <field name="name">depense.form</field>
        <field name="model">casocial.depenses</field>
        <field name="arch" type="xml">
            <form string="depense Form">
                <sheet>
                    <group>
                        <field name="type_depenses" widget="many2one_tags" />
                        <field name="mont_mens"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="depense_tree_view">
        <field name="name">depense.tree</field>
        <field name="model">casocial.depenses</field>
        <field name="arch" type="xml">
            <tree string="depense Form" create="true">


                <field name="type_depenses"/>
                <field name="mont_mens"/>


            </tree>
        </field>
    </record>




</odoo>


models.py:

    from odoo import models, fields, api


class association(models.Model):
   _name = 'association.association'

   name = fields.Char()


class casocial(models.Model):
   _name = 'association.casocial'
   _description = "cas social"
   name = fields.Char(string="cas social", required=True)
   num_fichier = fields.Char(string="numéro dus fichier", required=True)
   fiche_date = fields.Date(string="La date d'ouverture du fichier")
   maj_date = fields.Date(string="La date de mise à jour du fichier")
   nom_prenom = fields.Char(string="nom et prenom" , required=True)
   cin = fields.Char(string="numéro carte d'identité", required="True")
   adresse_act = fields.Char(string="adresse actuelle",required="True")
   num_tel=fields.Char(string="numéro de téléphone",required="True")
   famille_ids = fields.Many2many(comodel_name="res.partner", string="membres de la famille")
   type_log = fields.Many2one(comodel_name="casocial.typelog", string="type de logement")
   form_exploi = fields.Many2many(comodel_name="casocial.frmexploi", string="forme d'exploitation du logement")
   nbr_salle = fields.Integer(string="nombre de salles", required=True)
   surface = fields.Integer(string="surface", required=True)
   struct_mais = fields.Selection(string="structure de la maison", selection=[('terminé', 'terminé'), ('pas encore', 'pas encore'), ], required=True)
   cond_log = fields.Many2many(comodel_name="casocial.condlog", string="condition de logement")
   meuble = fields.Many2many(comodel_name="casocial.meuble", string="meubles et installations de base")
   moy_transport = fields.Char(string="moyen de transport", required=False)
   immob_terrain = fields.Char(string="Immobilier et terrains", required=False)
   revenu_ids = fields.One2many(comodel_name="casocial.revenu", inverse_name="casocial_id", string="les revenus", required=False)
   depenses_ids = fields.One2many('casocial.depenses','casocial_id', string="les depenses", required=False)

class Revenu(models.Model):
   _name = 'casocial.revenu'
   _description = "Cas social revenu"
   name = fields.Char(string="source", required=False)
   fix = fields.Selection(string="fixe ou non", selection=[('fixe', 'fixe'), ('non fixe', 'non fixe'), ], required=False)
   mont_mens = fields.Integer(string="montant mensuel", required=False)
   casocial_id = fields.Many2one(comodel_name="association.casocial", string="cas social", required=False)


class depense(models.Model):
   _name = 'casocial.depenses'
   _description = "Cas social depense"
   mont_mens = fields.Integer(string="montant mensuel", required=False)
   type_depense_id = fields.Many2many(comodel_name="casocial.typedepenses", string="type depense")
   casocial_id = fields.Many2one('association.casocial',ondelete='cascade', string="cas social", required=False)

class type_depense(models.Model):
    _name = 'casocial.typedepenses'
    _rec_name = "type_depense"
    type_depense = fields.Char(string="type de depense", required=False)


Avatar
Discard
Best Answer

Hi,

The error can be solved by adding a One2Many field in "type_depense" because as you have added a Many2One field in model "depense" you need to add an inverse field for it.

Regards

Avatar
Discard