Skip to content

Commit

Permalink
import data from excel with xlrd ___init___
Browse files Browse the repository at this point in the history
  • Loading branch information
Boubaker AB authored and Boubaker AB committed Aug 18, 2019
1 parent a1eef1f commit 83922c1
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gest_call/views/lesson_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
</form>
</field>
</record>


<record id="action_gestcal_calendar_view" model="ir.ui.view">
<field name="name">gestcal.lesson.calendar</field>
<field name="model">gestcal.lesson</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<calendar string="Lessons" date_start="date" event_open_popup="true" event_limit="5" color="course_id">
<field name="date"/>
<field name="course_id"/>
</calendar>
</field>
</record>

<!-- Tree View Of lesson Information -->
<record id="view_gestcal_lesson_tree" model="ir.ui.view">
<field name="name">gestcal.lesson.tree</field>
Expand All @@ -55,7 +69,7 @@
<field name="name">Lesson</field>
<field name="res_model">gestcal.lesson</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">calendar,tree,form</field>
</record>
</odoo>

3 changes: 3 additions & 0 deletions gestcall_import_data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
28 changes: 28 additions & 0 deletions gestcall_import_data/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
{
'name' : 'Gestcall Import Data',
'version' : '1.12.0',
'summary': 'Gestcall Import Data',
'description': """
This module allows you to import data from excel file .
""",
'category': 'Management',
'author': 'Boubaker Abdallah',
'website': '',
'images' : [],
'depends' : ['web','base','mail'],
'css':[ ],

'data': [
'security/ir.model.access.csv',
'views/import_data_view.xml',

],
'demo': [
],
'qweb': [],
'installable': True,
'application': True,
'auto_install': False,
}
3 changes: 3 additions & 0 deletions gestcall_import_data/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import import_data

89 changes: 89 additions & 0 deletions gestcall_import_data/models/import_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
import sys
import re
import datetime
import base64
from odoo import api, fields, models, _
from tempfile import TemporaryFile
import csv
import time
import functools
from xmlrpc import client
import openpyxl
import os
import xlrd
import fnmatch
import subprocess
import logging
import math
from docutils.nodes import address
logger=logging.getLogger('_______Boubaker____________')


class IMPORTDATA(models.Model):

AVAILABLE_STATES = [
('draft', 'Draft'),
('failure', 'Failure'),
('done', 'Done'),
]

_name = 'import.import'
_inherit = ['mail.thread']
_description = 'Import Data'
_order = 'id desc'

name = fields.Char('Nom de la pièce jointe')
description = fields.Text('Description de fichier')
data = fields.Binary('Fichier', required=True)
type = fields.Selection([('lesson', 'lesson'), ('partner', 'Partner')], 'Type', required=True)
filename = fields.Char('Nom fichier')
state = fields.Selection(AVAILABLE_STATES, 'Etat', readonly=True, default='draft')
path = fields.Char('Path', default='F:/')


@api.multi
def import_lesson_data(self):
lesson_obj = self.env['gestcal.lesson']
partner_obj = self.env['res.partner']
dest_filename = self.path + self.filename
workbook = xlrd.open_workbook(dest_filename)
for sheet in workbook.sheets():
cols = sheet.row_values(0)
lesson_date = cols.index(u'date')
start_date = cols.index(u'start')
end_date = cols.index(u'end')
for rowx in range(0,sheet.nrows):
rowx += 1
len_nr = len(range(sheet.nrows))
logger.info("_len_nr______________: %s ",len_nr)
if rowx < len_nr:
cols = sheet.row_values(rowx)
lesson_date_obj = cols[lesson_date] or ''
start_obj = cols[start_date] or ''
end_obj = cols[end_date] or ''
d0 = datetime.date(1900, 1, 1)
delta = datetime.timedelta(days=(lesson_date_obj -2))
date_lesson = d0 + delta
logger.info("_date_lesson______________: %s ",date_lesson)

if date_lesson:
lesson_id = lesson_obj.search([('date', '=', date_lesson)])
logger.info("_lesson_id______________: %s ",lesson_id)

if not lesson_id:
lesson_vals={
'date': date_lesson,
'start_time': start_obj * 24,
'end_time': end_obj * 24,
'teacher_id': 7,
}
logger.info("_lesson_vals______________: %s ",lesson_vals)
lesson_id = lesson_obj.create(lesson_vals)

self.write({'state':'done'})
return True




3 changes: 3 additions & 0 deletions gestcall_import_data/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink

access_maarefa_program_public,maarefa_program_public,model_import_import,,1,1,1,1
Binary file added gestcall_import_data/static/src/img/import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions gestcall_import_data/views/import_data_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="import_import_tree">
<field name="name">import.data.tree.view</field>
<field name="model">import.import</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Import Data">
<field name="name" string="Nom de l'import"/>
<!-- <field name="data" /> -->
<field name="state"/>
</tree>
</field>
</record>

<record model="ir.ui.view" id="import_import_form">
<field name="name">import.data.form.view</field>
<field name="model">import.import</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Import Data">
<header>
<button name="import_employee_data" string="Import Employee Data" type="object"
attrs="{'invisible': ['|',('state', '=', 'done'),('type', '!=', 'employee')]}" class="oe_highlight" />

<button name="import_lesson_data" string="Import Department Data" type="object"
class="oe_highlight" />
<!-- <button name="import_employee_data" string="Import Employee Data" type="object"
attrs="{'invisible': ['|',('state', '=', 'done'),('type', '!=', 'employee')]}" class="oe_highlight" /> -->
<field name="state" widget="statusbar" statusbar_visible="draft,failure,done" />
</header>
<sheet>

<div class="oe_title">
<h1>
Import Data
</h1>
</div>

<group>
<group>
<field name="name" required="1" string="Nom de l'import"/>
<field name="type"/>
<field name="filename"/>
<field name="data" filename="filename"/>
<field name="path"/>

</group>
</group>

<field name="description" placeholder="Infos about files" nolabel="1" />
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" />
<field name="message_ids" widget="mail_thread" />
</div>
</form>
</field>
</record>




<record id="action_import_import" model="ir.actions.act_window">
<field name="name">Import Data</field>
<field name="res_model">import.import</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Import Data
</p>
</field>
</record>


<menuitem name="Import Data" id="menu_import_data_maahed"/>
<menuitem action="action_import_import" id="menu_import_data" string="Import Data" parent="menu_import_data_maahed" />






</data>
</odoo>

0 comments on commit 83922c1

Please sign in to comment.