Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

Changing the product image in shop main view by module in odoo

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
ModuleodooV13
2 Antworten
6863 Ansichten
Avatar
Raitis

I am trying to change the image of a product on main shop(website_sale module) view, by my own module and inheritance. I will try to explain my logic, so my code will be more understandable.


First of all, I have inherited the product.product to get access to the variables in the webiste_sale module.


Then I made some xpaths to the html code, where those img src attributes are present, I was relying on this result html code:

---

<a class="d-block h-100" itemprop="url" href="/shop/product/a4tech-bloody-v8m-2">

                    <span data-oe-model="product.template" data-oe-id="2" 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/2/image_256/A4Tech Bloody V8M?unique=9ffc5e8" class="img img-fluid" alt="A4Tech Bloody V8M"/></span>

</a>

---

And so, here is my templates.xml code:

---

<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.product.image_256</field>

             </xpath>

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

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

             </xpath>

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

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

             </xpath>

          </xpath>

       </template>

    </data>

</odoo>

---

I selected the three individual image_256 from the products(I have 3 products in shop)


And finally by doing some searching through webiste_sale module, I have confirmed that, varriable name is image_256 inside a product.product. Here are the search results:

---

root@linux-desktop:/usr/lib/python3/dist-packages/odoo/addons/website_sale$ grep -rnw . -e "image_256"

./tests/test_website_sale_image.py:182:        image = Image.open(io.BytesIO(base64.b64decode(template.image_256)))

./tests/test_website_sale_image.py:185:        image = Image.open(io.BytesIO(base64.b64decode(product_red.image_256)))

./tests/test_website_sale_image.py:188:        image = Image.open(io.BytesIO(base64.b64decode(product_green.image_256)))

./static/src/xml/website_sale_recently_viewed.xml:15:                                            <img class="o_carousel_product_card_img_top card-img-top" t-attf-src="/web/image/product.product/#{product.id}#{productFrame == 1 ? '/image_256' : '/image_512'}" t-att-alt="product.display_name"/>

./views/templates.xml:156:                        t-options="{'widget': 'image', 'preview_image': 'image_1024' if product_image_big else 'image_256'}"


root@linux-desktop:/usr/lib/python3/dist-packages/odoo/addons/website_sale$ grep -rnw . --exclude="*.po" -e "/web/image"

./data/mail_template_data.xml:46:                                        <img src="/web/image/product.product/${line.product_id.id}/image_128" style="width: 100px; height: 100px; object-fit: contain;" alt="Product image"></img>

./i18n/website_sale.pot:96:"                                        <img src=\"/web/image/product.product/${line.product_id.id}/image_128\" style=\"width: 100px; height: 100px; object-fit: contain;\" alt=\"Product image\"/>\n"

./static/src/xml/website_sale_utils.xml:14:                <img t-attf-src="/web/image/product.template/#{product['id']}/image_128"

./static/src/xml/website_sale_recently_viewed.xml:15:                                            <img class="o_carousel_product_card_img_top card-img-top" t-attf-src="/web/image/product.product/#{product.id}#{productFrame == 1 ? '/image_256' : '/image_512'}" t-att-alt="product.display_name"/>

---

Here is resulting models.py code:

---

# -*- 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")

---

Just setting the fields from xml with test values to test the module, but strings are nowhere to be found. I would like to hear, what is wrong here, and why it is not working. Thanks :)


0
Avatar
Verwerfen
Avatar
Raitis
Autor Beste Antwort

@Anisha

Thank you for your answer, but it didn't help

0
Avatar
Verwerfen
Avatar
Anisha Bahukhandi
Beste Antwort

Hello Raitis,

Kindly replace product.product.image_256 with product.image_256 

For detailed information, you can refer to the below-mentioned code:

<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.product.image_256</field>

             </xpath>

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

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

             </xpath>

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

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

             </xpath>

          </xpath>

       </template>

    </data>

</odoo>


0
Avatar
Verwerfen
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
Changing the product image in shop main view by module in odoo
Module odooV13
Avatar
1
Apr. 25
4738
My Fist Odoo Modul
Module
Avatar
Avatar
2
Aug. 25
1316
Odoov13 UI suddenly stop working
odooV13
Avatar
Avatar
1
Nov. 24
1963
Odoo Server Error when Upgrading Module (Odoo 13)
Module
Avatar
Avatar
1
Nov. 24
13052
Module installation
Module
Avatar
Avatar
Avatar
2
Dez. 23
3278
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Ausbildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now