Merge lp:~red15/magentoerpconnect/fix-magentoerp-logging into lp:magentoerpconnect/oerp6.1-oldstable
- fix-magentoerp-logging
- Merge into trunk_version
Proposed by
Niels Huylebroeck
Status: | Merged |
---|---|
Merge reported by: | Guewen Baconnier @ Camptocamp |
Merged at revision: | not available |
Proposed branch: | lp:~red15/magentoerpconnect/fix-magentoerp-logging |
Merge into: | lp:magentoerpconnect/oerp6.1-oldstable |
Diff against target: |
965 lines (+135/-137) 6 files modified
magentoerpconnect/magerp_core.py (+4/-5) magentoerpconnect/magerp_osv.py (+30/-30) magentoerpconnect/product.py (+53/-55) magentoerpconnect/product_images.py (+14/-14) magentoerpconnect/sale.py (+25/-24) magentoerpconnect/stock.py (+9/-9) |
To merge this branch: | bzr merge lp:~red15/magentoerpconnect/fix-magentoerp-logging |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guewen Baconnier @ Camptocamp | Approve | ||
Review via email: mp+107348@code.launchpad.net |
Commit message
Description of the change
Replaced all logging calls for modules contained in the magentoerp branch, there are more modules that need fixing but they would have to be pulled into this branch first I suppose?
To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
review:
Approve
- 634. By Niels Huylebroeck
-
[MRG] Replaced all netsvc.Logger() calls with the appropriate logging.getLogger() and also adjusted the logging calls themselves.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'magentoerpconnect/magerp_core.py' | |||
2 | --- magentoerpconnect/magerp_core.py 2012-05-15 11:49:38 +0000 | |||
3 | +++ magentoerpconnect/magerp_core.py 2012-05-25 09:04:23 +0000 | |||
4 | @@ -25,7 +25,7 @@ | |||
5 | 25 | from osv import osv, fields | 25 | from osv import osv, fields |
6 | 26 | import magerp_osv | 26 | import magerp_osv |
7 | 27 | import pooler | 27 | import pooler |
9 | 28 | import netsvc | 28 | import logging |
10 | 29 | import base64, urllib | 29 | import base64, urllib |
11 | 30 | from magerp_osv import Connection | 30 | from magerp_osv import Connection |
12 | 31 | import tools | 31 | import tools |
13 | @@ -67,7 +67,7 @@ | |||
14 | 67 | 'magento_referential': fields.function(_is_magento_referential, type="boolean", method=True, string="Magento Referential"), | 67 | 'magento_referential': fields.function(_is_magento_referential, type="boolean", method=True, string="Magento Referential"), |
15 | 68 | 'last_imported_product_id': fields.integer('Last Imported Product Id', help="Product are imported one by one. This is the magento id of the last product imported. If you clear it all product will be imported"), | 68 | 'last_imported_product_id': fields.integer('Last Imported Product Id', help="Product are imported one by one. This is the magento id of the last product imported. If you clear it all product will be imported"), |
16 | 69 | 'last_imported_partner_id': fields.integer('Last Imported Partner Id', help="Partners are imported one by one. This is the magento id of the last partner imported. If you clear it all partners will be imported"), | 69 | 'last_imported_partner_id': fields.integer('Last Imported Partner Id', help="Partners are imported one by one. This is the magento id of the last partner imported. If you clear it all partners will be imported"), |
18 | 70 | 'import_all_attributs': fields.boolean('Import all attributs', help="If the option is uncheck only the attributs that doesn't exist in OpenERP will be imported"), | 70 | 'import_all_attributs': fields.boolean('Import all attributs', help="If the option is uncheck only the attributs that doesn't exist in OpenERP will be imported"), |
19 | 71 | 'import_image_with_product': fields.boolean('With image', help="If the option is check the product's image and the product will be imported at the same time and so the step '7-import images' is not needed"), | 71 | 'import_image_with_product': fields.boolean('With image', help="If the option is check the product's image and the product will be imported at the same time and so the step '7-import images' is not needed"), |
20 | 72 | 'import_links_with_product': fields.boolean('With links', help="If the option is check the product's links (Up-Sell, Cross-Sell, Related) and the product will be imported at the same time and so the step '8-import links' is not needed"), | 72 | 'import_links_with_product': fields.boolean('With links', help="If the option is check the product's links (Up-Sell, Cross-Sell, Related) and the product will be imported at the same time and so the step '8-import links' is not needed"), |
21 | 73 | } | 73 | } |
22 | @@ -123,7 +123,7 @@ | |||
23 | 123 | def sync_attribs(self, cr, uid, ids, context=None): | 123 | def sync_attribs(self, cr, uid, ids, context=None): |
24 | 124 | attr_obj = self.pool.get('magerp.product_attributes') | 124 | attr_obj = self.pool.get('magerp.product_attributes') |
25 | 125 | attr_set_obj = self.pool.get('magerp.product_attribute_set') | 125 | attr_set_obj = self.pool.get('magerp.product_attribute_set') |
27 | 126 | logger = netsvc.Logger() | 126 | logger = logging.getLogger('ext synchro') |
28 | 127 | for referential in self.browse(cr, uid, ids, context=context): | 127 | for referential in self.browse(cr, uid, ids, context=context): |
29 | 128 | attr_conn = referential.external_connection(DEBUG, context=context) | 128 | attr_conn = referential.external_connection(DEBUG, context=context) |
30 | 129 | attrib_set_ids = attr_set_obj.search(cr, uid, [('referential_id', '=', referential.id)]) | 129 | attrib_set_ids = attr_set_obj.search(cr, uid, [('referential_id', '=', referential.id)]) |
31 | @@ -146,7 +146,7 @@ | |||
32 | 146 | attributes_imported.append(ext_id) | 146 | attributes_imported.append(ext_id) |
33 | 147 | attr_obj.ext_import(import_cr, uid, [attribut], referential.id, defaults={'referential_id':referential.id}, context={'referential_id':referential.id}) | 147 | attr_obj.ext_import(import_cr, uid, [attribut], referential.id, defaults={'referential_id':referential.id}, context={'referential_id':referential.id}) |
34 | 148 | import_cr.commit() | 148 | import_cr.commit() |
36 | 149 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "All attributs for the attributs set id %s was succesfully imported" %(attr_set_id)) | 149 | logger.info("All attributs for the attributs set id %s was succesfully imported", attr_set_id) |
37 | 150 | #Relate attribute sets & attributes | 150 | #Relate attribute sets & attributes |
38 | 151 | mage_inp = {} | 151 | mage_inp = {} |
39 | 152 | #Pass in {attribute_set_id:{attributes},attribute_set_id2:{attributes}} | 152 | #Pass in {attribute_set_id:{attributes},attribute_set_id2:{attributes}} |
40 | @@ -263,7 +263,6 @@ | |||
41 | 263 | return conn.call('catalog_product_link.types') | 263 | return conn.call('catalog_product_link.types') |
42 | 264 | 264 | ||
43 | 265 | def sync_images(self, cr, uid, ids, context=None): | 265 | def sync_images(self, cr, uid, ids, context=None): |
44 | 266 | logger = netsvc.Logger() | ||
45 | 267 | product_obj = self.pool.get('product.product') | 266 | product_obj = self.pool.get('product.product') |
46 | 268 | image_obj = self.pool.get('product.images') | 267 | image_obj = self.pool.get('product.images') |
47 | 269 | import_cr = pooler.get_db(cr.dbname).cursor() | 268 | import_cr = pooler.get_db(cr.dbname).cursor() |
48 | 270 | 269 | ||
49 | === modified file 'magentoerpconnect/magerp_osv.py' | |||
50 | --- magentoerpconnect/magerp_osv.py 2012-05-24 06:57:34 +0000 | |||
51 | +++ magentoerpconnect/magerp_osv.py 2012-05-25 09:04:23 +0000 | |||
52 | @@ -24,7 +24,7 @@ | |||
53 | 24 | import time | 24 | import time |
54 | 25 | import datetime | 25 | import datetime |
55 | 26 | import xmlrpclib | 26 | import xmlrpclib |
57 | 27 | import netsvc | 27 | import logging |
58 | 28 | import urllib2 | 28 | import urllib2 |
59 | 29 | import base64 | 29 | import base64 |
60 | 30 | import pooler | 30 | import pooler |
61 | @@ -39,7 +39,7 @@ | |||
62 | 39 | def __init__(self, location, username, password, debug=False): | 39 | def __init__(self, location, username, password, debug=False): |
63 | 40 | #Append / if not there | 40 | #Append / if not there |
64 | 41 | if not location[-1] == '/': | 41 | if not location[-1] == '/': |
66 | 42 | location += '/' | 42 | location += '/' |
67 | 43 | self.corelocation = location | 43 | self.corelocation = location |
68 | 44 | #Please do not remove the str indeed xmlrpc lib require a string for the location | 44 | #Please do not remove the str indeed xmlrpc lib require a string for the location |
69 | 45 | #if an unicode is send it will raise you an error | 45 | #if an unicode is send it will raise you an error |
70 | @@ -48,33 +48,33 @@ | |||
71 | 48 | self.password = password | 48 | self.password = password |
72 | 49 | self.debug = False | 49 | self.debug = False |
73 | 50 | self.result = {} | 50 | self.result = {} |
77 | 51 | self.logger = netsvc.Logger() | 51 | self.logger = logging.getLogger('Connection(%s)' % self.location) |
78 | 52 | 52 | ||
79 | 53 | 53 | ||
80 | 54 | def connect(self): | 54 | def connect(self): |
81 | 55 | if not self.location[-1] == '/': | 55 | if not self.location[-1] == '/': |
82 | 56 | self.location += '/' | 56 | self.location += '/' |
83 | 57 | if self.debug: | 57 | if self.debug: |
85 | 58 | self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Attempting connection with Settings:%s,%s,%s") % (self.location, self.username, self.password)) | 58 | self.logger.info(_("Attempting connection with Settings:%s,%s,%s"), self.location, self.username, self.password) |
86 | 59 | self.ser = xmlrpclib.ServerProxy(self.location) | 59 | self.ser = xmlrpclib.ServerProxy(self.location) |
87 | 60 | for sleep_time in [1, 3, 6]: | 60 | for sleep_time in [1, 3, 6]: |
88 | 61 | try: | 61 | try: |
89 | 62 | self.session = self.ser.login(self.username, self.password) | 62 | self.session = self.ser.login(self.username, self.password) |
90 | 63 | if self.debug: | 63 | if self.debug: |
92 | 64 | self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Login Successful")) | 64 | self.logger.info(_("Login Successful")) |
93 | 65 | return True | 65 | return True |
94 | 66 | except IOError, e: | 66 | except IOError, e: |
97 | 67 | self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_ERROR, _("Error in connecting:%s") % (e)) | 67 | self.logger.error(_("Error in connecting:%s"), e, exc_info=True) |
98 | 68 | self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_WARNING, _("Webservice Failure, sleeping %s second before next attempt") % (sleep_time)) | 68 | self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time) |
99 | 69 | time.sleep(sleep_time) | 69 | time.sleep(sleep_time) |
100 | 70 | except Exception,e: | 70 | except Exception,e: |
108 | 71 | self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_ERROR, _("Error in connecting:%s") % (e)) | 71 | self.logger.error(_("Error in connecting:%s"), e, exc_info=True) |
109 | 72 | self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_WARNING, _("Webservice Failure, sleeping %s second before next attempt") % (sleep_time)) | 72 | self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time) |
110 | 73 | time.sleep(sleep_time) | 73 | time.sleep(sleep_time) |
111 | 74 | raise osv.except_osv(_('User Error'), _('Error when try to connect to magento, are your sure that your login is right? Did openerp can access to your magento?')) | 74 | raise osv.except_osv(_('User Error'), _('Error connecting to magento, are your sure that your login is right? Did you configure API user in magento?')) |
112 | 75 | 75 | ||
113 | 76 | 76 | ||
114 | 77 | def call(self, method, *arguments): | 77 | def call(self, method, *arguments): |
115 | 78 | if arguments: | 78 | if arguments: |
116 | 79 | arguments = list(arguments)[0] | 79 | arguments = list(arguments)[0] |
117 | 80 | else: | 80 | else: |
118 | @@ -82,18 +82,18 @@ | |||
119 | 82 | for sleep_time in [1, 3, 6]: | 82 | for sleep_time in [1, 3, 6]: |
120 | 83 | try: | 83 | try: |
121 | 84 | if self.debug: | 84 | if self.debug: |
123 | 85 | self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Calling Method:%s,Arguments:%s") % (method, arguments)) | 85 | self.logger.info(_("Calling Method:%s,Arguments:%s"), method, arguments) |
124 | 86 | res = self.ser.call(self.session, method, arguments) | 86 | res = self.ser.call(self.session, method, arguments) |
125 | 87 | if self.debug: | 87 | if self.debug: |
126 | 88 | if method=='catalog_product.list': | 88 | if method=='catalog_product.list': |
127 | 89 | # the response of the method catalog_product.list can be very very long so it's better to see it only if debug log is activate | 89 | # the response of the method catalog_product.list can be very very long so it's better to see it only if debug log is activate |
129 | 90 | self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_DEBUG, _("Query Returned:%s") % (res)) | 90 | self.logger.debug(_("Query Returned:%s"), res) |
130 | 91 | else: | 91 | else: |
132 | 92 | self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Query Returned:%s") % (res)) | 92 | self.logger.info(_("Query Returned:%s"), res) |
133 | 93 | return res | 93 | return res |
134 | 94 | except IOError, e: | 94 | except IOError, e: |
137 | 95 | self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_ERROR, _("Method: %s\nArguments:%s\nError:%s") % (method, arguments, e)) | 95 | self.logger.error(_("Method: %s\nArguments:%s\nError:%s"), method, arguments, e, exc_info=True) |
138 | 96 | self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_WARNING, _("Webservice Failure, sleeping %s second before next attempt") % (sleep_time)) | 96 | self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time) |
139 | 97 | time.sleep(sleep_time) | 97 | time.sleep(sleep_time) |
140 | 98 | raise | 98 | raise |
141 | 99 | 99 | ||
142 | @@ -118,7 +118,7 @@ | |||
143 | 118 | _DELETE_METHOD = False | 118 | _DELETE_METHOD = False |
144 | 119 | _mapping = {} | 119 | _mapping = {} |
145 | 120 | DEBUG = False | 120 | DEBUG = False |
147 | 121 | 121 | ||
148 | 122 | #TODO deprecated, remove use | 122 | #TODO deprecated, remove use |
149 | 123 | def mage_to_oe(self, cr, uid, mageid, instance, *arguments): | 123 | def mage_to_oe(self, cr, uid, mageid, instance, *arguments): |
150 | 124 | """given a record id in the Magento referential, returns a tuple (id, name) with the id in the OpenERP referential; Magento instance wise""" | 124 | """given a record id in the Magento referential, returns a tuple (id, name) with the id in the OpenERP referential; Magento instance wise""" |
151 | @@ -143,7 +143,7 @@ | |||
152 | 143 | read = self.read(cr, uid, oeid, [self._rec_name]) | 143 | read = self.read(cr, uid, oeid, [self._rec_name]) |
153 | 144 | return (read[0]['id'], read[0][self._rec_name]) | 144 | return (read[0]['id'], read[0][self._rec_name]) |
154 | 145 | return False | 145 | return False |
156 | 146 | 146 | ||
157 | 147 | #TODO deprecated, remove use | 147 | #TODO deprecated, remove use |
158 | 148 | def sync_import(self, cr, uid, magento_records, instance, debug=False, defaults=None, *attrs): | 148 | def sync_import(self, cr, uid, magento_records, instance, debug=False, defaults=None, *attrs): |
159 | 149 | 149 | ||
160 | @@ -178,7 +178,7 @@ | |||
161 | 178 | 'temp_vars':{}, | 178 | 'temp_vars':{}, |
162 | 179 | 'mage2oe_filters':mage2oe_filters | 179 | 'mage2oe_filters':mage2oe_filters |
163 | 180 | } | 180 | } |
165 | 181 | 181 | ||
166 | 182 | #now properly mapp known Magento attributes to OpenERP entity columns: | 182 | #now properly mapp known Magento attributes to OpenERP entity columns: |
167 | 183 | for each_valid_key in self._mapping: | 183 | for each_valid_key in self._mapping: |
168 | 184 | if each_valid_key in magento_record.keys(): | 184 | if each_valid_key in magento_record.keys(): |
169 | @@ -216,7 +216,7 @@ | |||
170 | 216 | self.record_save(cr, uid, rec_id, vals, defaults) | 216 | self.record_save(cr, uid, rec_id, vals, defaults) |
171 | 217 | else: | 217 | else: |
172 | 218 | self.record_save(cr, uid, rec_id, vals, defaults) | 218 | self.record_save(cr, uid, rec_id, vals, defaults) |
174 | 219 | 219 | ||
175 | 220 | def record_save(self, cr, uid, rec_id, vals, defaults): | 220 | def record_save(self, cr, uid, rec_id, vals, defaults): |
176 | 221 | if defaults: | 221 | if defaults: |
177 | 222 | for key in defaults.keys(): | 222 | for key in defaults.keys(): |
178 | @@ -227,7 +227,7 @@ | |||
179 | 227 | else: | 227 | else: |
180 | 228 | #Record is not there, create it | 228 | #Record is not there, create it |
181 | 229 | self.create(cr, uid, vals,) | 229 | self.create(cr, uid, vals,) |
183 | 230 | 230 | ||
184 | 231 | def cast_string(self, subject): | 231 | def cast_string(self, subject): |
185 | 232 | """This function will convert string objects to the data type required. Example "0"/"1" to boolean conversion""" | 232 | """This function will convert string objects to the data type required. Example "0"/"1" to boolean conversion""" |
186 | 233 | for key in subject.keys(): | 233 | for key in subject.keys(): |
187 | @@ -237,7 +237,7 @@ | |||
188 | 237 | else: | 237 | else: |
189 | 238 | subject[key] = True | 238 | subject[key] = True |
190 | 239 | return subject | 239 | return subject |
192 | 240 | 240 | ||
193 | 241 | def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None): | 241 | def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None): |
194 | 242 | if context is None: | 242 | if context is None: |
195 | 243 | context = {} | 243 | context = {} |
196 | @@ -259,7 +259,7 @@ | |||
197 | 259 | list_method = self.pool.get('external.mapping').read(cr,uid,mapping_id[0],['external_list_method']).get('external_list_method',False) | 259 | list_method = self.pool.get('external.mapping').read(cr,uid,mapping_id[0],['external_list_method']).get('external_list_method',False) |
198 | 260 | if list_method: | 260 | if list_method: |
199 | 261 | data = conn.call(list_method, context['ids_or_filter']) | 261 | data = conn.call(list_method, context['ids_or_filter']) |
201 | 262 | 262 | ||
202 | 263 | #it may happen that list method doesn't provide enough information, forcing us to use get_method on each record (case for sale orders) | 263 | #it may happen that list method doesn't provide enough information, forcing us to use get_method on each record (case for sale orders) |
203 | 264 | if context.get('one_by_one', False): | 264 | if context.get('one_by_one', False): |
204 | 265 | self.mage_import_one_by_one(cr, uid, conn, external_referential_id, mapping_id[0], data, defaults, context) | 265 | self.mage_import_one_by_one(cr, uid, conn, external_referential_id, mapping_id[0], data, defaults, context) |
205 | @@ -337,7 +337,7 @@ | |||
206 | 337 | self.sync_import(cr, uid, magento_records, instance, debug, defaults) | 337 | self.sync_import(cr, uid, magento_records, instance, debug, defaults) |
207 | 338 | else: | 338 | else: |
208 | 339 | raise osv.except_osv(_('Undefined List method !'), _("list method is undefined for this object!")) | 339 | raise osv.except_osv(_('Undefined List method !'), _("list method is undefined for this object!")) |
210 | 340 | 340 | ||
211 | 341 | #TODO deprecated, remove use | 341 | #TODO deprecated, remove use |
212 | 342 | def get_all_mage_ids(self, cr, uid, ids, instance=False): | 342 | def get_all_mage_ids(self, cr, uid, ids, instance=False): |
213 | 343 | search_param = [] | 343 | search_param = [] |
214 | @@ -350,4 +350,4 @@ | |||
215 | 350 | for each in reads: | 350 | for each in reads: |
216 | 351 | mageids.append(each[self._MAGE_FIELD]) | 351 | mageids.append(each[self._MAGE_FIELD]) |
217 | 352 | return mageids | 352 | return mageids |
219 | 353 | 353 | ||
220 | 354 | 354 | ||
221 | === modified file 'magentoerpconnect/product.py' | |||
222 | --- magentoerpconnect/product.py 2012-05-16 14:02:43 +0000 | |||
223 | +++ magentoerpconnect/product.py 2012-05-25 09:04:23 +0000 | |||
224 | @@ -28,7 +28,7 @@ | |||
225 | 28 | import pooler | 28 | import pooler |
226 | 29 | import magerp_osv | 29 | import magerp_osv |
227 | 30 | from tools.translate import _ | 30 | from tools.translate import _ |
229 | 31 | import netsvc | 31 | import logging |
230 | 32 | import unicodedata | 32 | import unicodedata |
231 | 33 | import base64, urllib | 33 | import base64, urllib |
232 | 34 | import os | 34 | import os |
233 | @@ -293,7 +293,7 @@ | |||
234 | 293 | 293 | ||
235 | 294 | def init(self, cr): | 294 | def init(self, cr): |
236 | 295 | """ Replace product_product by product.product | 295 | """ Replace product_product by product.product |
238 | 296 | and product_template by product.template for | 296 | and product_template by product.template for |
239 | 297 | consistency with model names""" | 297 | consistency with model names""" |
240 | 298 | cr.execute("UPDATE magerp_product_attributes SET based_on = REPLACE(based_on, '_', '.')") | 298 | cr.execute("UPDATE magerp_product_attributes SET based_on = REPLACE(based_on, '_', '.')") |
241 | 299 | cr.execute("UPDATE magerp_product_attributes SET based_on = 'product.template' WHERE based_on IS NULL") | 299 | cr.execute("UPDATE magerp_product_attributes SET based_on = 'product.template' WHERE based_on IS NULL") |
242 | @@ -561,12 +561,11 @@ | |||
243 | 561 | " result = [('%(attribute_code)s', [option.value for option in options])]") % \ | 561 | " result = [('%(attribute_code)s', [option.value for option in options])]") % \ |
244 | 562 | ({'field_name': field_name, 'attribute_code': attribute.attribute_code}) | 562 | ({'field_name': field_name, 'attribute_code': attribute.attribute_code}) |
245 | 563 | elif ttype in ['binary']: | 563 | elif ttype in ['binary']: |
252 | 564 | logger = netsvc.Logger() | 564 | logger = logging.getLogger('ext synchro mapping') |
253 | 565 | warning_text = "Binary mapping is actually not supported (attribute: %s)" % (attribute.attribute_code,) | 565 | logger.warn("Binary mapping is actually not supported (attribute: %s)", attribute.attribute_code) |
254 | 566 | logger.notifyChannel('ext synchro mapping', netsvc.LOG_WARNING, warning_text) | 566 | warning_msg = ("import logging\n" |
255 | 567 | warning_msg = ("import netsvc\n" | 567 | "logger = logging.getLogger('ext synchro mapping')\n" |
256 | 568 | "logger = netsvc.Logger()\n" | 568 | "logger.warn('Binary mapping is actually not supported (attribute: %%s)', %s)") % (attribute.attribute_code) |
251 | 569 | "logger.notifyChannel('ext synchro mapping', netsvc.LOG_WARNING, '%s')") % (warning_text,) | ||
257 | 570 | in_function = out_function = warning_msg | 569 | in_function = out_function = warning_msg |
258 | 571 | return in_function, out_function | 570 | return in_function, out_function |
259 | 572 | 571 | ||
260 | @@ -682,7 +681,7 @@ | |||
261 | 682 | _name = "magerp.product_attribute_set" | 681 | _name = "magerp.product_attribute_set" |
262 | 683 | _description = "Attribute sets in products" | 682 | _description = "Attribute sets in products" |
263 | 684 | _rec_name = 'attribute_set_name' | 683 | _rec_name = 'attribute_set_name' |
265 | 685 | 684 | ||
266 | 686 | _columns = { | 685 | _columns = { |
267 | 687 | 'sort_order':fields.integer('Sort Order'), | 686 | 'sort_order':fields.integer('Sort Order'), |
268 | 688 | 'attribute_set_name':fields.char('Set Name', size=100), | 687 | 'attribute_set_name':fields.char('Set Name', size=100), |
269 | @@ -731,7 +730,7 @@ | |||
270 | 731 | cr.execute(query) | 730 | cr.execute(query) |
271 | 732 | 731 | ||
272 | 733 | return True | 732 | return True |
274 | 734 | 733 | ||
275 | 735 | magerp_product_attribute_set() | 734 | magerp_product_attribute_set() |
276 | 736 | 735 | ||
277 | 737 | class magerp_product_attribute_groups(magerp_osv.magerp_osv): | 736 | class magerp_product_attribute_groups(magerp_osv.magerp_osv): |
278 | @@ -744,7 +743,7 @@ | |||
279 | 744 | for attribute_group in self.browse(cr, uid, ids, context): | 743 | for attribute_group in self.browse(cr, uid, ids, context): |
280 | 745 | res[attribute_group.id] = self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, attribute_group.attribute_set_id, attribute_group.referential_id.id) | 744 | res[attribute_group.id] = self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, attribute_group.attribute_set_id, attribute_group.referential_id.id) |
281 | 746 | return res | 745 | return res |
283 | 747 | 746 | ||
284 | 748 | _columns = { | 747 | _columns = { |
285 | 749 | 'attribute_set_id':fields.integer('Attribute Set ID'), | 748 | 'attribute_set_id':fields.integer('Attribute Set ID'), |
286 | 750 | 'attribute_set':fields.function(_get_set, type="many2one", relation="magerp.product_attribute_set", method=True, string="Attribute Set"), | 749 | 'attribute_set':fields.function(_get_set, type="many2one", relation="magerp.product_attribute_set", method=True, string="Attribute Set"), |
287 | @@ -758,7 +757,7 @@ | |||
288 | 758 | class product_tierprice(osv.osv): | 757 | class product_tierprice(osv.osv): |
289 | 759 | _name = "product.tierprice" | 758 | _name = "product.tierprice" |
290 | 760 | _description = "Implements magento tier pricing" | 759 | _description = "Implements magento tier pricing" |
292 | 761 | 760 | ||
293 | 762 | _columns = { | 761 | _columns = { |
294 | 763 | 'web_scope':fields.selection([ | 762 | 'web_scope':fields.selection([ |
295 | 764 | ('all', 'All Websites'), | 763 | ('all', 'All Websites'), |
296 | @@ -799,7 +798,7 @@ | |||
297 | 799 | 798 | ||
298 | 800 | class product_mag_osv(magerp_osv.magerp_osv): | 799 | class product_mag_osv(magerp_osv.magerp_osv): |
299 | 801 | _register = False # Set to false if the model shouldn't be automatically discovered. | 800 | _register = False # Set to false if the model shouldn't be automatically discovered. |
301 | 802 | 801 | ||
302 | 803 | #remember one thing in life: Magento lies: it tells attributes are required while they are awkward to fill | 802 | #remember one thing in life: Magento lies: it tells attributes are required while they are awkward to fill |
303 | 804 | #and will have a nice default vaule anyway, that's why we avoid making them mandatory in the product view | 803 | #and will have a nice default vaule anyway, that's why we avoid making them mandatory in the product view |
304 | 805 | _magento_fake_mandatory_attrs = ['created_at', 'updated_at', 'has_options', 'required_options', 'model'] | 804 | _magento_fake_mandatory_attrs = ['created_at', 'updated_at', 'has_options', 'required_options', 'model'] |
305 | @@ -880,7 +879,7 @@ | |||
306 | 880 | cr, uid, oerp_group_id, | 879 | cr, uid, oerp_group_id, |
307 | 881 | ['attribute_group_name'], | 880 | ['attribute_group_name'], |
308 | 882 | context=context)['attribute_group_name'] | 881 | context=context)['attribute_group_name'] |
310 | 883 | 882 | ||
311 | 884 | # Create a page for each attribute group | 883 | # Create a page for each attribute group |
312 | 885 | attr_group_fields_rel.setdefault(group_name, []) | 884 | attr_group_fields_rel.setdefault(group_name, []) |
313 | 886 | while True: | 885 | while True: |
314 | @@ -954,7 +953,7 @@ | |||
315 | 954 | wf, fields_get['websites_ids'], context=context) | 953 | wf, fields_get['websites_ids'], context=context) |
316 | 955 | 954 | ||
317 | 956 | return notebook | 955 | return notebook |
319 | 957 | 956 | ||
320 | 958 | def _filter_fields_to_return(self, cr, uid, field_names, context=None): | 957 | def _filter_fields_to_return(self, cr, uid, field_names, context=None): |
321 | 959 | '''This function is a hook in order to filter the fields that appears on the view''' | 958 | '''This function is a hook in order to filter the fields that appears on the view''' |
322 | 960 | return field_names | 959 | return field_names |
323 | @@ -1067,13 +1066,13 @@ | |||
324 | 1067 | #TODO base the import on the mapping and the function ext_import | 1066 | #TODO base the import on the mapping and the function ext_import |
325 | 1068 | def import_product_image(self, cr, uid, id, referential_id, conn, ext_id=None, context=None): | 1067 | def import_product_image(self, cr, uid, id, referential_id, conn, ext_id=None, context=None): |
326 | 1069 | image_obj = self.pool.get('product.images') | 1068 | image_obj = self.pool.get('product.images') |
328 | 1070 | logger = netsvc.Logger() | 1069 | logger = logging.getLogger('ext synchro') |
329 | 1071 | if not ext_id: | 1070 | if not ext_id: |
330 | 1072 | ext_id = self.oeid_to_extid(cr, uid, id, referential_id, context=None) | 1071 | ext_id = self.oeid_to_extid(cr, uid, id, referential_id, context=None) |
332 | 1073 | # TODO everythere will should pass the params 'id' for magento api in order to force | 1072 | # TODO everythere will should pass the params 'id' for magento api in order to force |
333 | 1074 | # to use the id as external key instead of mixed id/sku | 1073 | # to use the id as external key instead of mixed id/sku |
334 | 1075 | img_list = conn.call('catalog_product_attribute_media.list', [ext_id, False, 'id']) | 1074 | img_list = conn.call('catalog_product_attribute_media.list', [ext_id, False, 'id']) |
336 | 1076 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Magento image for product ext_id %s: %s" %(ext_id, img_list)) | 1075 | logger.info("Magento image for product ext_id %s: %s", ext_id, img_list) |
337 | 1077 | images_name = [] | 1076 | images_name = [] |
338 | 1078 | for image in img_list: | 1077 | for image in img_list: |
339 | 1079 | img=False | 1078 | img=False |
340 | @@ -1083,13 +1082,13 @@ | |||
341 | 1083 | data = f.read() | 1082 | data = f.read() |
342 | 1084 | f.close() | 1083 | f.close() |
343 | 1085 | if "DOCTYPE html PUBLIC" in data: | 1084 | if "DOCTYPE html PUBLIC" in data: |
345 | 1086 | logger.notifyChannel('ext synchro', netsvc.LOG_WARNING, "failed to open the image %s from Magento" % (image['url'],)) | 1085 | logger.warn("Failed to open the image %s from Magento", image['url']) |
346 | 1087 | continue | 1086 | continue |
347 | 1088 | else: | 1087 | else: |
348 | 1089 | img = base64.encodestring(data) | 1088 | img = base64.encodestring(data) |
349 | 1090 | except Exception, e: | 1089 | except Exception, e: |
350 | 1091 | #TODO raise correctly the error | 1090 | #TODO raise correctly the error |
352 | 1092 | logger.notifyChannel('ext synchro', netsvc.LOG_WARNING, "failed to open the image %s from Magento, error : %s" % (image['url'],e)) | 1091 | logger.error("Failed to open the image %s from Magento, error : %s", image['url'], e, exc_info=True) |
353 | 1093 | continue | 1092 | continue |
354 | 1094 | mag_filename, extention = os.path.splitext(os.path.basename(image['file'])) | 1093 | mag_filename, extention = os.path.splitext(os.path.basename(image['file'])) |
355 | 1095 | data = {'name': image['label'] and not image['label'] in images_name and image['label'] or mag_filename, | 1094 | data = {'name': image['label'] and not image['label'] in images_name and image['label'] or mag_filename, |
356 | @@ -1115,7 +1114,7 @@ | |||
357 | 1115 | new_image_id = image_obj.create(cr, uid, data, context=context) | 1114 | new_image_id = image_obj.create(cr, uid, data, context=context) |
358 | 1116 | image_obj.create_external_id_vals(cr, uid, new_image_id, image['file'], referential_id, context=context) | 1115 | image_obj.create_external_id_vals(cr, uid, new_image_id, image['file'], referential_id, context=context) |
359 | 1117 | return True | 1116 | return True |
361 | 1118 | 1117 | ||
362 | 1119 | def extid_to_existing_oeid(self, cr, uid, id, external_referential_id, context=None): | 1118 | def extid_to_existing_oeid(self, cr, uid, id, external_referential_id, context=None): |
363 | 1120 | """Returns the OpenERP id of a resource by its external id. | 1119 | """Returns the OpenERP id of a resource by its external id. |
364 | 1121 | Returns False if the resource does not exist.""" | 1120 | Returns False if the resource does not exist.""" |
365 | @@ -1180,7 +1179,7 @@ | |||
366 | 1180 | else: | 1179 | else: |
367 | 1181 | return False | 1180 | return False |
368 | 1182 | tier_price = False | 1181 | tier_price = False |
370 | 1183 | if 'x_magerp_tier_price' in vals.keys(): | 1182 | if 'x_magerp_tier_price' in vals.keys(): |
371 | 1184 | tier_price = vals.pop('x_magerp_tier_price') | 1183 | tier_price = vals.pop('x_magerp_tier_price') |
372 | 1185 | tp_obj = self.pool.get('product.tierprice') | 1184 | tp_obj = self.pool.get('product.tierprice') |
373 | 1186 | #Delete existing tier prices | 1185 | #Delete existing tier prices |
374 | @@ -1193,7 +1192,7 @@ | |||
375 | 1193 | stat = super(product_product, self).write(cr, uid, ids, vals, context) | 1192 | stat = super(product_product, self).write(cr, uid, ids, vals, context) |
376 | 1194 | #Perform other operation | 1193 | #Perform other operation |
377 | 1195 | return stat | 1194 | return stat |
379 | 1196 | 1195 | ||
380 | 1197 | def create_tier_price(self, cr, uid, tier_price, instance, product_id): | 1196 | def create_tier_price(self, cr, uid, tier_price, instance, product_id): |
381 | 1198 | tp_obj = self.pool.get('product.tierprice') | 1197 | tp_obj = self.pool.get('product.tierprice') |
382 | 1199 | for each in eval(tier_price): | 1198 | for each in eval(tier_price): |
383 | @@ -1215,13 +1214,13 @@ | |||
384 | 1215 | tier_vals['web_scope'] = 'specific' | 1214 | tier_vals['web_scope'] = 'specific' |
385 | 1216 | tier_vals['website_id'] = self.pool.get('external.shop.group').mage_to_oe(cr, uid, int(each['website_id']), instance) | 1215 | tier_vals['website_id'] = self.pool.get('external.shop.group').mage_to_oe(cr, uid, int(each['website_id']), instance) |
386 | 1217 | tp_obj.create(cr, uid, tier_vals) | 1216 | tp_obj.create(cr, uid, tier_vals) |
388 | 1218 | 1217 | ||
389 | 1219 | def create(self, cr, uid, vals, context=None): | 1218 | def create(self, cr, uid, vals, context=None): |
390 | 1220 | tier_price = False | 1219 | tier_price = False |
391 | 1221 | if vals.get('referential_id', False): | 1220 | if vals.get('referential_id', False): |
392 | 1222 | instance = vals['referential_id'] | 1221 | instance = vals['referential_id'] |
393 | 1223 | #Filter keys to be changed | 1222 | #Filter keys to be changed |
395 | 1224 | if 'x_magerp_tier_price' in vals.keys(): | 1223 | if 'x_magerp_tier_price' in vals.keys(): |
396 | 1225 | tier_price = vals.pop('x_magerp_tier_price') | 1224 | tier_price = vals.pop('x_magerp_tier_price') |
397 | 1226 | 1225 | ||
398 | 1227 | crid = super(product_product, self).create(cr, uid, vals, context) | 1226 | crid = super(product_product, self).create(cr, uid, vals, context) |
399 | @@ -1262,7 +1261,7 @@ | |||
400 | 1262 | raise osv.except_osv(_('Warning!'), _('This product is related to Magento. It can not be deleted!\nYou can change it Magento status to "Disabled" and uncheck the active box to hide it from OpenERP.')) | 1261 | raise osv.except_osv(_('Warning!'), _('This product is related to Magento. It can not be deleted!\nYou can change it Magento status to "Disabled" and uncheck the active box to hide it from OpenERP.')) |
401 | 1263 | else: | 1262 | else: |
402 | 1264 | return super(product_product, self).unlink(cr, uid, ids, context) | 1263 | return super(product_product, self).unlink(cr, uid, ids, context) |
404 | 1265 | 1264 | ||
405 | 1266 | #TODO move part of this to declarative mapping CSV template | 1265 | #TODO move part of this to declarative mapping CSV template |
406 | 1267 | def extdata_from_oevals(self, cr, uid, external_referential_id, data_record, mapping_lines, defaults, context=None): | 1266 | def extdata_from_oevals(self, cr, uid, external_referential_id, data_record, mapping_lines, defaults, context=None): |
407 | 1268 | product_data = super(product_product, self).extdata_from_oevals(cr, uid, external_referential_id, data_record, mapping_lines, defaults, context) #Aapply custom/attributes mappings | 1267 | product_data = super(product_product, self).extdata_from_oevals(cr, uid, external_referential_id, data_record, mapping_lines, defaults, context) #Aapply custom/attributes mappings |
408 | @@ -1275,10 +1274,10 @@ | |||
409 | 1275 | if isinstance(pl_default_id, int): | 1274 | if isinstance(pl_default_id, int): |
410 | 1276 | pl_default_id = [pl_default_id] | 1275 | pl_default_id = [pl_default_id] |
411 | 1277 | product_data.update({'price': self.pool.get('product.pricelist').price_get(cr, uid, pl_default_id, product.id, 1.0)[pl_default_id[0]]}) | 1276 | product_data.update({'price': self.pool.get('product.pricelist').price_get(cr, uid, pl_default_id, product.id, 1.0)[pl_default_id[0]]}) |
413 | 1278 | 1277 | ||
414 | 1279 | if not product_data.get('tax_class_id', False): | 1278 | if not product_data.get('tax_class_id', False): |
415 | 1280 | product_data.update({'tax_class_id': 2}) #FIXME hugly! | 1279 | product_data.update({'tax_class_id': 2}) #FIXME hugly! |
417 | 1281 | 1280 | ||
418 | 1282 | if not product_data.get('status', False): | 1281 | if not product_data.get('status', False): |
419 | 1283 | product_data.update({'status': product.active and 1 or 0}) | 1282 | product_data.update({'status': product.active and 1 or 0}) |
420 | 1284 | 1283 | ||
421 | @@ -1292,7 +1291,7 @@ | |||
422 | 1292 | product_data.update({'meta_keyword': product.name}) | 1291 | product_data.update({'meta_keyword': product.name}) |
423 | 1293 | if not product_data.get('meta_description', False): | 1292 | if not product_data.get('meta_description', False): |
424 | 1294 | product_data.update({'meta_description': product.description_sale and product.description_sale[:255]}) | 1293 | product_data.update({'meta_description': product.description_sale and product.description_sale[:255]}) |
426 | 1295 | 1294 | ||
427 | 1296 | return product_data | 1295 | return product_data |
428 | 1297 | 1296 | ||
429 | 1298 | def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, mapping_lines, key_for_external_id=None, parent_data=None, previous_lines=None, defaults=None, context=None): | 1297 | def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, mapping_lines, key_for_external_id=None, parent_data=None, previous_lines=None, defaults=None, context=None): |
430 | @@ -1350,7 +1349,7 @@ | |||
431 | 1350 | return ext_id | 1349 | return ext_id |
432 | 1351 | 1350 | ||
433 | 1352 | def action_before_exporting_grouped_product(self, cr, uid, id, external_referential_ids=None, defaults=None, context=None): | 1351 | def action_before_exporting_grouped_product(self, cr, uid, id, external_referential_ids=None, defaults=None, context=None): |
435 | 1353 | logger = netsvc.Logger() | 1352 | logger = logging.getLogger('ext synchro') |
436 | 1354 | if context.get('mrp_is_installed', False): | 1353 | if context.get('mrp_is_installed', False): |
437 | 1355 | bom_ids = self.read(cr, uid, id, ['bom_ids'])['bom_ids'] | 1354 | bom_ids = self.read(cr, uid, id, ['bom_ids'])['bom_ids'] |
438 | 1356 | if len(bom_ids): # it has or is part of a BoM | 1355 | if len(bom_ids): # it has or is part of a BoM |
439 | @@ -1361,18 +1360,18 @@ | |||
440 | 1361 | for row in results: | 1360 | for row in results: |
441 | 1362 | child_ids.append(row['product_id']) | 1361 | child_ids.append(row['product_id']) |
442 | 1363 | quantities.update({row['product_id']: row['product_qty']}) | 1362 | quantities.update({row['product_id']: row['product_qty']}) |
444 | 1364 | if child_ids: #it is an assembly and it contains the products child_ids: | 1363 | if child_ids: #it is an assembly and it contains the products child_ids: |
445 | 1365 | self.ext_export(cr, uid, child_ids, external_referential_ids, defaults, context) #so we export them | 1364 | self.ext_export(cr, uid, child_ids, external_referential_ids, defaults, context) #so we export them |
446 | 1366 | else: | 1365 | else: |
447 | 1367 | return False | 1366 | return False |
448 | 1368 | else: | 1367 | else: |
450 | 1369 | logger.notifyChannel('ext synchro', netsvc.LOG_ERROR, "OpenERP 'grouped' products will export to Magento as 'grouped products' only if they have a BOM and if the 'mrp' BOM module is installed") | 1368 | logger.error("OpenERP 'grouped' products will export to Magento as 'grouped products' only if they have a BOM and if the 'mrp' BOM module is installed") |
451 | 1370 | return quantities, child_ids | 1369 | return quantities, child_ids |
452 | 1371 | 1370 | ||
453 | 1372 | def action_before_exporting(self, cr, uid, id, product_type, external_referential_ids=None, defaults=None, context=None): | 1371 | def action_before_exporting(self, cr, uid, id, product_type, external_referential_ids=None, defaults=None, context=None): |
454 | 1373 | '''Hook to allow your external module to execute some code before exporting a product''' | 1372 | '''Hook to allow your external module to execute some code before exporting a product''' |
455 | 1374 | return True | 1373 | return True |
457 | 1375 | 1374 | ||
458 | 1376 | #todo move this code to a generic module | 1375 | #todo move this code to a generic module |
459 | 1377 | def get_last_update_date(self, cr, uid, product_read, context=None): | 1376 | def get_last_update_date(self, cr, uid, product_read, context=None): |
460 | 1378 | """if a product have a depends on other object like bom for grouped product, or other product for configurable | 1377 | """if a product have a depends on other object like bom for grouped product, or other product for configurable |
461 | @@ -1389,10 +1388,10 @@ | |||
462 | 1389 | if last_updated_bom_date > last_updated_date: | 1388 | if last_updated_bom_date > last_updated_date: |
463 | 1390 | last_updated_date=last_updated_bom_date | 1389 | last_updated_date=last_updated_bom_date |
464 | 1391 | else: | 1390 | else: |
466 | 1392 | conn.logger.notifyChannel('ext synchro', netsvc.LOG_ERROR, "OpenERP 'grouped' products will export to Magento as 'grouped products' only if they have a BOM and if the 'mrp' BOM module is installed") | 1391 | conn.logger.error("OpenERP 'grouped' products will export to Magento as 'grouped products' only if they have a BOM and if the 'mrp' BOM module is installed") |
467 | 1393 | return last_updated_date | 1392 | return last_updated_date |
470 | 1394 | 1393 | ||
471 | 1395 | 1394 | ||
472 | 1396 | def get_ordered_ids(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): | 1395 | def get_ordered_ids(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): |
473 | 1397 | #TODO pass the shop better than the referentials | 1396 | #TODO pass the shop better than the referentials |
474 | 1398 | dates_2_ids = [] | 1397 | dates_2_ids = [] |
475 | @@ -1408,7 +1407,7 @@ | |||
476 | 1408 | read = cr.dictfetchall() | 1407 | read = cr.dictfetchall() |
477 | 1409 | ids = [] | 1408 | ids = [] |
478 | 1410 | context['force']=True | 1409 | context['force']=True |
480 | 1411 | 1410 | ||
481 | 1412 | for product_read in read: | 1411 | for product_read in read: |
482 | 1413 | last_updated_date = self.get_last_update_date(cr, uid, product_read, context=context) | 1412 | last_updated_date = self.get_last_update_date(cr, uid, product_read, context=context) |
483 | 1414 | if last_exported_date and last_updated_date < last_exported_date: | 1413 | if last_exported_date and last_updated_date < last_exported_date: |
484 | @@ -1474,7 +1473,7 @@ | |||
485 | 1474 | context['default_set_id'] = default_set_id | 1473 | context['default_set_id'] = default_set_id |
486 | 1475 | 1474 | ||
487 | 1476 | context_dic = [context.copy()] | 1475 | context_dic = [context.copy()] |
489 | 1477 | context_dic[0]['export_url'] = True # for the magento version 1.3.2.4, only one url is autorized by product, so we only export with the MAPPING TEMPLATE the url of the default language | 1476 | context_dic[0]['export_url'] = True # for the magento version 1.3.2.4, only one url is autorized by product, so we only export with the MAPPING TEMPLATE the url of the default language |
490 | 1478 | context_dic[0]['lang'] = shop.referential_id.default_lang_id.code | 1477 | context_dic[0]['lang'] = shop.referential_id.default_lang_id.code |
491 | 1479 | 1478 | ||
492 | 1480 | for storeview in shop.storeview_ids: | 1479 | for storeview in shop.storeview_ids: |
493 | @@ -1499,14 +1498,14 @@ | |||
494 | 1499 | result['create_ids'] += temp_result['create_ids'] | 1498 | result['create_ids'] += temp_result['create_ids'] |
495 | 1500 | result['write_ids'] += temp_result['write_ids'] | 1499 | result['write_ids'] += temp_result['write_ids'] |
496 | 1501 | return result | 1500 | return result |
498 | 1502 | 1501 | ||
499 | 1503 | def try_ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None): | 1502 | def try_ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None): |
500 | 1504 | if context is None: context = {} | 1503 | if context is None: context = {} |
501 | 1505 | if context.get('storeview_code', False): | 1504 | if context.get('storeview_code', False): |
502 | 1506 | return conn.call(method, [external_id, data, context.get('storeview_code', False)]) | 1505 | return conn.call(method, [external_id, data, context.get('storeview_code', False)]) |
503 | 1507 | else: | 1506 | else: |
504 | 1508 | return conn.call(method, [external_id, data]) | 1507 | return conn.call(method, [external_id, data]) |
506 | 1509 | 1508 | ||
507 | 1510 | def ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None): | 1509 | def ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None): |
508 | 1511 | product = self.browse(cr, uid, oe_id) | 1510 | product = self.browse(cr, uid, oe_id) |
509 | 1512 | sku = self.product_to_sku(cr, uid, product) | 1511 | sku = self.product_to_sku(cr, uid, product) |
510 | @@ -1544,7 +1543,7 @@ | |||
511 | 1544 | :return: True | 1543 | :return: True |
512 | 1545 | """ | 1544 | """ |
513 | 1546 | if context is None: context = {} | 1545 | if context is None: context = {} |
515 | 1547 | logger = netsvc.Logger() | 1546 | logger = logging.getLogger('ext synchro') |
516 | 1548 | 1547 | ||
517 | 1549 | shop = self.pool.get('sale.shop').browse( | 1548 | shop = self.pool.get('sale.shop').browse( |
518 | 1550 | cr, uid, shop_id, context=context) | 1549 | cr, uid, shop_id, context=context) |
519 | @@ -1577,14 +1576,13 @@ | |||
520 | 1577 | connection.call('product_stock.update', | 1576 | connection.call('product_stock.update', |
521 | 1578 | [mag_product_id, inventory_vals]) | 1577 | [mag_product_id, inventory_vals]) |
522 | 1579 | 1578 | ||
529 | 1580 | logger.notifyChannel( | 1579 | logger.info( |
530 | 1581 | 'ext synchro', | 1580 | "Successfully updated stock level at %s for product with SKU %s", |
531 | 1582 | netsvc.LOG_INFO, | 1581 | inventory_vals.get('qty', 'N/A'), |
532 | 1583 | "Successfully updated stock level at %s for " | 1582 | product.magento_sku |
533 | 1584 | "product with SKU %s " % | 1583 | ) |
528 | 1585 | (inventory_vals.get('qty', 'N/A'), product.magento_sku)) | ||
534 | 1586 | return True | 1584 | return True |
536 | 1587 | 1585 | ||
537 | 1588 | def ext_assign_links(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): | 1586 | def ext_assign_links(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): |
538 | 1589 | """ Assign links of type up-sell, cross-sell, related """ | 1587 | """ Assign links of type up-sell, cross-sell, related """ |
539 | 1590 | if isinstance(ids, (int, long)): | 1588 | if isinstance(ids, (int, long)): |
540 | @@ -1607,7 +1605,7 @@ | |||
541 | 1607 | position = position or {} | 1605 | position = position or {} |
542 | 1608 | quantities = quantities or {} | 1606 | quantities = quantities or {} |
543 | 1609 | external_referential_ids = external_referential_ids or [] | 1607 | external_referential_ids = external_referential_ids or [] |
545 | 1610 | logger = netsvc.Logger() | 1608 | logger = logging.getLogger('ext assign') |
546 | 1611 | conn = context.get('conn_obj', False) | 1609 | conn = context.get('conn_obj', False) |
547 | 1612 | 1610 | ||
548 | 1613 | for ref_id in external_referential_ids: | 1611 | for ref_id in external_referential_ids: |
549 | @@ -1662,7 +1660,7 @@ | |||
550 | 1662 | for c_ext_id in ext_id_to_remove: | 1660 | for c_ext_id in ext_id_to_remove: |
551 | 1663 | # remove the product links that are no more setup on openerp | 1661 | # remove the product links that are no more setup on openerp |
552 | 1664 | conn.call('product_link.remove', magento_args + [c_ext_id]) | 1662 | conn.call('product_link.remove', magento_args + [c_ext_id]) |
554 | 1665 | logger.notifyChannel('ext assign', netsvc.LOG_INFO, "Successfully removed assignment of type %s for product %s to product %s" % (type, skus[parent_id], c_ext_id)) | 1663 | logger.info("Successfully removed assignment of type %s for product %s to product %s", type, skus[parent_id], c_ext_id) |
555 | 1666 | for child_ext_id in ext_id_to_assign: | 1664 | for child_ext_id in ext_id_to_assign: |
556 | 1667 | # assign new product links | 1665 | # assign new product links |
557 | 1668 | product_id = new_child_ext_ids[child_ext_id] | 1666 | product_id = new_child_ext_ids[child_ext_id] |
558 | @@ -1671,7 +1669,7 @@ | |||
559 | 1671 | [child_ext_id, | 1669 | [child_ext_id, |
560 | 1672 | {'position': position.get(product_id, 0), | 1670 | {'position': position.get(product_id, 0), |
561 | 1673 | 'qty': quantities.get(product_id, 1)}]) | 1671 | 'qty': quantities.get(product_id, 1)}]) |
563 | 1674 | logger.notifyChannel('ext assign', netsvc.LOG_INFO, "Successfully assigned product %s to product %s with type %s" %(skus[parent_id], skus[product_id], type)) | 1672 | logger.info("Successfully assigned product %s to product %s with type %s", skus[parent_id], skus[product_id], type) |
564 | 1675 | for child_ext_id in ext_id_to_update: | 1673 | for child_ext_id in ext_id_to_update: |
565 | 1676 | # update products links already assigned | 1674 | # update products links already assigned |
566 | 1677 | product_id = new_child_ext_ids[child_ext_id] | 1675 | product_id = new_child_ext_ids[child_ext_id] |
567 | @@ -1680,7 +1678,7 @@ | |||
568 | 1680 | [child_ext_id, | 1678 | [child_ext_id, |
569 | 1681 | {'position': position.get(product_id, 0), | 1679 | {'position': position.get(product_id, 0), |
570 | 1682 | 'qty': quantities.get(product_id, 1)}]) | 1680 | 'qty': quantities.get(product_id, 1)}]) |
572 | 1683 | logger.notifyChannel('ext assign', netsvc.LOG_INFO, "Successfully updated assignment of type %s of product %s to product %s" %(type, skus[parent_id], skus[product_id])) | 1681 | logger.info("Successfully updated assignment of type %s of product %s to product %s", type, skus[parent_id], skus[product_id]) |
573 | 1684 | return True | 1682 | return True |
574 | 1685 | 1683 | ||
575 | 1686 | #TODO move this code (get exportable image) and also some code in product_image.py and sale.py in base_sale_multichannel or in a new module in order to be more generic | 1684 | #TODO move this code (get exportable image) and also some code in product_image.py and sale.py in base_sale_multichannel or in a new module in order to be more generic |
576 | @@ -1696,7 +1694,7 @@ | |||
577 | 1696 | 1694 | ||
578 | 1697 | def _mag_import_product_links_type(self, cr, uid, product, link_type, external_referential_id, conn, context=None): | 1695 | def _mag_import_product_links_type(self, cr, uid, product, link_type, external_referential_id, conn, context=None): |
579 | 1698 | if context is None: context = {} | 1696 | if context is None: context = {} |
581 | 1699 | logger = netsvc.Logger() | 1697 | logger = logging.getLogger('ext synchro') |
582 | 1700 | product_link_obj = self.pool.get('product.link') | 1698 | product_link_obj = self.pool.get('product.link') |
583 | 1701 | selection_link_types = product_link_obj._columns['type'].selection(cr, uid, context) | 1699 | selection_link_types = product_link_obj._columns['type'].selection(cr, uid, context) |
584 | 1702 | # This method could be completed to import grouped products too, you know, for Magento a product link is as | 1700 | # This method could be completed to import grouped products too, you know, for Magento a product link is as |
585 | @@ -1707,7 +1705,7 @@ | |||
586 | 1707 | product_links = conn.call('product_link.list', [link_type, product.magento_sku]) | 1705 | product_links = conn.call('product_link.list', [link_type, product.magento_sku]) |
587 | 1708 | except Exception, e: | 1706 | except Exception, e: |
588 | 1709 | self.log(cr, uid, product.id, "Error when retrieving the list of links in Magento for product with sku %s and product id %s !" % (product.magento_sku, product.id,)) | 1707 | self.log(cr, uid, product.id, "Error when retrieving the list of links in Magento for product with sku %s and product id %s !" % (product.magento_sku, product.id,)) |
590 | 1710 | logger.notifyChannel('ext synchro', netsvc.LOG_DEBUG, "Error when retrieving the list of links in Magento for product with sku %s and product id %s !" % (product.magento_sku, product.id,)) | 1708 | logger.debug("Error when retrieving the list of links in Magento for product with sku %s and product id %s !", product.magento_sku, product.id) |
591 | 1711 | 1709 | ||
592 | 1712 | for product_link in product_links: | 1710 | for product_link in product_links: |
593 | 1713 | ctx = context.copy() | 1711 | ctx = context.copy() |
594 | @@ -1729,7 +1727,7 @@ | |||
595 | 1729 | product_link_obj.write(cr, uid, existing_link, link_data, context=context) | 1727 | product_link_obj.write(cr, uid, existing_link, link_data, context=context) |
596 | 1730 | else: | 1728 | else: |
597 | 1731 | product_link_obj.create(cr, uid, link_data, context=context) | 1729 | product_link_obj.create(cr, uid, link_data, context=context) |
599 | 1732 | logger.notifyChannel('Import Product Links', netsvc.LOG_INFO, "Successfully imported product link of type %s on product %s to product %s" %(link_type, product.id, linked_product_id)) | 1730 | logger.info("Successfully imported product link of type %s on product %s to product %s", link_type, product.id, linked_product_id) |
600 | 1733 | return True | 1731 | return True |
601 | 1734 | 1732 | ||
602 | 1735 | def mag_import_product_links_types(self, cr, uid, ids, link_types, external_referential_id, conn, context=None): | 1733 | def mag_import_product_links_types(self, cr, uid, ids, link_types, external_referential_id, conn, context=None): |
603 | 1736 | 1734 | ||
604 | === modified file 'magentoerpconnect/product_images.py' | |||
605 | --- magentoerpconnect/product_images.py 2011-11-27 15:12:39 +0000 | |||
606 | +++ magentoerpconnect/product_images.py 2012-05-25 09:04:23 +0000 | |||
607 | @@ -23,7 +23,7 @@ | |||
608 | 23 | from osv import osv, fields | 23 | from osv import osv, fields |
609 | 24 | import magerp_osv | 24 | import magerp_osv |
610 | 25 | import mimetypes | 25 | import mimetypes |
612 | 26 | import netsvc | 26 | import logging |
613 | 27 | from tools.translate import _ | 27 | from tools.translate import _ |
614 | 28 | 28 | ||
615 | 29 | #TODO the option small_image, thumbnail, exclude, base_image, should be store diferently indeed this is not compatible with mutli instance (maybe serialized will be a good solution) | 29 | #TODO the option small_image, thumbnail, exclude, base_image, should be store diferently indeed this is not compatible with mutli instance (maybe serialized will be a good solution) |
616 | @@ -48,12 +48,12 @@ | |||
617 | 48 | 'thumbnail':lambda * a:True, | 48 | 'thumbnail':lambda * a:True, |
618 | 49 | 'exclude':lambda * a:False | 49 | 'exclude':lambda * a:False |
619 | 50 | } | 50 | } |
621 | 51 | 51 | ||
622 | 52 | def get_changed_ids(self, cr, uid, start_date=False): | 52 | def get_changed_ids(self, cr, uid, start_date=False): |
623 | 53 | proxy = self.pool.get('product.images') | 53 | proxy = self.pool.get('product.images') |
624 | 54 | domain = start_date and ['|', ('create_date', '>', start_date), ('write_date', '>', start_date)] or [] | 54 | domain = start_date and ['|', ('create_date', '>', start_date), ('write_date', '>', start_date)] or [] |
625 | 55 | return proxy.search(cr, uid, domain) | 55 | return proxy.search(cr, uid, domain) |
627 | 56 | 56 | ||
628 | 57 | def del_image_name(self, cr, uid, id, context=None): | 57 | def del_image_name(self, cr, uid, id, context=None): |
629 | 58 | if context is None: context = {} | 58 | if context is None: context = {} |
630 | 59 | image_ext_name_obj = self.pool.get('product.images.external.name') | 59 | image_ext_name_obj = self.pool.get('product.images.external.name') |
631 | @@ -65,7 +65,7 @@ | |||
632 | 65 | def update_remote_images(self, cr, uid, ids, context=None): | 65 | def update_remote_images(self, cr, uid, ids, context=None): |
633 | 66 | if context is None: | 66 | if context is None: |
634 | 67 | context = {} | 67 | context = {} |
636 | 68 | logger = netsvc.Logger() | 68 | logger = logging.getLogger('ext synchro') |
637 | 69 | conn = context.get('conn_obj', False) | 69 | conn = context.get('conn_obj', False) |
638 | 70 | if not conn: | 70 | if not conn: |
639 | 71 | return False | 71 | return False |
640 | @@ -112,7 +112,7 @@ | |||
641 | 112 | image_2_date[image['id']] = image['write_date'] or image['create_date'] | 112 | image_2_date[image['id']] = image['write_date'] or image['create_date'] |
642 | 113 | list_date = date_2_image.keys() | 113 | list_date = date_2_image.keys() |
643 | 114 | list_date.sort() | 114 | list_date.sort() |
645 | 115 | 115 | ||
646 | 116 | ids = [date_2_image[date] for date in list_date] | 116 | ids = [date_2_image[date] for date in list_date] |
647 | 117 | 117 | ||
648 | 118 | while ids: | 118 | while ids: |
649 | @@ -122,24 +122,24 @@ | |||
650 | 122 | ext_file_name = each.oeid_to_extid(context['external_referential_id']) | 122 | ext_file_name = each.oeid_to_extid(context['external_referential_id']) |
651 | 123 | if ext_file_name: #If update | 123 | if ext_file_name: #If update |
652 | 124 | try: | 124 | try: |
654 | 125 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Updating %s's image: %s" %(each.product_id.magento_sku, each.name)) | 125 | logger.info("Updating %s's image: %s", each.product_id.magento_sku, each.name) |
655 | 126 | result = update_image(ext_file_name, each) | 126 | result = update_image(ext_file_name, each) |
657 | 127 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "%s's image updated with sucess: %s" %(each.product_id.magento_sku, each.name)) | 127 | logger.info("%s's image updated with sucess: %s", each.product_id.magento_sku, each.name) |
658 | 128 | need_to_be_created = False | 128 | need_to_be_created = False |
659 | 129 | except Exception, e: | 129 | except Exception, e: |
661 | 130 | logger.notifyChannel(_("Magento Connection"), netsvc.LOG_ERROR, _("Error in connecting:%s") % (e)) | 130 | logger.error(_("Error in connecting:%s"), e, exc_info=True) |
662 | 131 | if not "Fault 103" in str(e): | 131 | if not "Fault 103" in str(e): |
664 | 132 | logger.notifyChannel(_("Magento Connection"), netsvc.LOG_ERROR, _("Unknow error stop export")) | 132 | logger.error(_("Unknow error stop export")) |
665 | 133 | raise | 133 | raise |
666 | 134 | else: | 134 | else: |
667 | 135 | #If the image was deleded in magento, the external name is automatically deleded before trying to re-create the image in magento | 135 | #If the image was deleded in magento, the external name is automatically deleded before trying to re-create the image in magento |
668 | 136 | model_data_ids = ir_model_data_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', each.id), ('external_referential_id', '=', context['external_referential_id'])]) | 136 | model_data_ids = ir_model_data_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', each.id), ('external_referential_id', '=', context['external_referential_id'])]) |
669 | 137 | if model_data_ids and len(model_data_ids) > 0: | 137 | if model_data_ids and len(model_data_ids) > 0: |
670 | 138 | ir_model_data_obj.unlink(cr, uid, model_data_ids, context=context) | 138 | ir_model_data_obj.unlink(cr, uid, model_data_ids, context=context) |
672 | 139 | logger.notifyChannel(_("Magento Connection"), netsvc.LOG_ERROR, _("The image don't exist in magento, try to create it")) | 139 | logger.error(_("The image don't exist in magento, try to create it")) |
673 | 140 | if need_to_be_created: | 140 | if need_to_be_created: |
674 | 141 | if each.product_id.magento_sku: | 141 | if each.product_id.magento_sku: |
676 | 142 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Sending %s's image: %s" %(each.product_id.magento_sku, each.name)) | 142 | logger.info("Sending %s's image: %s", each.product_id.magento_sku, each.name) |
677 | 143 | result = conn.call('catalog_product_attribute_media.create', | 143 | result = conn.call('catalog_product_attribute_media.create', |
678 | 144 | [each.product_id.magento_sku, | 144 | [each.product_id.magento_sku, |
679 | 145 | {'file':{ | 145 | {'file':{ |
680 | @@ -151,12 +151,12 @@ | |||
681 | 151 | ]) | 151 | ]) |
682 | 152 | self.create_external_id_vals(cr, uid, each.id, result, context['external_referential_id'], context=context) | 152 | self.create_external_id_vals(cr, uid, each.id, result, context['external_referential_id'], context=context) |
683 | 153 | result = update_image(result, each) | 153 | result = update_image(result, each) |
685 | 154 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "%s's image send with sucess: %s" %(each.product_id.magento_sku, each.name)) | 154 | logger.info("%s's image send with sucess: %s", each.product_id.magento_sku, each.name) |
686 | 155 | if image_2_date[each.id] > context['last_images_export_date']: #indeed if a product was created a long time ago and checked as exportable recently, the write date of the image can be far away in the past | 155 | if image_2_date[each.id] > context['last_images_export_date']: #indeed if a product was created a long time ago and checked as exportable recently, the write date of the image can be far away in the past |
687 | 156 | self.pool.get('sale.shop').write(cr,uid,context['shop_id'],{'last_images_export_date':image_2_date[each.id]}) | 156 | self.pool.get('sale.shop').write(cr,uid,context['shop_id'],{'last_images_export_date':image_2_date[each.id]}) |
688 | 157 | cr.commit() | 157 | cr.commit() |
689 | 158 | ids = ids[1000:] | 158 | ids = ids[1000:] |
691 | 159 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "still %s image to export" %len(ids)) | 159 | logger.info("still %s image to export", len(ids)) |
692 | 160 | return True | 160 | return True |
694 | 161 | 161 | ||
695 | 162 | product_images() | 162 | product_images() |
696 | 163 | 163 | ||
697 | === modified file 'magentoerpconnect/sale.py' | |||
698 | --- magentoerpconnect/sale.py 2012-05-24 19:33:15 +0000 | |||
699 | +++ magentoerpconnect/sale.py 2012-05-25 09:04:23 +0000 | |||
700 | @@ -26,6 +26,7 @@ | |||
701 | 26 | import pooler | 26 | import pooler |
702 | 27 | import magerp_osv | 27 | import magerp_osv |
703 | 28 | import netsvc | 28 | import netsvc |
704 | 29 | import logging | ||
705 | 29 | from tools.translate import _ | 30 | from tools.translate import _ |
706 | 30 | import string | 31 | import string |
707 | 31 | #from datetime import datetime | 32 | #from datetime import datetime |
708 | @@ -50,7 +51,7 @@ | |||
709 | 50 | 51 | ||
710 | 51 | class sale_shop(magerp_osv.magerp_osv): | 52 | class sale_shop(magerp_osv.magerp_osv): |
711 | 52 | _inherit = "sale.shop" | 53 | _inherit = "sale.shop" |
713 | 53 | 54 | ||
714 | 54 | def _get_exportable_product_ids(self, cr, uid, ids, name, args, context=None): | 55 | def _get_exportable_product_ids(self, cr, uid, ids, name, args, context=None): |
715 | 55 | res = super(sale_shop, self)._get_exportable_product_ids(cr, uid, ids, name, args, context=None) | 56 | res = super(sale_shop, self)._get_exportable_product_ids(cr, uid, ids, name, args, context=None) |
716 | 56 | for shop_id in res: | 57 | for shop_id in res: |
717 | @@ -70,10 +71,10 @@ | |||
718 | 70 | else: | 71 | else: |
719 | 71 | res[shop.id] = False | 72 | res[shop.id] = False |
720 | 72 | return res | 73 | return res |
722 | 73 | 74 | ||
723 | 74 | def export_images(self, cr, uid, ids, context=None): | 75 | def export_images(self, cr, uid, ids, context=None): |
724 | 75 | if context is None: context = {} | 76 | if context is None: context = {} |
726 | 76 | logger = netsvc.Logger() | 77 | logger = logging.getLogger('ext synchro') |
727 | 77 | start_date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) | 78 | start_date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) |
728 | 78 | image_obj = self.pool.get('product.images') | 79 | image_obj = self.pool.get('product.images') |
729 | 79 | for shop in self.browse(cr, uid, ids): | 80 | for shop in self.browse(cr, uid, ids): |
730 | @@ -84,13 +85,13 @@ | |||
731 | 84 | exportable_product_ids = self.read(cr, uid, shop.id, ['exportable_product_ids'], context=context)['exportable_product_ids'] | 85 | exportable_product_ids = self.read(cr, uid, shop.id, ['exportable_product_ids'], context=context)['exportable_product_ids'] |
732 | 85 | res = self.pool.get('product.product').get_exportable_images(cr, uid, exportable_product_ids, context=context) | 86 | res = self.pool.get('product.product').get_exportable_images(cr, uid, exportable_product_ids, context=context) |
733 | 86 | if res: | 87 | if res: |
736 | 87 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Creating %s images" %(len(res['to_create']))) | 88 | logger.info("Creating %s images", len(res['to_create'])) |
737 | 88 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Updating %s images" %(len(res['to_update']))) | 89 | logger.info("Updating %s images", len(res['to_update'])) |
738 | 89 | image_obj.update_remote_images(cr, uid, res['to_update']+res['to_create'], context) | 90 | image_obj.update_remote_images(cr, uid, res['to_update']+res['to_create'], context) |
739 | 90 | self.write(cr,uid,context['shop_id'],{'last_images_export_date': start_date}) | 91 | self.write(cr,uid,context['shop_id'],{'last_images_export_date': start_date}) |
740 | 91 | return True | 92 | return True |
743 | 92 | 93 | ||
744 | 93 | 94 | ||
745 | 94 | def _get_rootcategory(self, cr, uid, ids, prop, unknow_none, context=None): | 95 | def _get_rootcategory(self, cr, uid, ids, prop, unknow_none, context=None): |
746 | 95 | res = {} | 96 | res = {} |
747 | 96 | for shop in self.browse(cr, uid, ids, context): | 97 | for shop in self.browse(cr, uid, ids, context): |
748 | @@ -131,7 +132,7 @@ | |||
749 | 131 | 'magento_shop': fields.boolean('Magento Shop', readonly=True), | 132 | 'magento_shop': fields.boolean('Magento Shop', readonly=True), |
750 | 132 | 'allow_magento_order_status_push': fields.boolean('Allow Magento Order Status push', help='Allow to send back order status to Magento if order status changed in OpenERP first?'), | 133 | 'allow_magento_order_status_push': fields.boolean('Allow Magento Order Status push', help='Allow to send back order status to Magento if order status changed in OpenERP first?'), |
751 | 133 | 'allow_magento_notification': fields.boolean('Allow Magento Notification', help='Allow Magento to notify customer with an e-mail when OpenERP change an order status, create an invoice or a delivery order on Magento.'), | 134 | 'allow_magento_notification': fields.boolean('Allow Magento Notification', help='Allow Magento to notify customer with an e-mail when OpenERP change an order status, create an invoice or a delivery order on Magento.'), |
753 | 134 | } | 135 | } |
754 | 135 | 136 | ||
755 | 136 | _defaults = { | 137 | _defaults = { |
756 | 137 | 'allow_magento_order_status_push': lambda * a: False, | 138 | 'allow_magento_order_status_push': lambda * a: False, |
757 | @@ -174,7 +175,7 @@ | |||
758 | 174 | conn = shop.referential_id.external_connection() | 175 | conn = shop.referential_id.external_connection() |
759 | 175 | # Update the state of orders in OERP that are in "need_to_update":True | 176 | # Update the state of orders in OERP that are in "need_to_update":True |
760 | 176 | # from the Magento's corresponding orders | 177 | # from the Magento's corresponding orders |
762 | 177 | 178 | ||
763 | 178 | # Get all need_to_update orders in OERP | 179 | # Get all need_to_update orders in OERP |
764 | 179 | orders_to_update = so_obj.search( | 180 | orders_to_update = so_obj.search( |
765 | 180 | cr, uid, | 181 | cr, uid, |
766 | @@ -239,7 +240,7 @@ | |||
767 | 239 | 240 | ||
768 | 240 | def run_update_images_scheduler(self, cr, uid, context=None): | 241 | def run_update_images_scheduler(self, cr, uid, context=None): |
769 | 241 | self._sale_shop(cr, uid, self.export_images, context=context) | 242 | self._sale_shop(cr, uid, self.export_images, context=context) |
771 | 242 | 243 | ||
772 | 243 | def run_export_shipping_scheduler(self, cr, uid, context=None): | 244 | def run_export_shipping_scheduler(self, cr, uid, context=None): |
773 | 244 | self._sale_shop(cr, uid, self.export_shipping, context=context) | 245 | self._sale_shop(cr, uid, self.export_shipping, context=context) |
774 | 245 | 246 | ||
775 | @@ -248,7 +249,7 @@ | |||
776 | 248 | 249 | ||
777 | 249 | class sale_order(magerp_osv.magerp_osv): | 250 | class sale_order(magerp_osv.magerp_osv): |
778 | 250 | _inherit = "sale.order" | 251 | _inherit = "sale.order" |
780 | 251 | 252 | ||
781 | 252 | _columns = { | 253 | _columns = { |
782 | 253 | 'magento_incrementid': fields.char('Magento Increment ID', size=32), | 254 | 'magento_incrementid': fields.char('Magento Increment ID', size=32), |
783 | 254 | 'magento_storeview_id': fields.many2one('magerp.storeviews', 'Magento Store View'), | 255 | 'magento_storeview_id': fields.many2one('magerp.storeviews', 'Magento Store View'), |
784 | @@ -257,14 +258,14 @@ | |||
785 | 257 | type='boolean', | 258 | type='boolean', |
786 | 258 | string='Is a Magento Sale Order') | 259 | string='Is a Magento Sale Order') |
787 | 259 | } | 260 | } |
789 | 260 | 261 | ||
790 | 261 | def _auto_init(self, cr, context=None): | 262 | def _auto_init(self, cr, context=None): |
791 | 262 | tools.drop_view_if_exists(cr, 'sale_report') | 263 | tools.drop_view_if_exists(cr, 'sale_report') |
792 | 263 | cr.execute("ALTER TABLE sale_order_line ALTER COLUMN discount TYPE numeric(16,6);") | 264 | cr.execute("ALTER TABLE sale_order_line ALTER COLUMN discount TYPE numeric(16,6);") |
793 | 264 | cr.execute("ALTER TABLE account_invoice_line ALTER COLUMN discount TYPE numeric(16,6);") | 265 | cr.execute("ALTER TABLE account_invoice_line ALTER COLUMN discount TYPE numeric(16,6);") |
794 | 265 | self.pool.get('sale.report').init(cr) | 266 | self.pool.get('sale.report').init(cr) |
795 | 266 | super(sale_order, self)._auto_init(cr, context) | 267 | super(sale_order, self)._auto_init(cr, context) |
797 | 267 | 268 | ||
798 | 268 | def get_order_addresses(self, cr, uid, referential_id, data_record, context=None): | 269 | def get_order_addresses(self, cr, uid, referential_id, data_record, context=None): |
799 | 269 | partner_obj = self.pool.get('res.partner') | 270 | partner_obj = self.pool.get('res.partner') |
800 | 270 | partner_address_obj = self.pool.get('res.partner.address') | 271 | partner_address_obj = self.pool.get('res.partner.address') |
801 | @@ -436,7 +437,7 @@ | |||
802 | 436 | name = product.name | 437 | name = product.name |
803 | 437 | if ext_code_field and data_record.get(ext_code_field, False): | 438 | if ext_code_field and data_record.get(ext_code_field, False): |
804 | 438 | name = "%s [%s]" % (name, data_record[ext_code_field]) | 439 | name = "%s [%s]" % (name, data_record[ext_code_field]) |
806 | 439 | 440 | ||
807 | 440 | if is_tax_included: | 441 | if is_tax_included: |
808 | 441 | price_unit = float(amount) + float(data_record[ext_tax_field]) | 442 | price_unit = float(amount) + float(data_record[ext_tax_field]) |
809 | 442 | else: | 443 | else: |
810 | @@ -464,7 +465,7 @@ | |||
811 | 464 | res['order_line'].append((0, 0, extra_line)) | 465 | res['order_line'].append((0, 0, extra_line)) |
812 | 465 | 466 | ||
813 | 466 | return res | 467 | return res |
815 | 467 | 468 | ||
816 | 468 | def add_order_shipping(self, cr, uid, res, external_referential_id, data_record, defaults, context=None): | 469 | def add_order_shipping(self, cr, uid, res, external_referential_id, data_record, defaults, context=None): |
817 | 469 | if context is None: context = {} | 470 | if context is None: context = {} |
818 | 470 | if data_record.get('shipping_amount', False) and float(data_record.get('shipping_amount', False)) > 0: | 471 | if data_record.get('shipping_amount', False) and float(data_record.get('shipping_amount', False)) > 0: |
819 | @@ -509,7 +510,7 @@ | |||
820 | 509 | product_ref = ('magentoerpconnect', 'product_product_cash_on_delivery') | 510 | product_ref = ('magentoerpconnect', 'product_product_cash_on_delivery') |
821 | 510 | res = self.add_order_extra_line(cr, uid, res, data_record, 'cod_fee', product_ref, defaults, ctx) | 511 | res = self.add_order_extra_line(cr, uid, res, data_record, 'cod_fee', product_ref, defaults, ctx) |
822 | 511 | return res | 512 | return res |
824 | 512 | 513 | ||
825 | 513 | def convert_extdata_into_oedata(self, cr, uid, external_data, external_referential_id, parent_data=None, defaults=None, context=None): | 514 | def convert_extdata_into_oedata(self, cr, uid, external_data, external_referential_id, parent_data=None, defaults=None, context=None): |
826 | 514 | res = super(sale_order, self).convert_extdata_into_oedata(cr, uid, external_data, external_referential_id, parent_data=parent_data, defaults=defaults, context=context) | 515 | res = super(sale_order, self).convert_extdata_into_oedata(cr, uid, external_data, external_referential_id, parent_data=parent_data, defaults=defaults, context=context) |
827 | 515 | res=res[0] | 516 | res=res[0] |
828 | @@ -566,7 +567,7 @@ | |||
829 | 566 | all_items.extend(item_modified) | 567 | all_items.extend(item_modified) |
830 | 567 | else: | 568 | else: |
831 | 568 | all_items.append(top_item) | 569 | all_items.append(top_item) |
833 | 569 | 570 | ||
834 | 570 | data_record['items'] = all_items | 571 | data_record['items'] = all_items |
835 | 571 | return data_record | 572 | return data_record |
836 | 572 | 573 | ||
837 | @@ -593,7 +594,7 @@ | |||
838 | 593 | res = super(magerp_osv.magerp_osv, self).oevals_from_extdata(cr, uid, external_referential_id, data_record, key_field, mapping_lines, parent_data, previous_lines, defaults, context) | 594 | res = super(magerp_osv.magerp_osv, self).oevals_from_extdata(cr, uid, external_referential_id, data_record, key_field, mapping_lines, parent_data, previous_lines, defaults, context) |
839 | 594 | 595 | ||
840 | 595 | #Move me in a mapping | 596 | #Move me in a mapping |
842 | 596 | if not context.get('one_by_one', False): | 597 | if not context.get('one_by_one', False): |
843 | 597 | if data_record.get('status_history', False) and len(data_record['status_history']) > 0: | 598 | if data_record.get('status_history', False) and len(data_record['status_history']) > 0: |
844 | 598 | res['date_order'] = data_record['status_history'][len(data_record['status_history'])-1]['created_at'] | 599 | res['date_order'] = data_record['status_history'][len(data_record['status_history'])-1]['created_at'] |
845 | 599 | return res | 600 | return res |
846 | @@ -653,7 +654,7 @@ | |||
847 | 653 | """ | 654 | """ |
848 | 654 | if context is None: | 655 | if context is None: |
849 | 655 | context = {} | 656 | context = {} |
851 | 656 | logger = netsvc.Logger() | 657 | logger = logging.getLogger('ext synchro') |
852 | 657 | conn = context.get('conn_obj', False) | 658 | conn = context.get('conn_obj', False) |
853 | 658 | parent_list = [] | 659 | parent_list = [] |
854 | 659 | # get all parents orders (to cancel) of the sale orders | 660 | # get all parents orders (to cancel) of the sale orders |
855 | @@ -669,7 +670,7 @@ | |||
856 | 669 | try: | 670 | try: |
857 | 670 | wf_service.trg_validate(uid, 'sale.order', canceled_order_id, 'cancel', cr) | 671 | wf_service.trg_validate(uid, 'sale.order', canceled_order_id, 'cancel', cr) |
858 | 671 | self.log(cr, uid, canceled_order_id, "order %s canceled when updated from external system" % (canceled_order_id,)) | 672 | self.log(cr, uid, canceled_order_id, "order %s canceled when updated from external system" % (canceled_order_id,)) |
860 | 672 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Order %s canceled when updated from external system because it has been replaced by a new one" % (canceled_order_id,)) | 673 | logger.info("Order %s canceled when updated from external system because it has been replaced by a new one", canceled_order_id) |
861 | 673 | except osv.except_osv, e: | 674 | except osv.except_osv, e: |
862 | 674 | #TODO: generic reporting of errors in magentoerpconnect | 675 | #TODO: generic reporting of errors in magentoerpconnect |
863 | 675 | # except if the sale order has been confirmed for example, we cannot cancel the order | 676 | # except if the sale order has been confirmed for example, we cannot cancel the order |
864 | @@ -744,10 +745,10 @@ | |||
865 | 744 | def ext_set_order_imported(self, cr, uid, external_id, external_referential_id, context=None): | 745 | def ext_set_order_imported(self, cr, uid, external_id, external_referential_id, context=None): |
866 | 745 | if context is None: | 746 | if context is None: |
867 | 746 | context = {} | 747 | context = {} |
869 | 747 | logger = netsvc.Logger() | 748 | logger = logging.getLogger('ext synchro') |
870 | 748 | conn = context.get('conn_obj', False) | 749 | conn = context.get('conn_obj', False) |
871 | 749 | conn.call('sales_order.done', [external_id]) | 750 | conn.call('sales_order.done', [external_id]) |
873 | 750 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Successfully set the imported flag on Magento on sale order %s" % external_id) | 751 | logger.info("Successfully set the imported flag on Magento on sale order %s", external_id) |
874 | 751 | return True | 752 | return True |
875 | 752 | 753 | ||
876 | 753 | def mage_import_base(self, cr, uid, conn, external_referential_id, defaults=None, context=None): | 754 | def mage_import_base(self, cr, uid, conn, external_referential_id, defaults=None, context=None): |
877 | @@ -774,7 +775,7 @@ | |||
878 | 774 | if context is None: | 775 | if context is None: |
879 | 775 | context = {} | 776 | context = {} |
880 | 776 | 777 | ||
882 | 777 | logger = netsvc.Logger() | 778 | logger = logging.getLogger('ext synchro') |
883 | 778 | mapping_id = self.pool.get('external.mapping').search( | 779 | mapping_id = self.pool.get('external.mapping').search( |
884 | 779 | cr, uid, | 780 | cr, uid, |
885 | 780 | [('model', '=', self._name), | 781 | [('model', '=', self._name), |
886 | @@ -792,7 +793,7 @@ | |||
887 | 792 | existing_id = self.extid_to_existing_oeid(cr, uid, ext_order_id, referential_id, context=context) | 793 | existing_id = self.extid_to_existing_oeid(cr, uid, ext_order_id, referential_id, context=context) |
888 | 793 | if existing_id: | 794 | if existing_id: |
889 | 794 | unchanged_ids.append(existing_id) | 795 | unchanged_ids.append(existing_id) |
891 | 795 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "the order %s already exist in OpenERP" % (ext_order_id,)) | 796 | logger.info("the order %s already exist in OpenERP", ext_order_id) |
892 | 796 | self.ext_set_order_imported(cr, uid, ext_order_id, referential_id, context=context) | 797 | self.ext_set_order_imported(cr, uid, ext_order_id, referential_id, context=context) |
893 | 797 | else: | 798 | else: |
894 | 798 | order_ids_filtred.append({'increment_id' : ext_order_id}) | 799 | order_ids_filtred.append({'increment_id' : ext_order_id}) |
895 | 799 | 800 | ||
896 | === modified file 'magentoerpconnect/stock.py' | |||
897 | --- magentoerpconnect/stock.py 2012-05-14 13:22:22 +0000 | |||
898 | +++ magentoerpconnect/stock.py 2012-05-25 09:04:23 +0000 | |||
899 | @@ -20,7 +20,7 @@ | |||
900 | 20 | ######################################################################### | 20 | ######################################################################### |
901 | 21 | 21 | ||
902 | 22 | import xmlrpclib | 22 | import xmlrpclib |
904 | 23 | import netsvc | 23 | import logging |
905 | 24 | 24 | ||
906 | 25 | from osv import fields,osv | 25 | from osv import fields,osv |
907 | 26 | from tools.translate import _ | 26 | from tools.translate import _ |
908 | @@ -38,14 +38,14 @@ | |||
909 | 38 | conn = context.get('conn_obj', False) | 38 | conn = context.get('conn_obj', False) |
910 | 39 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, {}, _("Shipping Created"), mail_notification, True]) | 39 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, {}, _("Shipping Created"), mail_notification, True]) |
911 | 40 | return ext_shipping_id | 40 | return ext_shipping_id |
913 | 41 | 41 | ||
914 | 42 | def add_picking_line(self, cr, uid, lines, picking_line, context=None): | 42 | def add_picking_line(self, cr, uid, lines, picking_line, context=None): |
915 | 43 | """ A line to add in the shipping is a dict with : product_id and product_qty keys.""" | 43 | """ A line to add in the shipping is a dict with : product_id and product_qty keys.""" |
916 | 44 | line_info = {'product_id': picking_line.product_id.id, | 44 | line_info = {'product_id': picking_line.product_id.id, |
917 | 45 | 'product_qty': picking_line.product_qty, | 45 | 'product_qty': picking_line.product_qty, |
918 | 46 | } | 46 | } |
919 | 47 | lines.append(line_info) | 47 | lines.append(line_info) |
921 | 48 | return lines | 48 | return lines |
922 | 49 | 49 | ||
923 | 50 | def create_ext_partial_shipping(self, cr, uid, id, external_referential_id, magento_incrementid, mail_notification=True, context=None): | 50 | def create_ext_partial_shipping(self, cr, uid, id, external_referential_id, magento_incrementid, mail_notification=True, context=None): |
924 | 51 | if context is None: context = {} | 51 | if context is None: context = {} |
925 | @@ -57,7 +57,7 @@ | |||
926 | 57 | product_2_item.update({self.pool.get('product.product').extid_to_oeid(cr, uid, item['product_id'], external_referential_id, context={}): item['item_id']}) | 57 | product_2_item.update({self.pool.get('product.product').extid_to_oeid(cr, uid, item['product_id'], external_referential_id, context={}): item['item_id']}) |
927 | 58 | picking = self.pool.get('stock.picking').browse(cr, uid, id, context) | 58 | picking = self.pool.get('stock.picking').browse(cr, uid, id, context) |
928 | 59 | item_qty = {} | 59 | item_qty = {} |
930 | 60 | 60 | ||
931 | 61 | lines = [] | 61 | lines = [] |
932 | 62 | # get product and quantities to ship from the picking | 62 | # get product and quantities to ship from the picking |
933 | 63 | for line in picking.move_lines: | 63 | for line in picking.move_lines: |
934 | @@ -70,7 +70,7 @@ | |||
935 | 70 | item_qty.update({product_2_item[line['product_id']]: line['product_qty']}) | 70 | item_qty.update({product_2_item[line['product_id']]: line['product_qty']}) |
936 | 71 | 71 | ||
937 | 72 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), mail_notification, True]) | 72 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), mail_notification, True]) |
939 | 73 | return ext_shipping_id | 73 | return ext_shipping_id |
940 | 74 | 74 | ||
941 | 75 | def create_ext_shipping(self, cr, uid, id, picking_type, external_referential_id, context=None): | 75 | def create_ext_shipping(self, cr, uid, id, picking_type, external_referential_id, context=None): |
942 | 76 | """ | 76 | """ |
943 | @@ -112,18 +112,18 @@ | |||
944 | 112 | 112 | ||
945 | 113 | def add_ext_tracking_reference(self, cr, uid, id, carrier_id, ext_shipping_id, context=None): | 113 | def add_ext_tracking_reference(self, cr, uid, id, carrier_id, ext_shipping_id, context=None): |
946 | 114 | if context is None: context = {} | 114 | if context is None: context = {} |
948 | 115 | logger = netsvc.Logger() | 115 | logger = logging.getLogger('ext synchro') |
949 | 116 | conn = context.get('conn_obj', False) | 116 | conn = context.get('conn_obj', False) |
950 | 117 | carrier = self.pool.get('delivery.carrier').read(cr, uid, carrier_id, ['magento_carrier_code', 'magento_tracking_title'], context) | 117 | carrier = self.pool.get('delivery.carrier').read(cr, uid, carrier_id, ['magento_carrier_code', 'magento_tracking_title'], context) |
952 | 118 | 118 | ||
953 | 119 | if self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', 'carrier_tracking_ref'), ('model', '=', 'stock.picking')]): #OpenERP v6 have the field carrier_tracking_ref on the stock_picking but v5 doesn't have it | 119 | if self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', 'carrier_tracking_ref'), ('model', '=', 'stock.picking')]): #OpenERP v6 have the field carrier_tracking_ref on the stock_picking but v5 doesn't have it |
954 | 120 | carrier_tracking_ref = self.read(cr, uid, id, ['carrier_tracking_ref'], context)['carrier_tracking_ref'] | 120 | carrier_tracking_ref = self.read(cr, uid, id, ['carrier_tracking_ref'], context)['carrier_tracking_ref'] |
955 | 121 | else: | 121 | else: |
956 | 122 | carrier_tracking_ref = '' | 122 | carrier_tracking_ref = '' |
958 | 123 | 123 | ||
959 | 124 | res = conn.call('sales_order_shipment.addTrack', [ext_shipping_id, carrier['magento_carrier_code'], carrier['magento_tracking_title'] or '', carrier_tracking_ref or '']) | 124 | res = conn.call('sales_order_shipment.addTrack', [ext_shipping_id, carrier['magento_carrier_code'], carrier['magento_tracking_title'] or '', carrier_tracking_ref or '']) |
960 | 125 | if res: | 125 | if res: |
962 | 126 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Successfully adding a tracking reference to the shipping with OpenERP id %s and ext id %s in external sale system" % (id, ext_shipping_id)) | 126 | logger.info("Successfully adding a tracking reference to the shipping with OpenERP id %s and ext id %s in external sale system", id, ext_shipping_id) |
963 | 127 | return True | 127 | return True |
964 | 128 | 128 | ||
965 | 129 | stock_picking() | 129 | stock_picking() |
Thanks for your contribution !
It's merged