fix: force commit image save and add debug logging for variant images

Image wasn't persisting because transient model write was in the same
transaction. Added cr.commit() after saving image to ensure it's
available when WC downloads it. Added size/type logging to trace
image data flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-04-01 21:37:39 -04:00
parent 21c1e37211
commit 27955c8c41

View File

@@ -172,8 +172,9 @@ class WooVariantPushWizard(models.TransientModel):
var_data['tax_class'] = wc_tax_class
# Save wizard image to Odoo product, then pass URL to WC
if line.image:
variant.image_1920 = line.image
if line.image and len(line.image) > 100:
variant.sudo().write({'image_1920': line.image})
self.env.cr.commit()
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
if odoo_base:
img_name = (line.sku or variant.default_code or 'variant') + '.png'
@@ -249,9 +250,16 @@ class WooVariantPushWizard(models.TransientModel):
# Save wizard image to Odoo product, then pass URL to WC
if line.image:
img_data = line.image
img_size = len(img_data) if img_data else 0
_logger.info("Variant %d image data: type=%s size=%d", variant.id, type(img_data).__name__, img_size)
# Save the image from the wizard to the actual Odoo product
variant.image_1920 = line.image
_logger.info("Saved image to Odoo product %d", variant.id)
if img_size > 100: # Skip tiny placeholders
variant.sudo().write({'image_1920': img_data})
self.env.cr.commit() # Force commit so the image is available for download
_logger.info("Saved image to Odoo product %d (%d bytes)", variant.id, img_size)
else:
_logger.warning("Skipping tiny image for variant %d (%d bytes)", variant.id, img_size)
# Now build the public URL for WC to download
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')