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:
@@ -171,12 +171,15 @@ class WooVariantPushWizard(models.TransientModel):
|
|||||||
if wc_tax_class:
|
if wc_tax_class:
|
||||||
var_data['tax_class'] = wc_tax_class
|
var_data['tax_class'] = wc_tax_class
|
||||||
|
|
||||||
# Set variant image via Odoo's public image URL
|
# Save wizard image to Odoo product, then pass URL to WC
|
||||||
if variant.id and (variant.image_variant_1920 or variant.image_1920):
|
if line.image:
|
||||||
|
variant.image_1920 = line.image
|
||||||
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
||||||
if odoo_base:
|
if odoo_base:
|
||||||
img_name = (line.sku or variant.default_code or 'variant') + '.png'
|
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'] = {
|
var_data['image'] = {
|
||||||
'src': img_url,
|
'src': img_url,
|
||||||
'name': img_name,
|
'name': img_name,
|
||||||
@@ -244,14 +247,20 @@ class WooVariantPushWizard(models.TransientModel):
|
|||||||
if wc_tax_class:
|
if wc_tax_class:
|
||||||
var_data['tax_class'] = wc_tax_class
|
var_data['tax_class'] = wc_tax_class
|
||||||
|
|
||||||
# Set variant image via Odoo's public image URL
|
# Save wizard image to Odoo product, then pass URL to WC
|
||||||
# WC downloads the image from this URL directly
|
if line.image:
|
||||||
if variant.id and (variant.image_variant_1920 or variant.image_1920):
|
# Save the image from the wizard to the actual Odoo product
|
||||||
# Build the public Odoo image URL
|
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', '')
|
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
||||||
if odoo_base:
|
if odoo_base:
|
||||||
img_name = (line.sku or variant.default_code or 'variant') + '.png'
|
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'] = {
|
var_data['image'] = {
|
||||||
'src': img_url,
|
'src': img_url,
|
||||||
'name': img_name,
|
'name': img_name,
|
||||||
|
|||||||
Reference in New Issue
Block a user