Hi,
another similar question:
prod = self.env['product.template'].search([('default_code', '=ilike', row['internalReference'])], limit=1)
if not prod: # Check if exists and archived
prod = self.env['product.template'].search([('default_code', '=ilike', row['internalReference']),
('active', '=', False)], limit=1)
This wrote a freelancer ... why did he check extra if the product is active?
In the first query he also get the product, even when its archived ... right?
So why again a second check?
and when I want first to check if the product with barcode "xy" exists, I use:
# check if product with barcode exists
prod = self.env['product.template'].search([('barcode', '=ilike', row['barcode'])], limit=1)
if not prod: # check if product with barcode exists and is not active
prod = self.env['product.template'].search([('barcode', '=ilike', row['barcode']),
('active', '=', False)], limit=1)
if not prod: # Check if exists
prod = self.env['product.template'].search([('default_code', '=ilike', row['internalReference'])], limit=1)
if not prod: # Check if exists and archived
prod = self.env['product.template'].search([('default_code', '=ilike', row['internalReference']),
('active', '=', False)], limit=1)
But the barcode is in product_product table .. did I get this with the query product.template?