2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
2018-01-16 06:58:15 +01:00
|
|
|
try:
|
|
|
|
from unittest.mock import patch
|
|
|
|
except ImportError:
|
|
|
|
from mock import patch
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra.tests.common import TransactionCase
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestWebsitePriceList(TransactionCase):
|
|
|
|
|
|
|
|
# Mock nedded because request.session doesn't exist during test
|
|
|
|
def _get_pricelist_available(self, show_visible=False):
|
|
|
|
return self.get_pl(self.args.get('show'), self.args.get('current_pl'), self.args.get('country'))
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestWebsitePriceList, self).setUp()
|
|
|
|
self.env.user.partner_id.country_id = False # Remove country to avoid property pricelist computed.
|
|
|
|
self.website = self.env['website'].browse(1)
|
|
|
|
self.website.user_id = self.env.user
|
|
|
|
|
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
|
|
|
self.env['product.pricelist'].search([]).write({'website_ids': []})
|
2018-01-16 06:58:15 +01:00
|
|
|
website_pls = ('list_benelux', 'list_christmas', 'list_europe')
|
|
|
|
for pl in website_pls:
|
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
|
|
|
self.env.ref('website_sale.' + pl).website_ids = [(6, 0, [self.website.id])]
|
|
|
|
self.env.ref('product.list0').website_ids = [(6, 0, [self.website.id])]
|
|
|
|
self.env.ref('website_sale.list_benelux').selectable = True
|
2018-01-16 06:58:15 +01:00
|
|
|
self.website.pricelist_id = self.ref('product.list0')
|
|
|
|
|
|
|
|
ca_group = self.env['res.country.group'].create({
|
|
|
|
'name': 'Canada',
|
|
|
|
'country_ids': [(6, 0, [self.ref('base.ca')])]
|
|
|
|
})
|
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
|
|
|
self.env['product.pricelist'].create({
|
2018-01-16 06:58:15 +01:00
|
|
|
'name': 'Canada',
|
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
|
|
|
'selectable': True,
|
|
|
|
'website_ids': [(6, 0, [self.website.id])],
|
2018-01-16 06:58:15 +01:00
|
|
|
'country_group_ids': [(6, 0, [ca_group.id])],
|
|
|
|
'sequence': 10
|
|
|
|
})
|
2018-01-16 11:34:37 +01:00
|
|
|
patcher = patch('flectra.addons.website_sale.models.website.Website.get_pricelist_available', wraps=self._get_pricelist_available)
|
2018-01-16 06:58:15 +01:00
|
|
|
patcher.start()
|
|
|
|
self.addCleanup(patcher.stop)
|
|
|
|
|
|
|
|
def get_pl(self, show, current_pl, country):
|
|
|
|
pls = self.website._get_pl(
|
|
|
|
country,
|
|
|
|
show,
|
|
|
|
self.website.pricelist_id.id,
|
|
|
|
current_pl,
|
|
|
|
self.website.pricelist_ids
|
|
|
|
)
|
|
|
|
return pls
|
|
|
|
|
|
|
|
def _test_get_pricelist_available_show(self):
|
|
|
|
show = True
|
|
|
|
current_pl = False
|
|
|
|
|
|
|
|
country_list = {
|
|
|
|
False: ['USD', 'EUR', 'Benelux', 'Canada'],
|
|
|
|
'BE': ['EUR', 'Benelux'],
|
|
|
|
'IT': ['EUR'],
|
|
|
|
'CA': ['Canada'],
|
|
|
|
'US': ['USD', 'EUR', 'Benelux', 'Canada']
|
|
|
|
}
|
|
|
|
for country, result in country_list.items():
|
|
|
|
pls = self.get_pl(show, current_pl, country)
|
|
|
|
self.assertEquals(len(set(pls.mapped('name')) & set(result)), len(pls), 'Test failed for %s (%s %s vs %s %s)'
|
|
|
|
% (country, len(pls), pls.mapped('name'), len(result), result))
|
|
|
|
|
|
|
|
def _test_get_pricelist_available_not_show(self):
|
|
|
|
show = False
|
|
|
|
current_pl = False
|
|
|
|
|
|
|
|
country_list = {
|
|
|
|
False: ['USD', 'EUR', 'Benelux', 'Christmas', 'Canada'],
|
|
|
|
'BE': ['EUR', 'Benelux', 'Christmas'],
|
|
|
|
'IT': ['EUR', 'Christmas'],
|
|
|
|
'US': ['USD', 'EUR', 'Benelux', 'Christmas', 'Canada'],
|
|
|
|
'CA': ['Canada']
|
|
|
|
}
|
|
|
|
|
|
|
|
for country, result in country_list.items():
|
|
|
|
pls = self.get_pl(show, current_pl, country)
|
|
|
|
self.assertEquals(len(set(pls.mapped('name')) & set(result)), len(pls), 'Test failed for %s (%s %s vs %s %s)'
|
|
|
|
% (country, len(pls), pls.mapped('name'), len(result), result))
|
|
|
|
|
|
|
|
def _test_get_pricelist_available_promocode(self):
|
|
|
|
christmas_pl = self.ref('website_sale.list_christmas')
|
|
|
|
public_pl = self.ref('product.list0')
|
|
|
|
self.args = {
|
|
|
|
'show': False,
|
|
|
|
'current_pl': public_pl,
|
|
|
|
}
|
|
|
|
|
|
|
|
country_list = {
|
|
|
|
False: True,
|
|
|
|
'BE': True,
|
|
|
|
'IT': True,
|
|
|
|
'US': True,
|
|
|
|
'CA': False
|
|
|
|
}
|
|
|
|
|
|
|
|
for country, result in country_list.items():
|
|
|
|
self.args['country'] = country
|
|
|
|
# mock patch method could not pass env context
|
|
|
|
available = self.website.is_pricelist_available(christmas_pl)
|
|
|
|
if result:
|
|
|
|
self.assertTrue(available, 'AssertTrue failed for %s' % country)
|
|
|
|
else:
|
|
|
|
self.assertFalse(available, 'AssertFalse failed for %s' % country)
|
|
|
|
|
|
|
|
def test_get_pricelist_available_show_with_auto_property(self):
|
|
|
|
show = True
|
|
|
|
self.env.user.partner_id.country_id = self.env.ref('base.be') # Add EUR pricelist auto
|
|
|
|
current_pl = False
|
|
|
|
|
|
|
|
country_list = {
|
|
|
|
False: ['USD', 'EUR', 'Benelux', 'Canada'],
|
|
|
|
'BE': ['EUR', 'Benelux'],
|
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
|
|
|
'IT': ['Benelux', 'USD', 'Canada'],
|
2018-01-16 06:58:15 +01:00
|
|
|
'CA': ['EUR', 'Canada'],
|
|
|
|
'US': ['USD', 'EUR', 'Benelux', 'Canada']
|
|
|
|
}
|
|
|
|
for country, result in country_list.items():
|
|
|
|
pls = self.get_pl(show, current_pl, country)
|
|
|
|
self.assertEquals(len(set(pls.mapped('name')) & set(result)), len(pls), 'Test failed for %s (%s %s vs %s %s)'
|
|
|
|
% (country, len(pls), pls.mapped('name'), len(result), result))
|