首页 > 解决方案 > 在odoo中按模块更改产品图像

问题描述

我正在尝试通过 odoo 中的自定义模块更改图像。

模板代码:

<odoo>

    <data>

       <template id="website_sales_inh" name="webiste_sales_inherit" inherit_id="website_sale.products_item">

          <xpath expr="//span[hasclass('d-flex')]" position="inside">

            <!-- <xpath expr="/@data-oe-id='1'" position="inside"> -->

               <field name="src1">product.image_256</field>

             <!--</xpath>-->

             <!--<xpath expr="//@data-oe-id='2'" position="inside">-->

               <field name="src2">product.image_256</field>

             <!--</xpath>-->

             <!--<xpath expr="//@data-oe-id='3'" position="inside">-->

               <field name="src3">product.image_256</field>

             <!--</xpath>-->

          </xpath>

       </template>

    </data>

</odoo>

PS我最近注释掉了测试代码的某些部分,我希望,如果xpath会找到3个元素,至少有一个会在python代码中改变,但没有。这是我的models.py代码:

# -*- coding: utf-8 -*-

from odoo import models, fields, api


class imgtogif_r(models.Model):
    _inherit = 'product.product'
    _name = 'product.product'
    src1 = fields.Text(string="testsrc1")
    src2 = fields.Text(string="testsrc2")
    src3 = fields.Text(string="testsrc3")

想知道,为什么它不工作 :) 作为 xpaths 的参考,我使用了 /shop 中的代码(website_sale 模块)

<form action="/shop/cart/update" method="post" class="card oe_product_cart" itemscope="itemscope" itemtype="http://schema.org/Product" data-publish="on">
            <div class="card-body p-1 oe_product_image">
                <input type="hidden" name="csrf_token" data-oe-model="ir.ui.view" data-oe-id="1215" data-oe-field="arch" data-oe-xpath="/t[1]/form[1]/div[1]/input[1]" value="dae94f88614c5b4388c970c97f5fd8831123904ao1589187185"/>
                <div class="ribbon-wrapper" data-oe-model="ir.ui.view" data-oe-id="1215" data-oe-field="arch" data-oe-xpath="/t[1]/form[1]/div[1]/div[1]">
                    <a href="#" role="button" class="ribbon btn btn-danger">Sale</a>
                </div>
                <a class="d-block h-100" itemprop="url" href="/shop/product/lenovo-ideapad-l340-15irh-3">
                    <span data-oe-model="product.template" data-oe-id="3" data-oe-field="image_1920" data-oe-type="image" data-oe-expression="product.image_1920" class="d-flex h-100 justify-content-center align-items-center"><img src="/web/image/product.template/3/image_256/Lenovo%20IdeaPad%20L340-15IRH?unique=5b26c3f" class="img img-fluid" alt="Lenovo IdeaPad L340-15IRH"/></span>
                </a>
            </div>
            <div class="card-body p-0 text-center o_wsale_product_information">
                <div class="p-2 o_wsale_product_information_text">
                    <h6 class="o_wsale_products_item_title">
                        <a data-oe-model="product.template" data-oe-id="3" data-oe-field="name" data-oe-type="char" data-oe-expression="product.name" itemprop="name" href="/shop/product/lenovo-ideapad-l340-15irh-3" content="Lenovo IdeaPad L340-15IRH">Lenovo IdeaPad L340-15IRH</a>

                    </h6>
                    <div class="product_price" itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer">
                        <del data-oe-type="monetary" data-oe-expression="combination_info['list_price']" style="white-space: nowrap;" class="text-danger mr-2 d-none">$ <span class="oe_currency_value">1,000.00</span></del>
                        <span data-oe-type="monetary" data-oe-expression="combination_info['price']">$ <span class="oe_currency_value">1,000.00</span></span>
                        <span itemprop="price" style="display:none;">1000.0</span>
                        <span itemprop="priceCurrency" style="display:none;">USD</span>
                    </div>
                </div>
                <div class="o_wsale_product_btn" data-oe-model="ir.ui.view" data-oe-id="1215" data-oe-field="arch" data-oe-xpath="/t[1]/form[1]/div[2]/div[2]"></div>
            </div>
        </form>

我需要更改图像的地方

标签: pythonhtmlxmlxpathodoo

解决方案


推荐阅读