summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormgh-odoo <mgh@odoo.com>2019-04-08 15:55:02 +0000
committerRomain Derie <rde@odoo.com>2019-04-10 06:49:37 +0000
commitb993a2d9c824050e1c3cf566d4bf9d8eb75c3f41 (patch)
treecd6ae81ef5a00944c8dc78c32c4dbb31a0d4c304
parent5eaa4f2967e88f9f619bfc95e82d89fbfcd03ed0 (diff)
[IMP] website_sale: restrict deleting/archiving pricelist for ecommerce
Before this commit, if none of the pricelist is available for the website then frontend ecommerce will crash. This issue is arrived from #30675 PR. The reason behind crash is, if there is no pricelist associated with the website then the ecommerce will not get the currency and breaks the frontend shop. This commit will restrict user from making those changes which breaks the frontend shop. We will ensure that atleast one pricelist is available for each website. task-1966811 Closes: #32534 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
-rw-r--r--addons/website_sale/models/product.py10
-rw-r--r--addons/website_sale/tests/test_website_sale_pricelist.py4
2 files changed, 12 insertions, 2 deletions
diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py
index 3705d7b3cb3..c3c641bedff 100644
--- a/addons/website_sale/models/product.py
+++ b/addons/website_sale/models/product.py
@@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, tools, _
-from odoo.exceptions import ValidationError
+from odoo.exceptions import ValidationError, UserError
from odoo.addons import decimal_precision as dp
from odoo.addons.website.models import ir_http
from odoo.tools.translate import html_translate
@@ -55,12 +55,15 @@ class ProductPricelist(models.Model):
@api.multi
def write(self, data):
res = super(ProductPricelist, self).write(data)
+ if data.keys() & {'code', 'active', 'website_id', 'selectable'}:
+ self._check_website_pricelist()
self.clear_cache()
return res
@api.multi
def unlink(self):
res = super(ProductPricelist, self).unlink()
+ self._check_website_pricelist()
self.clear_cache()
return res
@@ -78,6 +81,11 @@ class ProductPricelist(models.Model):
res = res.filtered(lambda pl: pl._is_available_on_website(website.id))
return res
+ def _check_website_pricelist(self):
+ for website in self.env['website'].search([]):
+ if not website.pricelist_ids:
+ raise UserError(_("With this action, '%s' website would not have any pricelist available.") % (website.name))
+
@api.multi
def _is_available_on_website(self, website_id):
""" To be able to be used on a website, a pricelist should either:
diff --git a/addons/website_sale/tests/test_website_sale_pricelist.py b/addons/website_sale/tests/test_website_sale_pricelist.py
index eb3b9d5d1f6..52858e3d8a8 100644
--- a/addons/website_sale/tests/test_website_sale_pricelist.py
+++ b/addons/website_sale/tests/test_website_sale_pricelist.py
@@ -65,6 +65,7 @@ class TestWebsitePriceList(TransactionCase):
self.addCleanup(patcher.stop)
def get_pl(self, show, current_pl, country):
+ self.website.invalidate_cache(['pricelist_ids'], [self.website.id])
pl_ids = self.website._get_pl_partner_order(
country,
show,
@@ -185,7 +186,7 @@ class TestWebsitePriceListAvailable(TransactionCase):
self.website2 = Website.create({'name': 'Website 2'})
# Remove existing pricelists and create new ones
- Pricelist.search([]).write({'active': False})
+ existing_pricelists = Pricelist.search([])
self.backend_pl = Pricelist.create({
'name': 'Backend Pricelist',
'website_id': False,
@@ -230,6 +231,7 @@ class TestWebsitePriceListAvailable(TransactionCase):
'name': 'Website 2 Pricelist',
'website_id': self.website2.id,
})
+ existing_pricelists.write({'active': False})
simulate_frontend_context(self)