Merge lp:~luigi.grilli/openobject-addons/product_metel into lp:~openerp-community/openobject-addons/trunk-addons-community

Proposed by Luigi Grilli
Status: Needs review
Proposed branch: lp:~luigi.grilli/openobject-addons/product_metel
Merge into: lp:~openerp-community/openobject-addons/trunk-addons-community
Diff against target: 959 lines (+898/-0)
11 files modified
product_metel/__init__.py (+35/-0)
product_metel/__terp__.py (+45/-0)
product_metel/i18n/it_IT.po (+148/-0)
product_metel/i18n/product_metel.pot (+148/-0)
product_metel/metel.py (+50/-0)
product_metel/metel_view.xml (+20/-0)
product_metel/metel_wizard.xml (+17/-0)
product_metel/test/metel-test.py (+58/-0)
product_metel/wizard/__init__.py (+28/-0)
product_metel/wizard/metel_import.py (+244/-0)
product_metel/wizard/wizard_metel_import.py (+105/-0)
To merge this branch: bzr merge lp:~luigi.grilli/openobject-addons/product_metel
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+19266@code.launchpad.net

Commit message

Merging product_metel module

To post a comment you must log in.
Revision history for this message
Luigi Grilli (luigi.grilli) wrote :

Metel pricelists import module

Unmerged revisions

1. By Luigi Grilli

