Skip to content
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

[12.0][FWD] Fix delete synchronisation #643

Merged
merged 2 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shopinvader/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ def _get_invader_variant(self, backend, lang):
return self.shopinvader_bind_ids.filtered(
lambda x: x.backend_id == backend and x.lang_id.code == lang
)

def unlink(self):
# Call unlink manually to be sure to trigger
# shopinvader variant unlink constraint
self.mapped("shopinvader_bind_ids").unlink()
return super(ProductProduct, self).unlink()
6 changes: 6 additions & 0 deletions shopinvader/models/shopinvader_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,9 @@ def _redirect_existing_url(self):
}
)
return True

def unlink(self):
# Call unlink manually to be sure to trigger
# shopinvader variant unlink constraint
self.mapped("shopinvader_variant_ids").unlink()
return super(ShopinvaderProduct, self).unlink()
1 change: 1 addition & 0 deletions shopinvader_search_engine/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_delete_product
64 changes: 64 additions & 0 deletions shopinvader_search_engine/tests/test_delete_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2019 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.exceptions import UserError
from odoo.tests import SavepointCase


class BindingCase(SavepointCase):
@classmethod
def setUpClass(cls):
super(BindingCase, cls).setUpClass()
cls.template = cls.env["product.template"].create({"name": "Test"})
cls.product = cls.template.product_variant_ids
cls.shopinvader_product = (
cls.env["shopinvader.product"]
.with_context(map_children=True)
.create(
{
"record_id": cls.template.id,
"backend_id": cls.env.ref("shopinvader.backend_1").id,
"lang_id": cls.env.ref("base.lang_en").id,
}
)
)
cls.shopinvader_variant = (
cls.shopinvader_product.shopinvader_variant_ids
)


class BindingDoneCase(BindingCase):
@classmethod
def setUpClass(cls):
super(BindingDoneCase, cls).setUpClass()
cls.shopinvader_variant.write({"sync_state": "done"})

def test_unlink_shopinvader_product(self):
with self.assertRaises(UserError):
self.shopinvader_product.unlink()

def test_unlink_product_product(self):
with self.assertRaises(UserError):
self.product.unlink()

def test_unlink_product_template(self):
with self.assertRaises(UserError):
self.template.unlink()


class BindingInactiveDoneCase(BindingCase):
@classmethod
def setUpClass(cls):
super(BindingInactiveDoneCase, cls).setUpClass()
cls.shopinvader_variant.active = False
cls.shopinvader_variant.sync_state = "done"

def test_unlink_shopinvader_product(self):
self.shopinvader_product.unlink()

def test_unlink_product_product(self):
self.product.unlink()

def test_unlink_product_template(self):
self.template.unlink()