Merge lp:~altegra/pepess/pepess_dev_carlos_magentopepess into lp:pepess
- pepess_dev_carlos_magentopepess
- Merge into pepess
Proposed by
Carlos Blanco - http://www.grupoaltegra.com
Status: | Merged |
---|---|
Merged at revision: | 76 |
Proposed branch: | lp:~altegra/pepess/pepess_dev_carlos_magentopepess |
Merge into: | lp:pepess |
Diff against target: |
259 lines (+244/-0) 3 files modified
magento_bridge_pepess/__init__.py (+32/-0) magento_bridge_pepess/__openerp__.py (+51/-0) magento_bridge_pepess/magento_bridge.py (+161/-0) |
To merge this branch: | bzr merge lp:~altegra/pepess/pepess_dev_carlos_magentopepess |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Eric Hernández - http://www.grupoaltegra.com | Approve | ||
Review via email: mp+240794@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Eric Hernández - http://www.grupoaltegra.com (daimon) wrote : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'magento_bridge_pepess' | |||
2 | === added file 'magento_bridge_pepess/__init__.py' | |||
3 | --- magento_bridge_pepess/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ magento_bridge_pepess/__init__.py 2014-11-05 23:08:04 +0000 | |||
5 | @@ -0,0 +1,32 @@ | |||
6 | 1 | #!/usr/bin/env python | ||
7 | 2 | #-*- coding:utf-8 -*- | ||
8 | 3 | |||
9 | 4 | ############################################################################# | ||
10 | 5 | # Module Writen to OpenERP, Open Source Management Solution | ||
11 | 6 | # CopyLeft 2012 - http://www.grupoaltegra.com | ||
12 | 7 | # You are free to share, copy, distribute, transmit, adapt and use for commercial purpose | ||
13 | 8 | # More information about license: http://www.gnu.org/licenses/agpl.html | ||
14 | 9 | # info Grupo Altegra (openerp@grupoaltegra.com) | ||
15 | 10 | # | ||
16 | 11 | ############################################################################# | ||
17 | 12 | # | ||
18 | 13 | # Coded by: Carlos Blanco (carlos.blanco@grupoaltegra.com) | ||
19 | 14 | # | ||
20 | 15 | ############################################################################# | ||
21 | 16 | # | ||
22 | 17 | # This program is free software: you can redistribute it and/or modify | ||
23 | 18 | # it under the terms of the GNU Affero General Public License as | ||
24 | 19 | # published by the Free Software Foundation, either version 3 of the | ||
25 | 20 | # License, or (at your option) any later version. | ||
26 | 21 | # | ||
27 | 22 | # This program is distributed in the hope that it will be useful, | ||
28 | 23 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
29 | 24 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
30 | 25 | # GNU Affero General Public License for more details. | ||
31 | 26 | # | ||
32 | 27 | # You should have received a copy of the GNU Affero General Public License | ||
33 | 28 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
34 | 29 | # | ||
35 | 30 | ############################################################################# | ||
36 | 31 | |||
37 | 32 | import magento_bridge | ||
38 | 0 | 33 | ||
39 | === added file 'magento_bridge_pepess/__openerp__.py' | |||
40 | --- magento_bridge_pepess/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
41 | +++ magento_bridge_pepess/__openerp__.py 2014-11-05 23:08:04 +0000 | |||
42 | @@ -0,0 +1,51 @@ | |||
43 | 1 | #!/usr/bin/env python | ||
44 | 2 | #-*- coding:utf-8 -*- | ||
45 | 3 | |||
46 | 4 | ############################################################################# | ||
47 | 5 | # Module Writen to OpenERP, Open Source Management Solution | ||
48 | 6 | # CopyLeft 2012 - http://www.grupoaltegra.com | ||
49 | 7 | # You are free to share, copy, distribute, transmit, adapt and use for commercial purpose | ||
50 | 8 | # More information about license: http://www.gnu.org/licenses/agpl.html | ||
51 | 9 | # info Grupo Altegra (openerp@grupoaltegra.com) | ||
52 | 10 | # | ||
53 | 11 | ############################################################################# | ||
54 | 12 | # | ||
55 | 13 | # Coded by: Carlos Blanco (carlos.blanco@grupoaltegra.com) | ||
56 | 14 | # | ||
57 | 15 | ############################################################################# | ||
58 | 16 | # | ||
59 | 17 | # This program is free software: you can redistribute it and/or modify | ||
60 | 18 | # it under the terms of the GNU Affero General Public License as | ||
61 | 19 | # published by the Free Software Foundation, either version 3 of the | ||
62 | 20 | # License, or (at your option) any later version. | ||
63 | 21 | # | ||
64 | 22 | # This program is distributed in the hope that it will be useful, | ||
65 | 23 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
66 | 24 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
67 | 25 | # GNU Affero General Public License for more details. | ||
68 | 26 | # | ||
69 | 27 | # You should have received a copy of the GNU Affero General Public License | ||
70 | 28 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
71 | 29 | # | ||
72 | 30 | ############################################################################# | ||
73 | 31 | |||
74 | 32 | { | ||
75 | 33 | "name" : 'Magento custom for Pepess ', | ||
76 | 34 | "version" : '0.1', | ||
77 | 35 | "author" : 'Grupo Altegra', | ||
78 | 36 | "category" : 'Custom Modules', | ||
79 | 37 | "website" : "http://www.grupoaltegra.com", | ||
80 | 38 | "description" : """ The basic fields are sent Pepess ERP """, | ||
81 | 39 | "init_xml" : [], | ||
82 | 40 | "depends" : ['base','magento_bridge'], | ||
83 | 41 | "update_xml" : [ | ||
84 | 42 | |||
85 | 43 | ], | ||
86 | 44 | "demo_xml" : [ | ||
87 | 45 | ], | ||
88 | 46 | "test" : [ | ||
89 | 47 | ], | ||
90 | 48 | "installable" : True, | ||
91 | 49 | "images": [], | ||
92 | 50 | "auto_install" : False, | ||
93 | 51 | } | ||
94 | 0 | 52 | ||
95 | === added file 'magento_bridge_pepess/magento_bridge.py' | |||
96 | --- magento_bridge_pepess/magento_bridge.py 1970-01-01 00:00:00 +0000 | |||
97 | +++ magento_bridge_pepess/magento_bridge.py 2014-11-05 23:08:04 +0000 | |||
98 | @@ -0,0 +1,161 @@ | |||
99 | 1 | #!/usr/bin/env python | ||
100 | 2 | #-*- coding:utf-8 -*- | ||
101 | 3 | |||
102 | 4 | ############################################################################# | ||
103 | 5 | # Module Writen to OpenERP, Open Source Management Solution | ||
104 | 6 | # CopyLeft 2012 - http://www.grupoaltegra.com | ||
105 | 7 | # You are free to share, copy, distribute, transmit, adapt and use for commercial purpose | ||
106 | 8 | # More information about license: http://www.gnu.org/licenses/agpl.html | ||
107 | 9 | # info Grupo Altegra (openerp@grupoaltegra.com) | ||
108 | 10 | # | ||
109 | 11 | ############################################################################# | ||
110 | 12 | # | ||
111 | 13 | # Coded by: Carlos Blanco (carlos.blanco@grupoaltegra.com) | ||
112 | 14 | # | ||
113 | 15 | ############################################################################# | ||
114 | 16 | # | ||
115 | 17 | # This program is free software: you can redistribute it and/or modify | ||
116 | 18 | # it under the terms of the GNU Affero General Public License as | ||
117 | 19 | # published by the Free Software Foundation, either version 3 of the | ||
118 | 20 | # License, or (at your option) any later version. | ||
119 | 21 | # | ||
120 | 22 | # This program is distributed in the hope that it will be useful, | ||
121 | 23 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
122 | 24 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
123 | 25 | # GNU Affero General Public License for more details. | ||
124 | 26 | # | ||
125 | 27 | # You should have received a copy of the GNU Affero General Public License | ||
126 | 28 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
127 | 29 | # | ||
128 | 30 | ############################################################################# | ||
129 | 31 | |||
130 | 32 | from osv import osv, fields | ||
131 | 33 | import xmlrpclib | ||
132 | 34 | |||
133 | 35 | class product_sync(osv.osv_memory): | ||
134 | 36 | |||
135 | 37 | _inherit="product.sync" | ||
136 | 38 | |||
137 | 39 | ############################################# | ||
138 | 40 | ## update all products ## | ||
139 | 41 | ############################################# | ||
140 | 42 | def update_products(self,cr,uid,ids,context=None): | ||
141 | 43 | count = pro = 0 | ||
142 | 44 | text = text1 = '' | ||
143 | 45 | error_ids = [] | ||
144 | 46 | get_product_data = {} | ||
145 | 47 | connection = self.pool.get('magento.configure')._create_connection(cr,uid) | ||
146 | 48 | if connection: | ||
147 | 49 | url = connection[0] | ||
148 | 50 | session = connection[1] | ||
149 | 51 | server = xmlrpclib.Server(url) | ||
150 | 52 | map_id = self.pool.get('magento.product').search(cr,uid,[('need_sync','=','Yes')]) | ||
151 | 53 | pro_ids = self.pool.get('product.product').search(cr,uid,[]) | ||
152 | 54 | if not map_id or not pro_ids: | ||
153 | 55 | raise osv.except_osv(_('Information'), _("No product(s) has been found to be Update on Magento!!!")) | ||
154 | 56 | if map_id: | ||
155 | 57 | for i in map_id: | ||
156 | 58 | pro_obj = self.pool.get('magento.product').browse(cr,uid,i) | ||
157 | 59 | pro_id = pro_obj.oe_product_id | ||
158 | 60 | mage_id = pro_obj.mag_product_id | ||
159 | 61 | if pro_id in pro_ids and mage_id: | ||
160 | 62 | prod_catg = 2 | ||
161 | 63 | quantity = 0 | ||
162 | 64 | stock = 0 | ||
163 | 65 | obj_pro = self.pool.get('product.product').browse(cr,uid,pro_id) | ||
164 | 66 | if obj_pro.categ_id.id: | ||
165 | 67 | prod_catg = self.pool.get('category.sync').sync_categories(cr, uid, url, session, obj_pro.categ_id.id) | ||
166 | 68 | get_product_data['name'] = obj_pro.name | ||
167 | 69 | get_product_data['price'] = obj_pro.list_price or 0.00 | ||
168 | 70 | get_product_data['weight'] = obj_pro.weight_net or 0.00 | ||
169 | 71 | get_product_data['categories'] = [prod_catg] | ||
170 | 72 | |||
171 | 73 | ################## | ||
172 | 74 | # Campos Pepess # | ||
173 | 75 | ################## | ||
174 | 76 | get_product_data['linea'] = obj_pro.line_id and obj_pro.line_id.name or '' | ||
175 | 77 | get_product_data['tipo'] = obj_pro.kind_id and obj_pro.kind_id.name or '' | ||
176 | 78 | get_product_data['tarca'] = obj_pro.brand_id and obj_pro.brand_id.name or '' | ||
177 | 79 | |||
178 | 80 | update_data = [mage_id, get_product_data] | ||
179 | 81 | try: | ||
180 | 82 | pro = server.call(session, 'product.update', update_data) | ||
181 | 83 | self.pool.get('magento.product').write(cr, uid, i, {'need_sync':'No'}) | ||
182 | 84 | count = count + 1 | ||
183 | 85 | except xmlrpclib.Fault, e: | ||
184 | 86 | error_ids.append(pro_id) | ||
185 | 87 | if pro and obj_pro.qty_available>0: | ||
186 | 88 | quantity = obj_pro.qty_available | ||
187 | 89 | stock = 1 | ||
188 | 90 | server.call(session, 'product_stock.update', [mage_id, {'manage_stock':1, 'qty':quantity,'is_in_stock':stock}]) | ||
189 | 91 | if count: | ||
190 | 92 | text = '%s Product has been sucessfully updated to Magento. \n'%count | ||
191 | 93 | self.pool.get('magento.sync.history').create(cr,uid,{'status':'yes','action_on':'product','action':'c','error_message':text}) | ||
192 | 94 | if error_ids: | ||
193 | 95 | text1 = 'The Listed Product ids %s does not updated on magento.'%error_ids | ||
194 | 96 | self.pool.get('magento.sync.history').create(cr,uid,{'status':'no','action_on':'product','action':'c','error_message':text1}) | ||
195 | 97 | text2 = text+text1 | ||
196 | 98 | if not text2: | ||
197 | 99 | raise osv.except_osv(_('Information'), _("No product(s) has been found to be Update on Magento!!!")) | ||
198 | 100 | partial = self.pool.get('message.wizard').create(cr, uid, {'text':text2}) | ||
199 | 101 | return { 'name':_("Information"), | ||
200 | 102 | 'view_mode': 'form', | ||
201 | 103 | 'view_id': False, | ||
202 | 104 | 'view_type': 'form', | ||
203 | 105 | 'res_model': 'message.wizard', | ||
204 | 106 | 'res_id': partial, | ||
205 | 107 | 'type': 'ir.actions.act_window', | ||
206 | 108 | 'nodestroy': True, | ||
207 | 109 | 'target': 'new', | ||
208 | 110 | 'domain': '[]', | ||
209 | 111 | } | ||
210 | 112 | |||
211 | 113 | |||
212 | 114 | ############################################# | ||
213 | 115 | ## Specific product sync ## | ||
214 | 116 | ############################################# | ||
215 | 117 | def _export_specific_product(self, cr, uid, id, url, session,context=None): | ||
216 | 118 | |||
217 | 119 | """ | ||
218 | 120 | @param code: product Id. | ||
219 | 121 | @param context: A standard dictionary | ||
220 | 122 | @return: list | ||
221 | 123 | """ | ||
222 | 124 | prod_catg = False | ||
223 | 125 | get_product_data = {} | ||
224 | 126 | server = xmlrpclib.Server(url) | ||
225 | 127 | if id: | ||
226 | 128 | obj_pro = self.pool.get('product.product').browse(cr,uid,id) | ||
227 | 129 | if obj_pro.categ_id.id: | ||
228 | 130 | prod_catg = self.pool.get('category.sync').sync_categories(cr, uid, url, session, obj_pro.categ_id.id) | ||
229 | 131 | sku = obj_pro.default_code or 'Ref %s'%id | ||
230 | 132 | get_product_data['name'] = obj_pro.name | ||
231 | 133 | get_product_data['short_description'] = obj_pro.description_sale or 'None' | ||
232 | 134 | get_product_data['description'] = obj_pro.description or 'None' | ||
233 | 135 | get_product_data['price'] = obj_pro.list_price or 0.00 | ||
234 | 136 | get_product_data['weight'] = obj_pro.weight_net or 0.00 | ||
235 | 137 | get_product_data['categories'] = [prod_catg] | ||
236 | 138 | get_product_data['websites'] = [1] | ||
237 | 139 | get_product_data['status'] = 1 | ||
238 | 140 | get_product_data['tax_class_id'] = 0 | ||
239 | 141 | |||
240 | 142 | ################## | ||
241 | 143 | # Campos Pepess # | ||
242 | 144 | ################## | ||
243 | 145 | get_product_data['linea'] = obj_pro.line_id and obj_pro.line_id.name or '' | ||
244 | 146 | get_product_data['tipo'] = obj_pro.kind_id and obj_pro.kind_id.name or '' | ||
245 | 147 | get_product_data['marca'] = obj_pro.brand_id and obj_pro.brand_id.name or '' | ||
246 | 148 | |||
247 | 149 | if obj_pro.type in ['product','consu']: | ||
248 | 150 | prodtype = 'simple' | ||
249 | 151 | else: | ||
250 | 152 | prodtype = 'virtual' | ||
251 | 153 | pro = self.prodcreate(cr,uid,url,session,id,prodtype,sku,get_product_data) | ||
252 | 154 | if pro[0] != 0: | ||
253 | 155 | if obj_pro.image: | ||
254 | 156 | file = {'content':obj_pro.image,'mime':'image/jpeg'} | ||
255 | 157 | type = ['image','small_image','thumbnail'] | ||
256 | 158 | pic = {'file':file,'label':'Label', 'position':'100','types':type, 'exclude':1} | ||
257 | 159 | image = [pro[1],pic] | ||
258 | 160 | k = server.call(session,'catalog_product_attribute_media.create',image) | ||
259 | 161 | return pro |
Good job, keep going !!