Skip to Content
Menu
This question has been flagged
9 Replies
10633 Views

Odoo CE 10

It seems that when you archive a product the barcode and the cost temporarily disappear from the product for some reason (even though they are still stored in database and show up when re-activated).  This makes it impossible to search archived items by barcode.  So lets say you want to add a new item and you get the "Cannot add item: this barcode already exists" message.  This means you cannot search the archived items for the matching  barcode and simply re-activate it.  I currently have to:

1) Search archived products by name or other filter

2) Temporarily un-archive product to "see" the barcode and check if it's my match

3 If it's not a match, repeat this process with all the filtered archived items until I find my barcode match and un-archive it

Is this the normal behavior?  How can I make this easier?  Thank you!

Avatar
Discard

Hello @Keegan,

I need barcode feature for my system Odoo CE 10. So, Can you help me by providing your barcode code or task perform by you to implement this feature.

Thanks,

Hello @Keegan,

I am also need barcode functionality for odoo10 Community Edition. So Can you tell me how to perform this functionality.

Best Answer

Hi,

This can be done by passing this value in the context of your view: {'active_test': False,}

Like for eg:  

<filter string="Archived" name="inactive" context="{'active_test': False}" domain="[('active','=',False)]"/>


Avatar
Discard
Best Answer

Archived records are NEVER included in any standard search..

If you use self.env['sale.order'].search([]), it will retrieve every sale order in your system.. Except the ones that are archived. This is standard.

This mean that, indeed, if you search a product over its barcode, the search function will NOT find your archived product.
However, if a SQL constrains is defined over the field, then it will still be triggered uppon insertion of a new record (meaning you won't be able to add a new product with the same barcode if a unique(barcode) constrains is set in the database)

The only way of including the archived records in a search is to specifically add a filter in the search function. 

You could add the filters ['|', ('active','=',True),  ('active','=',False)] to the search method whenever you need to search for any product (wether they are inactive or not) 

Avatar
Discard

This is a great answer for programmatic searching. I think from some of the clues in the post, like "temporarily un-archive product" and "filtered archived items" that the question may be about searching via the UI.

Author

Correct. This is a function I was hoping an end-user can do from the web UI. If not possible by default, I can possibly use the info in the previous answer to make a custom module for this? Users need to be able to find products by barcode whether archived or not.

you can also do that from the UI.

On the search bar, click on the "+", "filters", "add a custom filter", "active is false", "add a condition", "active is true".

This will create a filter "active is false or active is true".

you can then save the current search.

All the products will now be displayed in the tree view by default.

Author

I know how to display all the items in the list view, but this still does not allow for searching them by barcode, try for yourself.

I just tested with that specific case and indeed it act kind of weird.

The barcode field is defined on product.product. So if you go in the product variants, you'll be able to search over that field.

However, on the product.template, the field barcode is defined as related to the variant_ids:

barcode = fields.Char('Barcode', oldname='ean13', related='product_variant_ids.barcode')

and indeed when a record with a related field is archived, the relation might be broken until you un-archive the record.

If you want to solve this completely using the GUI, i think there is only a dirty way of doing it :/.

- install Studio

- add a new field on the product.template form view

- go to its properties, then click on "more"

- make it computed, stored, and dependent on "barcode"

- then use this kind of code:

for product in self:

if product.product_variant_ids[0]:

product['x_permanent_barcode'] = product.product_variant_ids[0].barcode

where x_permanent_barcode is the name of the field you are defining.

By doing so, you will be able to search over the value of x_permanent_barcode, this time, even archiving the record will NOT remove that value.

However, as i said, you'll still have to use a custom filter (programmaticaly or from the GUI) to be able to search for archived records.

We never use studio, so i would of course recommand creating a custom module that fits your needs, for example by directly redifining the barcode field on product.product (remove the related=.. and make it computed), but if you specifically need to use only the GUI, this would work.