Skip to Content
Menu
This question has been flagged
3 Replies
3935 Views

Hello

I try to execute a python code (function chargement_ratio(self)) when I click on a menuitem that I've created (Weight/Number Ratio) but it's gives me this error : ParseError:
"External ID not found in the system: miadi_packaging.miadi_poidsConditionnement" while parsing file:///C:/Program Files (x86)/Odoo 10.0/server/odoo/addons/miadi_packaging/views/miadi_poidsConditionnement_view.xml:62, near

<record id="action_chargement_ratio" model="ir.actions.server">
			<field name="name">Chargement Ratio</field>
                        <field name="type">ir.actions.server</field> <field name="model_id" ref="miadi_poidsConditionnement"/>
                        <field name="code">action = self.chargement_ratio()</field> </record>


There is my miadi_poidsConditionnement.py :

import odoo from odoo import models, fields, tools, api

class miadi_poidsConditionnement(models.Model):

    _name = 'miadi.poidsconditionnement' 

    conditionnement_id = fields.Char('Packaging', size=4, default='', required=True) 

    produit_id = fields.Char('Product', size=256, default='')

    nb_articles = fields.Integer(string='Number of products', default=0)

    poids = fields.Float(string='Packaging Weight', default=0)

    _sql_constraints = [

        ('uniq_id', 'unique(produit_id, conditionnement_id)', 'A product already exists with this packaging !'),


     @api.multi

    def chargement_ratio(self):

            conditionnements = self._cr.execute("SELECT conditionnement_id FROM miadi_packaging")

            productRatio = self.env['miadi.poidsconditionnement']

            products = self.env['product.product'].search([])

            for conditionnements in self.env.cr.dictfetchall():

                    nom_conditionnement = conditionnements['name']

                    for rec in products:

                            product = rec.display_name

                            productRatio.create({'conditionnement_id': nom_conditionnement, 'produit_id': product})


And my XML file where are the views of the menuitem on which I want to do the action (miadi_poidsConditionnement_view.xml) :

<?xml version="1.0" encoding="utf-8"?>

<openerp>

 <data>

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

   <field name="name">miadi.poidsconditionnement.form</field>

   <field name="model">miadi.poidsconditionnement</field>

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

    <form string="Weight/number ratio">

     <group col="4"> 

      <field name="produit_id" /> 

      <field name="conditionnement_id" />

      <field name="nb_articles" />

      <field name="poids" />

     </group>

    </form>

   </field>

  </record>

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

   <field name="name">miadi.poidsconditionnement.tree</field>

   <field name="model">miadi.poidsconditionnement</field>

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

    <tree string="Weight/number ratio">

     <!-- <field name="produit_id" ref="product.product.attribute_value_ids" /> -->

     <field name="produit_id" />

     <!-- <field name="conditionnement_id" ref="miadi.packaging.conditionnement_id" /> -->

     <field name="conditionnement_id" />

     <field name="nb_articles" />

     <field name="poids" />

    </tree>

   </field>

  </record>

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

   <field name="name">miadi.poidsconditionnement.search</field>

   <field name="model">miadi.poidsconditionnement</field>

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

    <search string="Weight/number ratio">

     <field name="produit_id" />

     <group expand="0" string="Group by">

      <filter string="Product" domain="[]" context="{'group_by':'produit_id'}"/>

      <filter string="Packaging" domain="[]" context="{'group_by':'conditionnement_id'}"/>

     </group>

    </search>

   </field>

  </record>

  <record model="ir.actions.act_window" id="action_miadi_poidsConditionnement">

   <field name="name">Weight/number ratio</field>

   <field name="type">ir.actions.act_window</field>

   <field name="res_model">miadi.poidsconditionnement</field>

   <field name="view_type">form</field>

   <field name="view_mode">tree,form</field>

   <field name="view_id" ref="miadi_poidsConditionnement_tree"/>

   <field name="help" type="html">

    <p class="oe_view_nocontent_create">Click here to create a weight/number ratio.</p>

   </field>

  </record>

  <record id="action_chargement_ratio" model="ir.actions.server">

   <field name="name">Chargement Ratio</field>

   <field name="type">ir.actions.server</field>

   <field name="model_id" ref="model_miadi_poidsConditionnement" /> 

   <field name="code">action = self.chargement_ratio()</field>

  </record>

  <menuitem name="Weight/number ratio" id="menu_miadi_poidsConditionnement" parent="menu_miadi_packaging" sequence="15" groups="sales_team.group_sale_manager" />

  <menuitem id="menu_action_miadi_poidsConditionnement" parent="menu_miadi_packaging" action="action_miadi_poidsConditionnement" />

<menuitem id="menu_action_chargement_ratio" parent="menu_miadi_poidsConditionnement" action="action_chargement_ratio" />

 </data>

</openerp>


Organization of my module :

- miadi_packaging

         - i18n

         - models

                 - __init__.py

                 - miadi_packaging.py (class miadi_packaging)

                 - miadi_poidsConditionnement.py (class miadi_poidsConditionnement)

         - views

                 - miadi_packaging_view.xml

                 - miadi_poidsConditionnement_view.xml

         - __init__.py

         - __manifest__.py



I hope someone will found the solution because I'm on this error since yesterday

Thanks

Avatar
Discard

in your question it is said that the problem is in this line "<field name="model_id" ref="miadi_poidsConditionnement"/>"

but it is not available in the code you given

Author

Hi,

Yes it is : class miadi_poidsConditionnement(models.Model)

So, I don't understand why I have this issue

Best Answer

Try with this 

<field name="model_id" ref="miadi_packaging.model_miadi_poidsconditionnement"/>
Avatar
Discard
Author

It's the same error : External ID not found in the system: miadi_packaging.model_miadi_poidsConditionnement

No man....Its : <field name="model_id" ref="miadi_packaging.model_miadi_poidsconditionnement"/>

all in small case as your model name

Author

Oh thanks, it works but now I've another error :

ValueError: <type 'exceptions.NameError'>: "name 'self' is not defined" while evaluating

u'action = self.chargement_ratio()'

can you please mention odoo version?

Author

Odoo 10

Try to call method with "records":

<field name="code">action = records.chargement_ratio()</field>

Author

Another issue :

ValueError: <type 'exceptions.AttributeError'>: "'NoneType' object has no attribute 'chargement_ratio'" while evaluating

u'action = records.chargement_ratio()'