Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

How to return a tree view from a python function

Subscribe

Get notified when there's activity on this post

This question has been flagged
10 Replies
23140 Views
Avatar
MIADI

Hello, I asked on this forum how to put 2 actions for 1 menuitem but someone answers that I don't need to put 2 actions for 1 menuitem but I've to return the tree view in my python function which is called in my action server in my XML file.


This is my python code :

class miadi_poidsConditionnement(models.Model):

    _name = 'miadi.poidsconditionnement'

    # _order = 'conditionnement_id asc'

    conditionnement_id = fields.Many2one('miadi.packaging', 'Packaging', default='', required=True)

    produit_id = fields.Many2one('product.product', 'Product', default='', required=True)

    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

    @api.model

    def chargement_ratio(self):

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

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

        query_cond = self.env.cr.dictfetchall()

        produits = self._cr.execute("SELECT id FROM product_product")

        query_prod = self.env.cr.dictfetchall()

        for conditionnements in query_cond:

            nom_conditionnement = conditionnements['id']

            for produits in query_prod:

                product = produits['id']

                if_exist = self._cr.execute("SELECT * FROM miadi_poidsConditionnement WHERE conditionnement_id=%s AND produit_id=%s", (nom_conditionnement, product))

                if not if_exist:

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

                    return {'type': 'ir.actions.act_window', 'view_type': 'tree', 'view_mode': 'tree', 'res_model': 'miadi.poidsconditionnement', 'res_id': miadi.poidsconditionnement.id, 'view_id': self.env.ref('action_miadi_poidsConditionnement').id, 'target': 'current',}


And this is my 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" widget="selection" eval="ref('product.product.attribute_value_ids')" />

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

      <field name="conditionnement_id" widget="selection" eval="ref('miadi.packaging.conditionnement_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="conditionnement_id" ref="miadi.packaging.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="res_model">action_miadi_poidsConditionnement</field>

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

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

   <field name="code">chargementRatio = env['miadi.poidsconditionnement'].browse(context.get('active_id'));chargementRatio.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" action="action_chargement_ratio" />

 </data>

</openerp>


And it gives me an issue :

ValueError: <type 'exceptions.NameError'>: "global name 'miadi' is not defined" while evaluating
u"chargementRatio = env['miadi.poidsconditionnement'].browse(context.get('active_id'));chargementRatio.chargement_ratio()"


I want to return the tree view (action_miadi_packaging) and I want my python function is called when I click on the menuitem

How can I resolve this issue ?


And if I write "'res_id': productRatio.id" (where productRatio = self.env['miadi.poidsconditionnement']), instead of "'res_id': miadi.poidsconditionnement.id" the error is :

ValueError: <type 'exceptions.ValueError'>: "need more than 1 value to unpack" while evaluating
u"chargementRatio = env['miadi.poidsconditionnement'].browse(context.get('active_id'));chargementRatio.chargement_ratio()"

Thanks for answers


PS : I'm on Odoo 10

0
Avatar
Discard
Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi Miadi,

You can return a view from python code like this, you have to mention the correct view id

return {
'name': _('test'),
'view_type': 'tree',
'view_mode': 'tree',
'view_id': self.env.ref('account.invoice_tree').id,
'res_model': 'account.invoice',
'context': "{'type':'out_invoice'}",
'type': 'ir.actions.act_window',
'target': 'new',
}
2
Avatar
Discard
MIADI
Author

Hi Niyas,

my view_id is correct (if you look my XML code and my Python code, you can see that the view id is correct

MIADI
Author

I update my code with your answer and it's works, my tree view is display BUT, what I put in my code before the return doesn't happen...

MIADI
Author

No, finally it doesn't works, it gives me this issue : ValueError: <type 'exceptions.NameError'>: "global name '_' is not defined" while evaluating

u"chargementRatio = env['miadi.poidsconditionnement'];chargementRatio.chargement_ratio()"

MIADI
Author

and if I remove 'name': _('test'), the view is not display

MIADI
Author

I wrote this :

return {

'name': _('test'),

'view_type': 'tree',

'view_mode': 'tree',

'view_id': self.env.ref('miadi_packaging.miadi_poidsConditionnement_tree').id,

'res_model': 'miadi.poidsconditionnement',

'type': 'ir.actions.act_window',

'target': 'new',

}

It should work no ?

MIADI
Author

In the action of the menuitem, I've to put the server action id no ?

If yes, it should work but my tree view is not display...

Can you help me ?

MIADI
Author

Looking at my codes, can you tell me if my view_id is good ? Because nothing happens when I click on the menu

MIADI
Author

I fix the problem, the error was in my XLM code

But the result is not really that I want...

When I click on the menuitem, I have a popup^with the tree view but I can't modify the records and what I really want is to have a tree view but not in a popup, I want a "normal" tree view

Niyas Raphy (Walnut Software Solutions)

Hai Miadi, A simplecorrection , not XLM code its XML code

Aslam Up

Hi Niyas,

Can we return this view by some grouping ( A grouped view by state/year/salesperson) ??

joyanto

thanks its work

Avatar
MIADI
Author Best Answer

Hi,

It works and I have a treeview but it's not the tree view that I want because I've a tree view in a popup (and I can't chage any record) and what I want is a "normal" tree view

What I have : https://www.hostingpics.net/viewer.php?id=358419Capturetreeview.png


What I want : https://www.hostingpics.net/viewer.php?id=947270Capturetreeview2.png


Or I want to be able to modify some fields in this popup treeview. Is it possible ? If yes, how can I do it ?


If someone can help me, it will be very good

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now