Initial import

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'product_metel'
=== added file 'product_metel/__init__.py'
--- product_metel/__init__.py 1970-01-01 00:00:00 +0000
+++ product_metel/__init__.py 2010-02-13 11:58:12 +0000
@@ -0,0 +1,35 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Copyright (c) 2009 Luigi Grilli (luigi.grilli at gmail.com)
5# All Rights Reserved.
6#
7# WARNING: This program as such is intended to be used by professional
8# programmers who take the whole responsability of assessing all potential
9# consequences resulting from its eventual inadequacies and bugs
10# End users who are looking for a ready-to-use solution with commercial
11# garantees and support are strongly adviced to contract a Free Software
12# Service Company
13#
14# This program is Free Software; you can redistribute it and/or
15# modify it under the terms of the GNU General Public License
16# as published by the Free Software Foundation; either version 2
17# of the License, or (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27#
28##############################################################################
29# I used the code of account_bankimport as base for this module.
30#
31# This module can import metel formatted files (see www.metel.it)
32#
33
34import wizard
35import metel
036
=== added file 'product_metel/__terp__.py'
--- product_metel/__terp__.py 1970-01-01 00:00:00 +0000
+++ product_metel/__terp__.py 2010-02-13 11:58:12 +0000
@@ -0,0 +1,45 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Copyright (c) 2009 Luigi Grilli (luigi.grilli at gmail.com)
5# All Rights Reserved.
6#
7# WARNING: This program as such is intended to be used by professional
8# programmers who take the whole responsability of assessing all potential
9# consequences resulting from its eventual inadequacies and bugs
10# End users who are looking for a ready-to-use solution with commercial
11# garantees and support are strongly adviced to contract a Free Software
12# Service Company
13#
14# This program is Free Software; you can redistribute it and/or
15# modify it under the terms of the GNU General Public License
16# as published by the Free Software Foundation; either version 2
17# of the License, or (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27#
28##############################################################################
29# I used the code of account_bankimport as base for this module.
30#
31# This module can import metel formatted files (see www.metel.it)
32#
33
34{
35 "name":"Metel Listprice Import/Export",
36 "version":"0.0.1",
37 "author":"Luigi Grilli",
38 "category":"Generic Modules/Others",
39 "description":"Import and export Metel formatted pricelist",
40 "depends":["base", "product_electronic"],
41 "init_xml":[],
42 "update_xml" : ["metel_view.xml", "metel_wizard.xml"],
43 "active":False,
44 "installable":True,
45}
046
=== added directory 'product_metel/i18n'
=== added file 'product_metel/i18n/it_IT.po'
--- product_metel/i18n/it_IT.po 1970-01-01 00:00:00 +0000
+++ product_metel/i18n/it_IT.po 2010-02-13 11:58:12 +0000
@@ -0,0 +1,148 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * product_metel
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 5.0.6\n"
8"Report-Msgid-Bugs-To: support@openerp.com\n"
9"POT-Creation-Date: 2010-02-13 08:49:31+0000\n"
10"PO-Revision-Date: 2010-02-13 08:49:31+0000\n"
11"Last-Translator: <>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: \n"
16"Plural-Forms: \n"
17
18#. module: product_metel
19#: model:ir.module.module,description:product_metel.module_meta_information
20msgid "Import and export Metel formatted pricelist"
21msgstr "Importa ed esporta Listini Metel"
22
23#. module: product_metel
24#: wizard_button:metel.pricelist,import,end:0
25msgid "End"
26msgstr "Fine"
27
28#. module: product_metel
29#: view:res.partner:0
30msgid "Sales & Purchases"
31msgstr ""
32
33#. module: product_metel
34#: constraint:ir.model:0
35msgid "The Object name must start with x_ and not contain any special character !"
36msgstr ""
37
38#. module: product_metel
39#: wizard_view:metel.pricelist,init:0
40msgid "Please select metel pricelist file to import."
41msgstr "Selezionare il file del listino da importare"
42
43#. module: product_metel
44#: field:res.partner,metel_category:0
45msgid "Import Category"
46msgstr "Categoria importazione"
47
48#. module: product_metel
49#: code:addons\product_metel\wizard\metel_import.py:0
50#, python-format
51msgid "Metel Import Completed"
52msgstr "Importazione Metel completata"
53
54#. module: product_metel
55#: code:addons\product_metel\wizard\wizard_metel_import.py:0
56#, python-format
57msgid "Error: could not find a partner with this metel code: %s"
58msgstr "Errore: impossibile trovare un partner con questo codice metel: %s"
59
60#. module: product_metel
61#: wizard_field:metel.pricelist,import,uo_message:0
62msgid "Status"
63msgstr "Stato"
64
65#. module: product_metel
66#: code:addons\product_metel\wizard\wizard_metel_import.py:0
67#, python-format
68msgid "Error: no import category defined for the partner."
69msgstr "Errore: non è stata specificata una categoria per il partner."
70
71#. module: product_metel
72#: code:addons\product_metel\wizard\wizard_metel_import.py:0
73#, python-format
74msgid "Import operation in progress"
75msgstr "Importazione dei dati in corso"
76
77#. module: product_metel
78#: model:ir.model,name:product_metel.model_product_metel_fileimport
79msgid "product.metel.fileimport"
80msgstr ""
81
82#. module: product_metel
83#: model:ir.ui.menu,name:product_metel.menu_metel_import_action
84msgid "Import Metel Pricelist file"
85msgstr "Importa listino Metel"
86
87#. module: product_metel
88#: wizard_button:metel.pricelist,init,import:0
89msgid "Import pricelist"
90msgstr "Importa listino"
91
92#. module: product_metel
93#: field:res.partner,metel_code:0
94msgid "Metel Code"
95msgstr "Codice Metel"
96
97#. module: product_metel
98#: wizard_field:metel.pricelist,init,metel_file:0
99msgid "Metel pricelist file"
100msgstr "File del listino Metel"
101
102#. module: product_metel
103#: constraint:ir.ui.view:0
104msgid "Invalid XML for View Architecture!"
105msgstr ""
106
107#. module: product_metel
108#: model:ir.actions.wizard,name:product_metel.wizard_metel_pricelist
109msgid "Import Metel pricelist file"
110msgstr "Importa file listino Metel"
111
112#. module: product_metel
113#: field:product.metel.fileimport,tmpfilename:0
114msgid "File Metel"
115msgstr "File Metel"
116
117#. module: product_metel
118#: model:ir.module.module,shortdesc:product_metel.module_meta_information
119msgid "Metel Listprice Import/Export"
120msgstr "Importazione/Esportazione Listini Metel"
121
122#. module: product_metel
123#: view:res.partner:0
124msgid "Metel Properties"
125msgstr "Proprietà Metel"
126
127#. module: product_metel
128#: code:addons\product_metel\wizard\metel_import.py:0
129#, python-format
130msgid "Imported products: %d \nUpdated products: %d"
131msgstr "Nuovi prodotti importati: %d\Prodotti aggiornati: %d"
132
133#. module: product_metel
134#: wizard_view:metel.pricelist,import:0
135msgid "Metel pricelist import report"
136msgstr "Rapporto di importazione file Metel"
137
138#. module: product_metel
139#: wizard_button:metel.pricelist,init,end:0
140msgid "Cancel"
141msgstr "Annulla"
142
143#. module: product_metel
144#: wizard_view:metel.pricelist,import:0
145#: wizard_view:metel.pricelist,init:0
146msgid "Metel pricelist import"
147msgstr "Importazione listino Metel"
148
0149
=== added file 'product_metel/i18n/product_metel.pot'
--- product_metel/i18n/product_metel.pot 1970-01-01 00:00:00 +0000
+++ product_metel/i18n/product_metel.pot 2010-02-13 11:58:12 +0000
@@ -0,0 +1,148 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * product_metel
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 5.0.6\n"
8"Report-Msgid-Bugs-To: support@openerp.com\n"
9"POT-Creation-Date: 2010-02-13 08:49:31+0000\n"
10"PO-Revision-Date: 2010-02-13 08:49:31+0000\n"
11"Last-Translator: <>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: \n"
16"Plural-Forms: \n"
17
18#. module: product_metel
19#: model:ir.module.module,description:product_metel.module_meta_information
20msgid "Import and export Metel formatted pricelist"
21msgstr ""
22
23#. module: product_metel
24#: wizard_button:metel.pricelist,import,end:0
25msgid "End"
26msgstr ""
27
28#. module: product_metel
29#: view:res.partner:0
30msgid "Sales & Purchases"
31msgstr ""
32
33#. module: product_metel
34#: constraint:ir.model:0
35msgid "The Object name must start with x_ and not contain any special character !"
36msgstr ""
37
38#. module: product_metel
39#: wizard_view:metel.pricelist,init:0
40msgid "Please select metel pricelist file to import."
41msgstr ""
42
43#. module: product_metel
44#: field:res.partner,metel_category:0
45msgid "Import Category"
46msgstr ""
47
48#. module: product_metel
49#: code:addons\product_metel\wizard\metel_import.py:0
50#, python-format
51msgid "Metel Import Completed"
52msgstr ""
53
54#. module: product_metel
55#: code:addons\product_metel\wizard\wizard_metel_import.py:0
56#, python-format
57msgid "Error: could not find a partner with this metel code: %s"
58msgstr ""
59
60#. module: product_metel
61#: wizard_field:metel.pricelist,import,uo_message:0
62msgid "Status"
63msgstr ""
64
65#. module: product_metel
66#: code:addons\product_metel\wizard\wizard_metel_import.py:0
67#, python-format
68msgid "Error: no import category defined for the partner."
69msgstr ""
70
71#. module: product_metel
72#: code:addons\product_metel\wizard\wizard_metel_import.py:0
73#, python-format
74msgid "Import operation in progress"
75msgstr ""
76
77#. module: product_metel
78#: model:ir.model,name:product_metel.model_product_metel_fileimport
79msgid "product.metel.fileimport"
80msgstr ""
81
82#. module: product_metel
83#: model:ir.ui.menu,name:product_metel.menu_metel_import_action
84msgid "Import Metel Pricelist file"
85msgstr ""
86
87#. module: product_metel
88#: wizard_button:metel.pricelist,init,import:0
89msgid "Import pricelist"
90msgstr ""
91
92#. module: product_metel
93#: field:res.partner,metel_code:0
94msgid "Metel Code"
95msgstr ""
96
97#. module: product_metel
98#: wizard_field:metel.pricelist,init,metel_file:0
99msgid "Metel pricelist file"
100msgstr ""
101
102#. module: product_metel
103#: constraint:ir.ui.view:0
104msgid "Invalid XML for View Architecture!"
105msgstr ""
106
107#. module: product_metel
108#: model:ir.actions.wizard,name:product_metel.wizard_metel_pricelist
109msgid "Import Metel pricelist file"
110msgstr ""
111
112#. module: product_metel
113#: field:product.metel.fileimport,tmpfilename:0
114msgid "File Metel"
115msgstr ""
116
117#. module: product_metel
118#: model:ir.module.module,shortdesc:product_metel.module_meta_information
119msgid "Metel Listprice Import/Export"
120msgstr ""
121
122#. module: product_metel
123#: view:res.partner:0
124msgid "Metel Properties"
125msgstr ""
126
127#. module: product_metel
128#: code:addons\product_metel\wizard\metel_import.py:0
129#, python-format
130msgid "Imported products: %d \nUpdated products: %d"
131msgstr ""
132
133#. module: product_metel
134#: wizard_view:metel.pricelist,import:0
135msgid "Metel pricelist import report"
136msgstr ""
137
138#. module: product_metel
139#: wizard_button:metel.pricelist,init,end:0
140msgid "Cancel"
141msgstr ""
142
143#. module: product_metel
144#: wizard_view:metel.pricelist,import:0
145#: wizard_view:metel.pricelist,init:0
146msgid "Metel pricelist import"
147msgstr ""
148
0149
=== added file 'product_metel/metel.py'
--- product_metel/metel.py 1970-01-01 00:00:00 +0000
+++ product_metel/metel.py 2010-02-13 11:58:12 +0000
@@ -0,0 +1,50 @@
1##############################################################################
2#
3# Copyright (c) 2009 Luigi Grilli (luigi.grilli at gmail.com)
4# All Rights Reserved.
5#
6# WARNING: This program as such is intended to be used by professional
7# programmers who take the whole responsability of assessing all potential
8# consequences resulting from its eventual inadequacies and bugs
9# End users who are looking for a ready-to-use solution with commercial
10# garantees and support are strongly adviced to contract a Free Software
11# Service Company
12#
13# This program is Free Software; you can redistribute it and/or
14# modify it under the terms of the GNU General Public License
15# as published by the Free Software Foundation; either version 2
16# of the License, or (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26#
27##############################################################################
28# I used the code of account_bankimport as base for this module.
29#
30# This module can import metel formatted files (see www.metel.it)
31#
32
33from osv import fields,osv
34
35class res_partner(osv.osv):
36 _inherit = 'res.partner'
37 _columns = {
38 'metel_code': fields.char('Metel Code', size=10, required=False, translate=False),
39 'metel_category': fields.many2one('product.category', 'Import Category', required=False, translate=False),
40 }
41res_partner()
42
43class metel_file(osv.osv):
44 _name = 'product.metel.fileimport'
45 _columns = {
46 'tmpfilename': fields.char('File Metel', size=255, required=True, translate=False),
47 }
48metel_file()
49
50# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
051
=== added file 'product_metel/metel_view.xml'
--- product_metel/metel_view.xml 1970-01-01 00:00:00 +0000
+++ product_metel/metel_view.xml 2010-02-13 11:58:12 +0000
@@ -0,0 +1,20 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<openerp>
3 <data>
4 <record model="ir.ui.view" id="view_partner_property_form">
5 <field name="name">res.partner.product.property.form.inherit</field>
6 <field name="model">res.partner</field>
7 <field name="type">form</field>
8 <field name="inherit_id" ref="base.view_partner_form"/>
9 <field name="arch" type="xml">
10 <page string="Sales &amp; Purchases" position="inside">
11 <group colspan="2" col="2" name="metel">
12 <separator string="Metel Properties" colspan="2"/>
13 <field name="metel_code"/>
14 <field name="metel_category"/>
15 </group>
16 </page>
17 </field>
18 </record>
19 </data>
20</openerp>
0\ No newline at end of file21\ No newline at end of file
122
=== added file 'product_metel/metel_wizard.xml'
--- product_metel/metel_wizard.xml 1970-01-01 00:00:00 +0000
+++ product_metel/metel_wizard.xml 2010-02-13 11:58:12 +0000
@@ -0,0 +1,17 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<openerp>
3 <data>
4 <wizard
5 id="wizard_metel_pricelist"
6 string="Import Metel pricelist file"
7 model="ir.module.module"
8 name="metel.pricelist" />
9
10 <menuitem
11 parent="product.menu_product_pricelist_main"
12 name="Import Metel Pricelist file"
13 type="wizard"
14 action="wizard_metel_pricelist"
15 id="menu_metel_import_action"/>
16 </data>
17</openerp>
0\ No newline at end of file18\ No newline at end of file
119
=== added directory 'product_metel/test'
=== added file 'product_metel/test/metel-test.py'
--- product_metel/test/metel-test.py 1970-01-01 00:00:00 +0000
+++ product_metel/test/metel-test.py 2010-02-13 11:58:12 +0000
@@ -0,0 +1,58 @@
1##############################################################################
2# TRACCIATO FILE LISTINO METEL (ver 020)
3#
4# pos descrizione campo column tipo e lunghezza del campo
5# 1 Sigla Marchio 1 M An 03
6# 2 Codice Prodotto Produttore 4 M An 16
7# 3 Codice EAN 20 O N 13
8# 4 Descrizione prodotto 33 M An 43
9# 5 Quantita cartone 76 M N 05
10# 6 Quantita multipla ordinazione 81 M N 05
11# 7 Quantita minima ordinazione 86 M N 05
12# 8 Quantita massima ordinazione 91 M N 06
13# 9 Lead Time 97 M An 1
14# 10 Prezzo al grossista 98 M N 11.2
15# 11 Prezzo al Pubblico 109 M N 11.2
16# 12 Moltiplicatore prezzo 120 M N 06
17# 13 Codice Valuta 126 M A 03
18# 14 Unita di misura 129 M An 03
19# 15 Prodotto Composto 132 M N 01
20# 16 Stato del prodotto 133 M An 01
21# 17 Data ultima variazione 134 M Dt
22# 18 Famiglia di sconto 142 O An 18
23# 19 Famiglia statistica 160 O An 18
24# Lunghezza Record 177 bytes seguito da un fine riga (CR+LF = Carriage Return e Line feed)
25#
26##############################################################################
27
28import datetime
29
30f = open(r'Beclsp09.txt')
31
32line = f.readline()
33metel = line[0:20].strip()
34prod = line[20:23]
35desc = line[56:125].strip()
36date_start = datetime.date(int(line[40:44]), int(line[44:46]), int(line[46:48]))
37last_change = datetime.date(int(line[48:52]), int(line[52:54]), int(line[54:56]))
38
39print prod, "\t", desc, "\t", date_start, " last changed ", last_change
40
41for line in f:
42 prod = line[0:3]
43 code = line[3:19].strip()
44 desc = line[32:75].strip()
45 qmin = int(line[85:90].strip())
46 leadtime = line[96:97]
47 price1 = float(line[97:108].strip()) / 100
48 price2 = float(line[108:119].strip()) / 100
49 price_multi = float(line[119:125].strip());
50 price1 /= price_multi
51 price2 /= price_multi
52
53 family_discount = line[141:159].strip()
54 family_stat = line[159:177].strip()
55 print prod, " ", code, "\t", qmin, "\t", leadtime, "\t", price_multi, "\t", family_discount, "\t", family_stat, "\t", price1, "\t", price2, "\t", desc
56
57
58f.close()
0\ No newline at end of file59\ No newline at end of file
160
=== added directory 'product_metel/wizard'
=== added file 'product_metel/wizard/__init__.py'
--- product_metel/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ product_metel/wizard/__init__.py 2010-02-13 11:58:12 +0000
@@ -0,0 +1,28 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6# $Id$
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23
24import wizard_metel_import
25import metel_import
26
27# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
28
029
=== added file 'product_metel/wizard/metel_import.py'
--- product_metel/wizard/metel_import.py 1970-01-01 00:00:00 +0000
+++ product_metel/wizard/metel_import.py 2010-02-13 11:58:12 +0000
@@ -0,0 +1,244 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Copyright (c) 2010 Luigi Grilli (luigi.grilli at gmail.com)
5# All Rights Reserved.
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22
23import pooler
24import time
25import datetime
26import netsvc
27import base64
28import tools
29import threading
30from osv import fields, osv
31from tools.translate import _
32from tempfile import TemporaryFile
33from tools.misc import debug
34
35class MetelImport(threading.Thread):
36 def Init(self, cr, uid, data):
37 self.uid = uid
38
39 self.dbname = cr.dbname
40 self.pool = pooler.get_pool(cr.dbname)
41 self.cr = cr
42
43 self.uo_new = 0
44 self.uo_update = 0
45 self.SetFile(data)
46
47 return self.ReadMetelHeader()
48
49 def SetFile(self, data):
50 self.fileobj = TemporaryFile()
51 self.fileobj.write( data )
52 self.fileobj.seek(0)
53 return
54
55 def run(self):
56 self.cr = pooler.get_db(self.dbname).cursor()
57 self.pool = pooler.get_pool(self.cr.dbname)
58
59 self.ImportFile()
60
61 body = _("Imported products: %d \nUpdated products: %d") % (self.uo_new, self.uo_update)
62 request = self.pool.get('res.request')
63 request.create(self.cr, self.uid, {
64 'name': _("Metel Import Completed"),
65 'act_from': self.uid,
66 'act_to': self.uid,
67 'ref_partner_id': self.partner_id,
68 'state': 'waiting',
69 'body': body,
70 'active': True,
71 })
72
73 self.cr.commit()
74 self.cr.close()
75
76 return
77
78 def ReadMetelHeader(self):
79 line = self.fileobj.readline()
80 self.metel = line[0:20].strip()
81 self.prod = line[20:23]
82 self.desc = line[56:125].strip()
83 self.date_start = datetime.date(int(line[40:44]), int(line[44:46]), int(line[46:48]))
84 self.last_change = datetime.date(int(line[48:52]), int(line[52:54]), int(line[54:56]))
85
86 # is there a matching partner?
87 partner_ids = self.pool.get('res.partner').search(self.cr, self.uid, [('metel_code', '=', self.prod)])
88
89 if partner_ids:
90 self.partner_id = partner_ids[0]
91 #get partner record
92 self.partner_obj = self.pool.get('res.partner').browse(self.cr, self.uid, partner_ids)
93 if self.partner_obj[0].metel_category:
94 self.cat_id = self.partner_obj[0].metel_category.id
95 return 1
96
97 return -2
98 else:
99 self.partner_id = 0
100 self.partner_obj = None
101 self.cat_id = 0
102
103 return -1
104
105 def GetDiscountFamily(self, name):
106 '''Get the category that match the specified discount family, in not found create it
107
108 Args:
109 name: Discount family name
110
111 Returns:
112 The category ID of the product
113 '''
114 if len(name) > 0:
115 #is there a matching category ?
116 family_id = self.pool.get('product.category').search(self.cr, self.uid, [('name', '=', name), ("parent_id", '=', self.cat_id)])
117
118 # family found
119 if family_id:
120 return family_id[0]
121 #family discount not found, create it
122 else:
123 return self.pool.get('product.category').create(self.cr, self.uid,
124 {
125 'name': name,
126 'parent_id': self.cat_id,
127 })
128
129 #if category name is empty return the main import category ID
130 return self.cat_id
131
132 def GetUOM(self, uom):
133 '''Get the unity of measure specified, in not found create it
134
135 Args:
136 name: UOM name
137
138 Returns:
139 The UOM ID of the product
140 '''
141
142 if len(uom) <= 0:
143 return 0
144
145 #is there a matching category ?
146 uom_id = self.pool.get('product.uom').search(self.cr, self.uid, [('name', '=', uom)])
147
148 if uom_id:
149 return uom_id[0]
150 else:
151 uom_cat_ids = self.pool.get('product.uom.categ').search(self.cr, self.uid, [('name', '=', 'Unit')])
152 return self.pool.get('product.uom').create(self.cr, self.uid,
153 {
154 'name': uom,
155 'category_id': uom_cat_ids[0],
156 })
157
158 return 0
159
160 def ImportFile(self):
161 if self.partner_id > 0:
162 #Import Products
163 for line in self.fileobj:
164 self.ImportRow(line)
165 return
166
167 def ImportRow(self, line):
168 prod = line[0:3]
169 code = line[3:19].strip()
170 ean13 = line[19:32]
171 desc = line[32:75].strip()
172 qmin = int(line[85:90].strip())
173 leadtime = line[96:97]
174 price1 = float(line[97:108].strip()) / 100
175 price2 = float(line[108:119].strip()) / 100
176 price_multi = float(line[119:125].strip());
177 price1 /= price_multi
178 price2 /= price_multi
179 uom = line[128:131].strip()
180 family_discount = line[141:159].strip()
181 family_stat = line[159:177].strip()
182
183 if len(code) <= 0:
184 return
185
186 print "code:", code, " partner_id:", self.partner_id
187 # is there a matching product ?
188 product_id = self.pool.get('product.product').search(self.cr, self.uid, [('manufacturer', '=', self.partner_id), ("manufacturer_pref", '=', code)])
189
190 # product found, update it
191 if product_id:
192 self.uo_update += 1
193 product = self.pool.get('product.product').write(self.cr, self.uid, product_id[0], {'standard_price': price1})
194
195 # is there a matching supplier info ?
196 supplier_id = self.pool.get('product.supplierinfo').search(self.cr, self.uid, [('product_id', '=', product_id[0])])
197
198 #updated supplier info with leadtime and minimun quantity
199 if supplier_id:
200 supplier = self.pool.get('product.supplierinfo').write(self.cr, self.uid, supplier_id[0], {'qty': qmin, 'delay': leadtime})
201 # create the supplier info for the manufacturer
202 else:
203 supplier = self.pool.get('product.supplierinfo').create(self.cr, self.uid,
204 {
205 'product_id': product_id[0],
206 'qty': qmin,
207 'delay': leadtime,
208 'name': self.partner_id,
209 'product_code': code,
210 'product_name': desc,
211 })
212
213 #product not found, create it. we use the code and the description of the manufacturer
214 else:
215 self.uo_new += 1
216
217 product_cat = self.GetDiscountFamily(family_discount)
218 product_uom = self.GetUOM(uom)
219
220 product = self.pool.get('product.product').create(self.cr, self.uid,
221 {
222 'default_code': code,
223 'name': desc,
224 'ean13': ean13,
225 'manufacturer': self.partner_id,
226 'manufacturer_pref': code,
227 'manufacturer_pname': desc,
228 'standard_price': price1,
229 'list_price': price2,
230 'categ_id': product_cat,
231 'uom_id': product_uom,
232 'uom_po_id': product_uom,
233 })
234
235 # create the supplier info for the manufacturer
236 supplier = self.pool.get('product.supplierinfo').create(self.cr, self.uid,
237 {
238 'product_id': product,
239 'qty': qmin,
240 'delay': leadtime,
241 'name': self.partner_id,
242 'product_code': code,
243 'product_name': desc,
244 })
0245
=== added file 'product_metel/wizard/wizard_metel_import.py'
--- product_metel/wizard/wizard_metel_import.py 1970-01-01 00:00:00 +0000
+++ product_metel/wizard/wizard_metel_import.py 2010-02-13 11:58:12 +0000
@@ -0,0 +1,105 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Copyright (c) 2009 Luigi Grilli (luigi.grilli at gmail.com)
5# All Rights Reserved.
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22
23import pooler
24import time
25import datetime
26import wizard
27import netsvc
28import base64
29import tools
30from osv import fields, osv
31from tools.translate import _
32from tempfile import TemporaryFile
33from tools.misc import debug
34import metel_import
35
36_finish_form ="""<?xml version="1.0"?>
37<form string="Metel pricelist import">
38 <separator string="Metel pricelist import report" colspan="4" />
39 <field name="uo_message"/>
40</form>"""
41
42_ask_form ="""<?xml version="1.0"?>
43<form string="Metel pricelist import">
44 <label string="Please select metel pricelist file to import." colspan="4"/>
45 <field name="metel_file"/>
46</form>"""
47
48_ask_fields = {
49 'metel_file': {'string': 'Metel pricelist file', 'type': 'binary', 'required': True},
50}
51
52_finish_fields = {
53 'uo_message': {'string':'Status', 'readonly': True, 'type':'text'},
54}
55
56class metel_import_pricelist(wizard.interface):
57 def ImportPriceList(self, cr, uid, data, context):
58 '''Import the pricelist from a Metel file, creating products where needed
59
60 Returns:
61 uo_message: Messagge for the user
62 '''
63
64
65 #initialization
66 metel = metel_import.MetelImport()
67 execute = metel.Init(cr, uid, base64.decodestring(data['form']['metel_file']))
68
69 if execute == 1:
70 metel.start()
71 uo_message = _("Import operation in progress")
72 elif execute == -1:
73 uo_message = _("Error: could not find a partner with this metel code: %s") % metel.prod
74 elif execute == -2:
75 uo_message = _("Error: no import category defined for the partner.")
76
77 return {'uo_message': uo_message}
78
79 states = {
80 'init': {
81 'actions': [],
82 'result': {
83 'type': 'form',
84 'arch': _ask_form,
85 'fields': _ask_fields,
86 'state': [
87 ('end', 'Cancel', 'gtk-cancel'),
88 ('import', 'Import pricelist', 'gtk-ok', True)
89 ]
90 }
91 },
92 'import': {
93 'actions': [ImportPriceList],
94 'result': {
95 'type': 'form',
96 'arch': _finish_form,
97 'fields': _finish_fields,
98 'state': [('end','End')]
99 }
100 },
101 }
102metel_import_pricelist("metel.pricelist")
103
104# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
105