fix: save wizard images to Odoo product before passing URL to WC

The wizard's binary image field wasn't being saved to the product.product
record, so the public URL returned the default placeholder. Now saves
line.image → variant.image_1920 first, then generates the URL with a
cache-busting timestamp. Only includes image in WC data if the wizard
line has an actual image uploaded.

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

View File

@@ -171,12 +171,15 @@ class WooVariantPushWizard(models.TransientModel):
if wc_tax_class:
var_data['tax_class'] = wc_tax_class
# Set variant image via Odoo's public image URL
if variant.id and (variant.image_variant_1920 or variant.image_1920):
# Save wizard image to Odoo product, then pass URL to WC
if line.image:
variant.image_1920 = line.image
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'
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{img_name}"
import time
cache_bust = int(time.time())
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{img_name}?t={cache_bust}"
var_data['image'] = {
'src': img_url,
'name': img_name,
@@ -244,14 +247,20 @@ class WooVariantPushWizard(models.TransientModel):
if wc_tax_class:
var_data['tax_class'] = wc_tax_class
# Set variant image via Odoo's public image URL
# WC downloads the image from this URL directly
if variant.id and (variant.image_variant_1920 or variant.image_1920):
# Build the public Odoo image URL
# Save wizard image to Odoo product, then pass URL to WC
if line.image:
# 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)
# Now build the public URL for WC to download
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'
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{img_name}"
# Add timestamp to bust WC cache
import time
cache_bust = int(time.time())
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{img_name}?t={cache_bust}"
var_data['image'] = {
'src': img_url,
'name': img_name,