Some clients use the same barcode for products in different companies,
with different configuration. It is inconvenient for those users to have
to ensure the uniqueness of barcodes across all companies.
This commit will allow products to have duplicated barcodes, as long as
they are assigned to different companies. Products without a company are
treated as belonging to all companies. Product variants require unique barcodes.
The validation needs to be triggered both on barcode and company_id, so
product template (where company_id is stored) was also adjusted.
NOTE: when a barcode is duplicated in 2 companies, an attempt to remove
both the company and the barcode from a product will result in an
error, despite the fact that a product without a company and a barcode
would have a correct configuration. This happens because the barcode
uniqueness check is performed before changing the barcode, but after
changing the company. A workaround for this problem is to remove the
barcode first, save the product, and remove the company.
Task: 3290154
Related task: 3270732
Related: odoo/enterprise#42541
Part-of: odoo/odoo#122511