Odoo Help

Welcome!

This community 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.

0

Run automatically a fonction during a load of a view

By
jabal
on 5/27/16, 8:27 AM 239 views

this is  the  fonction :

    @api.one

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()

conn_stat.commit()

# 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"]))

con_odoo.commit()

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">

<group>

<group>

<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"/>

</group>

</group>

</form>

</field>

</record>

This is an english forum, please use english language.

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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