Odoo Help


Run automatically a fonction during a load of a view

on 5/27/16, 8:27 AM 538 views

this is  the  fonction :


def importation_automatique(self):

# connexion avec la base statagris

conn_stat = psycopg2.connect(database="db_statagris", user="openpg", password="openpgpwd", host="localhost", port="5432")

print ("Opened database statistic1 successfully")

cursor = conn_stat.cursor(cursor_factory=psycopg2.extras.DictCursor)

cursor.execute("SELECT * FROM statistic")

rows = cursor.fetchall()


# connexion avec la base odoo

con_odoo = psycopg2.connect(database="frma", user="openpg", password="openpgpwd", host="localhost", port="5432")

curr_stat = con_odoo.cursor()

print ("Opened database odoo successfully")

#fout = open('tempo', 'w')

#cur.copy_to(fout, 'tempo', sep="|")

#print ("file created successfully")

curr_stat.execute("TRUNCATE TABLE ml_stat ")

for row in rows:

curr_stat.execute("""insert into ml_stat values (%s,%s,%s,%s)""",( row["unid"],"2016-05-13 15:15:20.264",row["occurrence"], row["variante2_valeur"]))

print( '%s' % ( row["unid"]))


and here's the form I want the data to be loaded:

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

<field name="name">ml.stat.form</field>

<field name="model">ml.stat</field>

<field name="priority">4</field>

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

<form string="Plan Maroc vert stat">



<field name="annee_reference"/>

<field name="periodicite"/>

<field name="occurrence"/>

<field name="sous_region_type"/>

<field name="region_name"/>

<field name="province_name"/>

<field name="sous_region_name"/>

<field name="zone_name"/>

</group> <group>

<field name="produit_name"/>

<field name="variante1_name"/>

<field name="variante1_valeur"/>

<field name="variante2_name"/>

<field name="variante2_valeur"/>

<field name="variante3_name"/>

<field name="variante3_valeur"/>

<field name="indicateur_name"/>

<field name="valeur"/>






This is an english forum, please use english language.

Ermin Trevisan
on 5/28/16, 4:41 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/27/16, 8:27 AM
Seen: 538 times
Last updated: 5/29/16, 5:49 PM