Merge lp:~therp-nl/magentoerpconnect/oerp6.1-stable-fix_image_update into lp:magentoerpconnect/oerp6.1-stable

Proposed by Stefan Rijnhart (Opener)
Status: Needs review
Proposed branch: lp:~therp-nl/magentoerpconnect/oerp6.1-stable-fix_image_update
Merge into: lp:magentoerpconnect/oerp6.1-stable
Diff against target: 68 lines (+33/-7)
1 file modified
magentoerpconnect/product_images.py (+33/-7)
To merge this branch: bzr merge lp:~therp-nl/magentoerpconnect/oerp6.1-stable-fix_image_update
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Review via email: mp+190804@code.launchpad.net

Commit message

[FIX] Actually update the image on product image update
[FIX] Magento requires image info to be updated for each storeview

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM

review: Approve (code review)

Unmerged revisions

695. By Stefan Rijnhart (Opener)

[FIX] Refer to local variable name

694. By Stefan Rijnhart (Opener)

[FIX] Actually update the image on product image update
[FIX] Magento requires image info to be updated for each storeview

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'magentoerpconnect/product_images.py'
--- magentoerpconnect/product_images.py 2012-12-03 15:08:39 +0000
+++ magentoerpconnect/product_images.py 2013-10-12 17:01:06 +0000
@@ -97,6 +97,10 @@
9797
98 ir_model_data_obj = self.pool.get('ir.model.data')98 ir_model_data_obj = self.pool.get('ir.model.data')
9999
100 storeviews = [
101 storeview.code for storeview in
102 external_session.sync_from_object.storeview_ids]
103
100 def detect_types(image):104 def detect_types(image):
101 types = []105 types = []
102 if image.small_image:106 if image.small_image:
@@ -107,16 +111,37 @@
107 types.append('thumbnail')111 types.append('thumbnail')
108 return types112 return types
109113
110 #TODO update the image file114 def update_image(product_extid, image_name, image, send_image=False):
111 def update_image(product_extid, image_name, image):115
116 values = {'label': image.name,
117 'exclude': image.exclude,
118 'types': detect_types(image),
119 }
120
121 # Update image info per storeview
122 for storeview in storeviews:
123 result = external_session.connection.call(
124 'catalog_product_attribute_media.update',
125 [product_extid, image_name, values, storeview])
126
127 if send_image:
128 values['file'] = {
129 'name': image.name,
130 'content': image.file,
131 'mime': (
132 image.link and image.url and mimetypes.guess_type(image.url)[0] or
133 image.extention and
134 mimetypes.guess_type(image.name + image.extention)[0] or
135 'image/jpeg'),
136 }
137
138 # Update global settings, including the image
112 result = external_session.connection.call('catalog_product_attribute_media.update',139 result = external_session.connection.call('catalog_product_attribute_media.update',
113 [product_extid,140 [product_extid,
114 image_name,141 image_name,
115 {'label':image.name,142 values,
116 'exclude':image.exclude,
117 'types':detect_types(image),
118 }
119 ])143 ])
144
120 return result145 return result
121 list_image = []146 list_image = []
122 list_image = self.read(cr, uid, ids, ['write_date', 'create_date'], context=context)147 list_image = self.read(cr, uid, ids, ['write_date', 'create_date'], context=context)
@@ -152,7 +177,8 @@
152 if ext_file_name: #If update177 if ext_file_name: #If update
153 try:178 try:
154 external_session.logger.info("Updating %s's image: %s" %(each.product_id.default_code, each.name))179 external_session.logger.info("Updating %s's image: %s" %(each.product_id.default_code, each.name))
155 result = update_image(product_extid, ext_file_name, each)180 result = update_image(
181 product_extid, ext_file_name, each, send_image=True)
156 external_session.logger.info("%s's image updated with sucess: %s" %(each.product_id.default_code, each.name))182 external_session.logger.info("%s's image updated with sucess: %s" %(each.product_id.default_code, each.name))
157 need_to_be_created = False183 need_to_be_created = False
158 except Exception, e:184 except Exception, e: