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

How to display barcode of a product in Sales Order tree view ?

I want to display product barcode in Sales Order tree view. When a product has variants, it should display the barcode of that product variant.


@Cybrosys Techno Solutions Pvt.Ltd

That I have already done it in product.template.product.tree view. But now I want to display it in sale.order.tree view. So how can I do it with custom addons?

I tried creating barcode_id (a many2one field) in sale.order model and after that i created a related field 'barcode'.

barcode_id = fields.Many2one(comodel_name="product.product")

barcode = fields.Char(related='barcode_id.barcode', string="Product Barcode", required=False, store=True).

I am getting the 'Product Barcode' column in sale.order.tree view, but the product barcode is not displayed in the column.

Avatar
Discard
Best Answer

Hi,

You can add a new field in the tree view to display the barcode in the tree view. Either you can do it by creating custom addons or from manually editing after the user interface.




If you want to do it from the UI, activate the developer mode and open the products list view, then click on lady debugger button near the logged in user name in the menu bar, and select the Edit List View as shown in above image,


Then add a line in the position you required, <field name="barcode"/>

UPDT:

To add the custom field to the sale order line, first, you can inherit the model and add the field to the model,

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

barcode = fields.Char(string='Product Barcode')


Then in the XML,'

<record id="sale_order_view_inherit_barcode1" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="after">
<field name ="barcode"/>
</xpath>
</field>
</record>


Also, already we have the product_id field in the order line, you can remove the one of the field barcode_id you have defined and change the other field as follows,

barcode = fields.Char(related='product_id.barcode', string="Product Barcode", store=True).


Thanks

Avatar
Discard
Author Best Answer

@Cybrosys Techno Solutions Pvt.Ltd

That I have already done it in product.template.product.tree view. But now I want to display it in sale.order.tree view. So how can I do it with custom addons?

I tried creating barcode_id (a many2one field) in sale.order model and after that i created a related field 'barcode'.

barcode_id = fields.Many2one(comodel_name="product.product")

barcode = fields.Char(related='barcode_id.barcode', string="Product Barcode", required=False, store=True).

I am getting the 'Product Barcode' column in sale.order.tree view, but the product barcode is not displayed in the column.

Avatar
Discard

Hi, If you are looking to add a barcode field inside the sale order line by a custom module, please see the coding done for this module which is available in the store for free: https://apps.odoo.com/apps/modules/11.0/barcode_scanning_sale_purchase/

Also see the updated answer :)