-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
import data from excel with xlrd ___init___
- Loading branch information
Boubaker AB
authored and
Boubaker AB
committed
Aug 18, 2019
1 parent
a1eef1f
commit 83922c1
Showing
8 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import import_data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|