Skip to Content
Menu
This question has been flagged
2 Replies
559 Views

Hello every, I'm trying to add product image and sales description on picking & delivery app(note: not printed report). When you try to mark inventory, you need click Inverntory from Home page and click either picking/ delivery. After jumping to picking/ delivery page, you will see product name and quantity required. At this section, I hope to add product image & sales description next to product name. 

I'm not familiar with python, so please send step by step image and code. Thank you very much.

Avatar
Discard

What version of Odoo?

Best Answer

Hi,


Try the following code to add the product image to the delivery line.

1- Inherit the model 'stock.move' and define the image field.

Python

from odoo import fields, models


class StockMove(models.Model):
"""Inherits the model stock move to add image field"""
_inherit = 'stock.move'

order_line_image = fields.Binary(string="Image",
related="product_id.image_1920",
help='Product Image in Sale orderLine')

2- Add the field in to the XML view.

    <field name="name">
stock.picking.view.form.inherit.order.line
</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='move_ids_without_package']//list//field[@name='product_id']"
position="after">
<field name="order_line_image" widget="image"
style="height:30px ;width:30px;" readonly="1"/>
</xpath>
</field>
</record>

3- Make sure that the Python file is added to the init file and the path of the XML file is added in the manifest file.

4- Result.



For more reference,

https://apps.odoo.com/apps/modules/18.0/sale_product_image

https://www.odoo.com/sl_SI/forum/pomoc-1/add-the-product-image-to-the-line-item-on-a-sales-and-purchase-order-252695


Hope it helps

Avatar
Discard
Best Answer

Hey Yuqi,

Important Prerequisites:

  • Odoo Version: This guide assumes you're using a relatively recent version of Odoo (14 or later). The steps should be similar in older versions, but the interface might look slightly different.
  • Developer Mode: Make sure you have activated developer mode in Odoo. (Settings > Activate the developer mode).

Step-by-Step Guide:

Step 1: Identify the Correct View

  1. Navigate to Picking/Delivery: Go to the Inventory app. Click on "Operations" and then either "Pickings" or "Deliveries" (depending on which one you want to modify).
  2. Open a Record: Open any existing picking or delivery order.
  3. Activate Debug Mode: Make sure you're in developer mode.
  4. Inspect the View: Click the Debug View icon (the bug icon in the top right corner).
  5. Choose "View: Form" or "View: Tree":
    • If you want to modify the form view (the detailed view of a picking), choose "View: Form".
    • If you want to modify the list view (the list of products within a picking), choose "View: Tree".
  6. Note the View ID: A popup will appear. Look for the "External ID". This is the technical name of the view. It will look something like stock.view_picking_form (for the form view) or stock.move.line.tree (for the tree view). Write this down! This is crucial.

Step 2: Create the Inherited View

  1. Go to Views: Go to Settings > Technical > User Interface > Views.
  2. Create a New View: Click "Create".
  3. Fill in the View Information:
    • View Name: Give it a descriptive name (e.g., picking_product_image_form or picking_product_image_tree).
    • Inherited View: Check the box next to "Inherited View".
    • Inherit From: In the "Inherit From" field, enter the External ID you wrote down in Step 1 (e.g., stock.view_picking_form or stock.move.line.tree).
    • Architecture: Leave this blank for now.

Step 3: Add the XML Code

  1. Choose the Correct XML Code: The XML code will depend on whether you're modifying the form view or the tree view.
    • Form View (Modifying the detailed picking view):
      <record id="picking_product_image_form" model="ir.ui.view">
          <field name="name">picking.product.image.form</field>
          <field name="inherit_id" ref="stock.view_picking_form"/>  <!-- REPLACE WITH YOUR VIEW ID -->
          <field name="arch" type="xml">
              <xpath expr="//field[@name='product_id']" position="after">
                  <field name="product_id.image_1920" widget="image" class="oe_avatar"/>
                  <field name="product_id.description_sale"/>
              </xpath>
          </field>
      </record>
      
    • Tree View (Modifying the list of products within the picking):
      <record id="picking_product_image_tree" model="ir.ui.view">
          <field name="name">picking.product.image.tree</field>
          <field name="inherit_id" ref="stock.move_line_tree"/>  <!-- REPLACE WITH YOUR VIEW ID -->
          <field name="arch" type="xml">
              <xpath expr="//field[@name='product_id']" position="before">
                  <field name="product_id.image_128" widget="image" style="width: 40px; height: 40px;"/>
              </xpath>
              <xpath expr="//field[@name='product_id']" position="after">
                  <field name="product_id.description_sale"/>
              </xpath>
          </field>
      </record>
      
  2. Paste the Code: Copy the appropriate XML code (either the form view or the tree view code) and paste it into the "Architecture" field of the view you're creating.
  3. Replace the View ID: IMPORTANT: In the XML code, find the line that says <field name="inherit_id" ref="YOUR_VIEW_ID"/>. Replace YOUR_VIEW_ID with the External ID you wrote down in Step 1. For example, if your External ID was stock.view_picking_form, the line should look like this: <field name="inherit_id" ref="stock.view_picking_form"/>.
  4. Save the View: Click "Save" to save the view.

