Hello,
In a module that I've created, I want to call a python function and after, I want to display the tree view of the table.
More explanations : When I click on "Weight/number Ratio" menuitem, I want to call the chargement_ratio function and I want to display the tree view after that (returning the tree view). But, in my case, nothing happens. (See python and XML codes below)
Python :
class miadi_poidsConditionnement(models.Model):
_name = 'miadi.poidsconditionnement'
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))
exist = self.env.cr.dictfetchall()
if not exist:
Ratio = productRatio.create({'conditionnement_id': nom_conditionnement, 'produit_id': product})
return {'type': 'ir.actions.act_window', 'view_type': 'tree', 'view_mode': 'tree,form', 'res_model': 'miadi.poidsconditionnement', 'res_id': productRatio.id, 'view_id': self.env.ref('miadi_packaging.miadi_poidsConditionnement_tree').id, 'target': 'current'}
XML :
<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.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'];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" />
But when I make this and I click on "Weight/number Ratio" menuitem, nothing happens.
Why and how can I resolve this problem ?
PS : I'm on Odoo 10