1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# ShineERP, Enterprise Management Solution
5
# Copyright (C) 2007-2013 ShineERP Co.,ltd (<http://www.erp.mn>). All Rights Reserved
7
# Address : Suhkbaatar District, National ITPark, ShineERP LLC
9
# Phone : 976 + 11-318043
11
##############################################################################
13
from osv import osv,fields,orm
14
from tools.translate import _
16
import netsvc, decimal, base64, os, time, xlrd
17
from tempfile import NamedTemporaryFile
19
class product_data_initial(osv.osv_memory):
20
_name = 'product.data.initial'
21
_description = 'Product Data Initial'
24
'data': fields.binary('Product Data File', required=True)
27
def import_data(self, cr, uid, ids, context={}):
28
product_obj = self.pool.get('product.product')
29
product_tmpl_obj = self.pool.get('product.template')
30
product_category_obj = self.pool.get('product.category')
31
product_uom_obj = self.pool.get('product.uom')
33
product_uoms = {u'ш':'Unit(s)'}
35
form = self.browse(cr, uid, ids[0])
37
fileobj = NamedTemporaryFile('w+')
38
fileobj.write(base64.decodestring(form.data))
41
if not os.path.isfile(fileobj.name):
42
raise osv.except_osv(u'Алдаа',u'Мэдээллийн файлыг уншихад алдаа гарлаа.\nЗөв файл эсэхийг шалгаад дахин оролдоно уу!')
43
book = xlrd.open_workbook(fileobj.name)
45
sheet = book.sheet_by_index(0)
53
product_name = row[0].value
54
product_category = u'' + row[1].value
55
product_cost = row[2].value
56
product_uom = row[3].value
57
product_type = row[4].value
58
product_supply_method = row[5].value
59
product_procure_method = row[6].value
60
product_sale_ok = row[7].value
61
product_purchase_ok = row[8].value
62
product_cost_method = row[9].value
64
category_id = product_category_obj.search(cr, uid, [('name', '=', product_category)], limit=1)
65
if len(category_id) ==0:
66
raise osv.except_osv('Error', 'Category does not exist! %s ' % product_category)
67
product_uom_id = product_uom_obj.search(cr, uid, [('name', '=', product_uoms[product_uom] if product_uoms.has_key(product_uom) else '')], limit=1)
68
if len(product_uom_id) ==0:
69
raise osv.except_osv('Error', 'Product uom does not exist! %s ' % product_uom)
71
product_tmpl_id = product_tmpl_obj.create(cr, uid, {
73
'categ_id': category_id[0],
74
'standard_price': product_cost,
75
'uom_id': product_uom_id[0],
77
'supply_method': product_supply_method,
78
'procure_method': product_procure_method,
79
'purchase_ok': product_sale_ok,
80
'sale_ok': product_purchase_ok,
81
'cost_method': product_cost_method,
84
print 'created product_tmpl_id: ' + str(product_tmpl_id)
85
product_id = product_obj.create(cr, uid, {
86
'product_tmpl_id': product_tmpl_id,
88
'valuation': 'manual_periodic',
90
print 'created product_id: ' + str(product_id)
94
raise osv.except_osv('Error', 'Excel sheet must be 10 columned : error on row %s ' % rowi)
96
product_data_initial()
b'\\ No newline at end of file'