Step 4: Clear Odoo's Cache

  1. Go to Reload Server Registry: Go to Settings > Technical > Actions > Reload Server Registry.
  2. Click "Reload Server Registry": Click the "Reload Server Registry" button. This clears Odoo's cache and forces it to recognize your changes.

Step 5: Test and Adjust

  1. Go Back to Picking/Delivery: Go back to the Inventory app and open a picking or delivery order.
  2. Check for the Image and Description: See if the product image and sales description are now displayed in the view you modified.
  3. Adjust if Necessary:
    • Image Size: If the image is too large or too small, you can adjust the width and height attributes in the XML code (in the <field> tag for the image). You can also try using a different image field (e.g., image_128 instead of image_1920 for a smaller image).
    • Description Placement: If the description is not in the right place, you might need to adjust the xpath expression. The xpath tells Odoo where to insert the new fields. Inspect the original view's XML (using the "View Architecture" option in developer mode) to find the correct location.

Explanation of the XML Code:

  • <record id="unique_id" model="ir.ui.view">: This creates a new view record in Odoo. The id should be a unique identifier for your view.
  • <field name="name">view.name</field>: This gives your view a name.
  • <field name="inherit_id" ref="original_view_id"/>: This tells Odoo that you're inheriting from an existing view. original_view_id is the External ID of the view you're modifying.
  • <field name="arch" type="xml">: This contains the XML code that defines the changes you're making to the view.
  • <xpath expr="//some/xpath/expression" position="after|before|inside|replace">: This is the most important part. It tells Odoo where to insert your new code.
    • expr="//some/xpath/expression": This is an XPath expression that selects a specific element in the original view's XML. You need to find the correct XPath expression to insert your code in the right place.
    • position="after|before|inside|replace": This tells Odoo how to insert your code:
      • after: Insert the code after the selected element.
      • before: Insert the code before the selected element.
      • inside: Insert the code inside the selected element (as a child element).
      • replace: Replace the selected element with your code.
  • <field name="product_id.image_1920" widget="image"/>: This adds the product image. product_id.image_1920 refers to the image_1920 field of the product_id (which is the product). widget="image" tells Odoo to display it as an image.
  • <field name="product_id.description_sale"/>: This adds the sales description.

Troubleshooting:

  • Nothing Happens:
    • Make sure you cleared the cache (Reload Server Registry).
    • Double-check that you entered the correct External ID in the inherit_id field.
    • Double-check that your XPath expression is correct.
  • Error Message:
    • Read the error message carefully. It will usually tell you what's wrong (e.g., invalid XML syntax, invalid XPath expression).
  • Image Not Displaying:
    • Make sure the product actually has an image.
    • Try using a different image field (e.g., image_128).
    • Check the image size and adjust the width and height attributes.
  • Description Not Displaying:
    • Make sure the product actually has a sales description.
    • Double-check that the field name is correct (description_sale).

This is a detailed guide, but it requires careful attention to detail. The most important parts are identifying the correct view, using the correct XML code, and making sure your XPath expression is correct. Good luck!

🚀 Did This Solve Your Problem?

If this answer helped you save time, money, or frustration, consider:

✅ Upvoting (👍) to help others find it faster

✅ Marking as "Best Answer" if it resolved your issue

Your feedback keeps the Odoo community strong! 💪

(Need further customization? Drop a comment—I’m happy to refine the solution!)

Avatar
Discard
Related Posts Replies Views Activity
1
May 25
1326
0
Dec 24
1285
0
May 23
1746
1
Apr 23
2747
3
May 18
5616