New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Delete Error #30047

Closed
wants to merge 3 commits into
base: 12.0
from

Conversation

Projects
None yet
5 participants
@Alexcn
Copy link
Contributor

Alexcn commented Jan 9, 2019

Description of the issue/feature this PR addresses:

addons/product/models/product.py in line 360
If a product has two variant, and ONE is NOT active, this statement other_products = self.search([('product_tmpl_id', '=', product.product_tmpl_id.id), ('id', '!=', product.id)]) cannot search the inactive one.
It should be like this:

other_products = self.search([('product_tmpl_id', '=', product.product_tmpl_id.id), ('id', '!=', product.id), '|', ('active', '=', False), ('active', '=', True)])

Current behavior before PR:

If the product has two or more variant, and only one is active, the database will prevent to delete it for data consistency purpose.

Desired behavior after PR is merged:

If a product has two or more variant, and only one is active, we should not delete it.

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@@ -357,7 +357,8 @@ def unlink(self):
if not product.exists():
continue
# Check if the product is last product of this template...
other_products = self.search([('product_tmpl_id', '=', product.product_tmpl_id.id), ('id', '!=', product.id)])
other_products = self.search([('product_tmpl_id', '=', product.product_tmpl_id.id), ('id', '!=', product.id),\

This comment has been minimized.

@fmdl

fmdl Jan 9, 2019

Contributor

Hi @Alexcn there are a better way to search on all records:
other_products = self.with_context(active_test=False).search([('product_tmpl_id', '=', product.product_tmpl_id.id), ('id', '!=', product.id)])

This comment has been minimized.

@javierjcf

javierjcf Jan 9, 2019

Contributor

I think it must be:
other_products = self.with_context(active_test=False).search([('product_tmpl_id', '=', product.product_tmpl_id.id), ('id', '!=', self.ids)])

Because if you delete all variants of a template, other_products is allways returning a record and the variant is not deleted

This comment has been minimized.

@Alexcn

Alexcn Jan 10, 2019

Contributor

I think may use a better way:

other_products = self.env['product.product'].with_context(active_test=False).\
                                    search([('product_tmpl_id', '=', product.product_tmpl_id.id), ('id', 'not in', self.ids)])

Beacuse ('id', '!=', self.ids) could trigger a warning:

image

My new PR: #30094

@mreficent

This comment has been minimized.

Copy link
Contributor

mreficent commented Jan 9, 2019

This PR should be closed, because #30069 fixes the same for previous version, then will be forward ported.

@robodoo robodoo removed the CI 🤖 label Jan 10, 2019

@mreficent

This comment has been minimized.

Copy link
Contributor

mreficent commented Jan 10, 2019

@Alexcn as you also created the #30094, that is the same that this one, then close this one, in order to not have duplicated PRs.

@Alexcn

This comment has been minimized.

Copy link
Contributor

Alexcn commented Jan 12, 2019

OK, I will close this PR.

@Alexcn Alexcn closed this Jan 12, 2019

@robodoo robodoo added closed 💔 and removed CI 🤖 labels Jan 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment