From 0d8e89474b2b0f2debf2237f1f00af89bdfe067c Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Mon, 18 Oct 2021 16:15:43 -0300 Subject: [PATCH 01/10] [ADD]website_sale_product_multi_website:new module --- website_sale_product_multi_website/README.rst | 0 .../__init__.py | 2 + .../__manifest__.py | 14 +++++ website_sale_product_multi_website/hooks.py | 7 +++ .../models/__init__.py | 1 + .../models/product_template.py | 15 +++++ .../views/product_template_views.xml | 56 +++++++++++++++++++ 7 files changed, 95 insertions(+) create mode 100644 website_sale_product_multi_website/README.rst create mode 100644 website_sale_product_multi_website/__init__.py create mode 100644 website_sale_product_multi_website/__manifest__.py create mode 100644 website_sale_product_multi_website/hooks.py create mode 100644 website_sale_product_multi_website/models/__init__.py create mode 100644 website_sale_product_multi_website/models/product_template.py create mode 100644 website_sale_product_multi_website/views/product_template_views.xml diff --git a/website_sale_product_multi_website/README.rst b/website_sale_product_multi_website/README.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_sale_product_multi_website/__init__.py b/website_sale_product_multi_website/__init__.py new file mode 100644 index 0000000000..cc6b6354ad --- /dev/null +++ b/website_sale_product_multi_website/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook diff --git a/website_sale_product_multi_website/__manifest__.py b/website_sale_product_multi_website/__manifest__.py new file mode 100644 index 0000000000..bf33b03e5a --- /dev/null +++ b/website_sale_product_multi_website/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "Multi-website product", + "summary": "Show products in many web-sites", + "version": "13.0.1.0.0", + "category": "Website", + "author": "Odoo Community Association (OCA), Adhoc S.A.", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["website_sale"], + "data": ["views/product_template_views.xml"], + "demo": [], + "post_init_hook": "post_init_hook", +} diff --git a/website_sale_product_multi_website/hooks.py b/website_sale_product_multi_website/hooks.py new file mode 100644 index 0000000000..f667849a08 --- /dev/null +++ b/website_sale_product_multi_website/hooks.py @@ -0,0 +1,7 @@ +from odoo import SUPERUSER_ID, api + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + for rec in env["product.template"].with_context(active_test=False).search([]): + rec.website_ids += rec.website_id diff --git a/website_sale_product_multi_website/models/__init__.py b/website_sale_product_multi_website/models/__init__.py new file mode 100644 index 0000000000..e8fa8f6bf1 --- /dev/null +++ b/website_sale_product_multi_website/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/website_sale_product_multi_website/models/product_template.py b/website_sale_product_multi_website/models/product_template.py new file mode 100644 index 0000000000..c8b9675f28 --- /dev/null +++ b/website_sale_product_multi_website/models/product_template.py @@ -0,0 +1,15 @@ +from odoo import fields, models +from odoo.http import request + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + website_ids = fields.Many2many("website", string="Websites") + + def can_access_from_current_website(self, website_id=False): + website_id = website_id or request.website.id + for rec in self.filtered(lambda x: x.website_ids): + if website_id not in rec.website_ids.ids: + return False + return True diff --git a/website_sale_product_multi_website/views/product_template_views.xml b/website_sale_product_multi_website/views/product_template_views.xml new file mode 100644 index 0000000000..3291907205 --- /dev/null +++ b/website_sale_product_multi_website/views/product_template_views.xml @@ -0,0 +1,56 @@ + + + product.template.inherit.view.form + product.template + + + + 1 + + + + + + + + product.product.website.inherit.view.tree + product.product + + + + 1 + + + + + + + + product_template_view_tree.view.tree + product.template + + + + 1 + + + + + + + From 8bd5722139b024b14dd409be4e54fe3134892061 Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Tue, 26 Oct 2021 11:54:35 -0300 Subject: [PATCH 02/10] wip --- .../models/product_template.py | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/website_sale_product_multi_website/models/product_template.py b/website_sale_product_multi_website/models/product_template.py index c8b9675f28..6fb0df39c9 100644 --- a/website_sale_product_multi_website/models/product_template.py +++ b/website_sale_product_multi_website/models/product_template.py @@ -1,5 +1,9 @@ -from odoo import fields, models +from odoo import api, fields, models from odoo.http import request +from odoo.osv import expression +import logging + +_logger = logging.getLogger(__name__) class ProductTemplate(models.Model): @@ -8,8 +12,38 @@ class ProductTemplate(models.Model): website_ids = fields.Many2many("website", string="Websites") def can_access_from_current_website(self, website_id=False): + """ We overwrite this method completely in order to use the website_ids logic instead of website_id """ website_id = website_id or request.website.id for rec in self.filtered(lambda x: x.website_ids): if website_id not in rec.website_ids.ids: return False return True + + @api.depends('is_published', 'website_ids') + @api.depends_context('website_id') + def _compute_website_published(self): + """ We overwrite this method completely in order to use the website_ids logic instead of website_id """ + current_website_id = self._context.get('website_id') + for record in self: + if current_website_id: + record.website_published = record.is_published and ( + not record.website_ids or current_website_id in record.website_ids.ids) + else: + record.website_published = record.is_published + + def _search_website_published(self, operator, value): + """ We overwrite this method completely in order to use the website_ids logic instead of website_id """ + if not isinstance(value, bool) or operator not in ('=', '!='): + _logger.warning('unsupported search on website_published: %s, %s', operator, value) + return [()] + + if operator in expression.NEGATIVE_TERM_OPERATORS: + value = not value + + current_website_id = self._context.get('website_id') + is_published = [('is_published', '=', value)] + if current_website_id: + on_current_website = ['|'] + [('website_ids', 'ilike', item) for item in (False, current_website_id)] + return (['!'] if value is False else []) + expression.AND([is_published, on_current_website]) + else: # should be in the backend, return things that are published anywhere + return is_published From e25421558c55a24836bfbf25e62ca4e02f9d682d Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Wed, 27 Oct 2021 10:54:12 -0300 Subject: [PATCH 03/10] wip2 --- .../models/product_template.py | 18 + .../tests/tours/website_sale_complete_flow.js | 386 ++++++++++++++++++ .../tests/__init__.py | 2 + .../website_sale_product_multi_website.py | 22 + 4 files changed, 428 insertions(+) create mode 100644 website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js create mode 100644 website_sale_product_multi_website/tests/__init__.py create mode 100644 website_sale_product_multi_website/tests/website_sale_product_multi_website.py diff --git a/website_sale_product_multi_website/models/product_template.py b/website_sale_product_multi_website/models/product_template.py index 6fb0df39c9..140fefbaef 100644 --- a/website_sale_product_multi_website/models/product_template.py +++ b/website_sale_product_multi_website/models/product_template.py @@ -47,3 +47,21 @@ def _search_website_published(self, operator, value): return (['!'] if value is False else []) + expression.AND([is_published, on_current_website]) else: # should be in the backend, return things that are published anywhere return is_published + + +# # TODO KZ If it works move it to new file +# class ProductPublicCategory(models.Model): +# # _inherit = ["product.public.category", "website.published.mixin"] +# # _name = "product.public.category" +# _inherit = "product.public.category" +# website_ids = fields.Many2many("website", string="Websites") + +# class Website(models.Model): + +# _inherit = "website" + +# @api.model +# def website_domain(self, website_id=False): +# res = ['|'] + [('website_ids', 'ilike', item) for item in (False, website_id or self.id)] +# print(" --- website_domain %s" % res) +# return res diff --git a/website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js b/website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js new file mode 100644 index 0000000000..0aa9a2d250 --- /dev/null +++ b/website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js @@ -0,0 +1,386 @@ +odoo.define('website_sale_tour.tour', function (require) { + 'use strict'; + + var tour = require("web_tour.tour"); + var rpc = require("web.rpc"); + + tour.register('website_sale_tour', { + test: true, + url: '/shop?search=Storage Box', + }, [ + // Testing b2c with Tax-Excluded Prices + { + content: "Open product page", + trigger: '.oe_product_cart a:contains("Storage Box")', + }, + { + content: "Add one more storage box", + trigger: '.js_add_cart_json:eq(1)', + }, + { + content: "Check b2b Tax-Excluded Prices", + trigger: '.product_price .oe_price .oe_currency_value:containsExact(79.00)', + run: function () {}, // it's a check + }, + { + content: "Click on add to cart", + trigger: '#add_to_cart', + }, + { + content: "Check for 2 products in cart and proceed to checkout", + extra_trigger: '#cart_products tr:contains("Storage Box") input.js_quantity:propValue(2)', + trigger: 'a[href*="/shop/checkout"]', + }, + { + content: "Check Price b2b subtotal", + trigger: 'tr#order_total_untaxed .oe_currency_value:containsExact(158.00)', + run: function () {}, // it's a check + }, + { + content: "Check Price b2b Sale Tax(15%)", + trigger: 'tr#order_total_taxes .oe_currency_value:containsExact(23.70)', + run: function () {}, // it's a check + }, + { + content: "Check Price b2b Total amount", + trigger: 'tr#order_total .oe_currency_value:containsExact(181.70)', + run: function () {}, // it's a check + }, + { + content: "Fulfill billing address form", + trigger: 'select[name="country_id"]', + run: function () { + $('input[name="name"]').val('abc'); + $('input[name="phone"]').val('99999999'); + $('input[name="email"]').val('abc@odoo.com'); + $('input[name="street"]').val('SO1 Billing Street, 33'); + $('input[name="city"]').val('SO1BillingCity'); + $('#country_id option:eq(1)').attr('selected', true); + }, + }, + { + content: "Shipping address is not same as billing address", + trigger: '#shipping_use_same', + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Fulfill shipping address form", + trigger: 'select[name="country_id"]', + extra_trigger: 'h2:contains("Shipping Address")', + run: function () { + $('input[name="name"]').val('def'); + $('input[name="phone"]').val('8888888888'); + $('input[name="street"]').val('17, SO1 Shipping Road'); + $('input[name="city"]').val('SO1ShippingCity'); + $('#country_id option:eq(1)').attr('selected', true); + }, + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Check selected billing address is same as typed in previous step", + trigger: '#shipping_and_billing:contains(SO1 Billing Street, 33):contains(SO1BillingCity):contains(Afghanistan)', + run: function () {}, // it's a check + }, + { + content: "Check selected shipping address is same as typed in previous step", + trigger: '#shipping_and_billing:contains(17, SO1 Shipping Road):contains(SO1ShippingCity):contains(Afghanistan)', + run: function () {}, // it's a check + }, + { + content: "Click for edit address", + trigger: 'a:contains("Edit") i', + }, + { + content: "Click for edit billing address", + trigger: '.js_edit_address:first', + }, + { + content: "Change billing address form", + trigger: 'select[name="country_id"]', + extra_trigger: 'h2:contains("Your Address")', + run: function () { + $('input[name="name"]').val('abcd'); + $('input[name="phone"]').val('11111111'); + $('input[name="street"]').val('SO1 Billing Street Edited, 33'); + $('input[name="city"]').val('SO1BillingCityEdited'); + }, + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Confirm Address", + trigger: 'a.btn:contains("Confirm")', + }, + { + content: "Check selected billing address is same as typed in previous step", + trigger: '#shipping_and_billing:contains(SO1 Billing Street Edited, 33):contains(SO1BillingCityEdited):contains(Afghanistan)', + run: function () {}, // it's a check + }, + { + content: "Select `Wire Transfer` payment method", + trigger: '#payment_method label:contains("Wire Transfer")', + }, + { + content: "Pay Now", + extra_trigger: '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', + trigger: 'button[id="o_payment_form_pay"]:visible:not(:disabled)', + }, + { + content: "Sign up", + trigger: '.oe_cart a:contains("Sign Up")', + }, + { + content: "Submit login", + trigger: '.oe_signup_form', + run: function () { + $('.oe_signup_form input[name="password"]').val("1admin@admin"); + $('.oe_signup_form input[name="confirm_password"]').val("1admin@admin"); + $('.oe_signup_form').submit(); + }, + }, + { + content: "See Quotations", + trigger: '.o_portal_docs a:contains("Quotations")', + }, + // Sign in as admin change config auth_signup -> b2b, sale_show_tax -> total and Logout + { + content: "Open Dropdown for logout", + trigger: '#top_menu li.dropdown:visible a:contains("abcd")', + }, + { + content: "Logout", + trigger: '#o_logout:contains("Logout")', + }, + { + content: "Sign in as admin", + trigger: '#top_menu li a b:contains("Sign in")', + }, + { + content: "Submit login", + trigger: '.oe_login_form', + run: function () { + $('.oe_login_form input[name="login"]').val("admin"); + $('.oe_login_form input[name="password"]').val("admin"); + $('.oe_login_form input[name="redirect"]').val("/"); + $('.oe_login_form').submit(); + }, + }, + { + content: "Configuration Settings for 'Tax Included' and sign up 'On Invitation'", + extra_trigger: '.o_connected_user #wrapwrap', + trigger: '#wrapwrap', + run: function () { + var def1 = rpc.query({ + model: 'res.config.settings', + method: 'create', + args: [{ + 'auth_signup_uninvited': 'b2b', + 'show_line_subtotals_tax_selection': 'tax_included', + 'group_show_line_subtotals_tax_excluded': false, + 'group_show_line_subtotals_tax_included': true, + }], + }); + var def2 = def1.then(function (resId) { + return rpc.query({ + model: 'res.config.settings', + method: 'execute', + args: [[resId]], + }); + }); + def2.then(function () { + window.location.href = '/web/session/logout?redirect=/shop?search=Storage Box'; + }); + }, + }, + // Testing b2b with Tax-Included Prices + { + content: "Open product page", + trigger: '.oe_product_cart a:contains("Storage Box")', + }, + { + content: "Add one more Storage Box", + trigger: '.js_add_cart_json:eq(1)', + }, + { + content: "Check b2c Tax-Included Prices", + trigger: '.product_price .oe_price .oe_currency_value:containsExact(90.85)', + run: function () {}, // it's a check + }, + { + content: "Click on add to cart", + trigger: '#add_to_cart', + }, + { + content: "Check for 2 products in cart and proceed to checkout", + extra_trigger: '#cart_products tr:contains("Storage Box") input.js_quantity:propValue(2)', + trigger: 'a[href*="/shop/checkout"]', + }, + { + content: "Check Price b2c total", + trigger: 'tr#order_total_untaxed .oe_currency_value:containsExact(158.00)', + run: function () {}, // it's a check + }, + { + content: "Check Price b2c Sale Tax(15%)", + trigger: 'tr#order_total_taxes .oe_currency_value:containsExact(23.70)', + run: function () {}, // it's a check + }, + { + content: "Check Price b2c Total amount", + trigger: 'tr#order_total .oe_currency_value:containsExact(181.70)', + run: function () {}, // it's a check + }, + { + content: "Click on Login Button", + trigger: '.oe_cart a.btn:contains("Log In")', + }, + { + content: "Submit login", + trigger: '.oe_login_form', + run: function () { + $('.oe_login_form input[name="login"]').val("abc@odoo.com"); + $('.oe_login_form input[name="password"]').val("1admin@admin"); + $('.oe_login_form').submit(); + }, + }, + { + content: "Add new shipping address", + trigger: '.one_kanban form[action^="/shop/address"] .btn', + }, + { + content: "Fulfill shipping address form", + trigger: 'select[name="country_id"]', + run: function () { + $('input[name="name"]').val('ghi'); + $('input[name="phone"]').val('7777777777'); + $('input[name="street"]').val('SO2New Shipping Street, 5'); + $('input[name="city"]').val('SO2NewShipping'); + $('#country_id option:eq(1)').attr('selected', true); + }, + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Select `Wire Transfer` payment method", + trigger: '#payment_method label:contains("Wire Transfer")', + }, + { + content: "Pay Now", + extra_trigger: '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', + trigger: 'button[id="o_payment_form_pay"]:visible:not(:disabled)', + }, + { + content: "Open Dropdown for See quotation", + extra_trigger: '.oe_cart .oe_website_sale_tx_status', + trigger: '#top_menu li.dropdown:visible a:contains("abc")', + }, + { + content: "My account", + extra_trigger: '#top_menu li.dropdown .js_usermenu.show', + trigger: '#top_menu .dropdown-menu a[href="/my/home"]:visible', + }, + { + content: "See Quotations", + trigger: '.o_portal_docs a:contains("Quotations") .badge:containsExact(2)', + }, + + // enable extra step on website checkout and check extra step on checkout process + { + content: "Open Dropdown for logout", + trigger: '#top_menu li.dropdown:visible a:contains("abc")', + }, + { + content: "Logout", + trigger: '#o_logout:contains("Logout")', + }, + { + content: "Sign in as admin", + trigger: '#top_menu li a b:contains("Sign in")', + }, + { + content: "Submit login", + trigger: '.oe_login_form', + run: function () { + $('.oe_login_form input[name="login"]').val("admin"); + $('.oe_login_form input[name="password"]').val("admin"); + $('.oe_login_form input[name="redirect"]').val("/shop/cart"); + $('.oe_login_form').submit(); + }, + }, + { + content: "Open Customize menu", + trigger: '.o_menu_sections a:contains("Customize")', + }, + { + content: "Enable Extra step", + trigger: 'a.dropdown-item label:contains("Extra Step Option")', + }, + { + content: "Open Dropdown for logout", + extra_trigger: '.progress-wizard-step:contains("Extra Info")', + trigger: '#top_menu li.dropdown:visible a:contains("Mitchell Admin")', + }, + { + content: "Logout", + trigger: '#o_logout:contains("Logout")', + }, + { + content: "Sign in as abc", + trigger: '#top_menu li a b:contains("Sign in")', + }, + { + content: "Submit login", + trigger: '.oe_login_form', + run: function () { + $('.oe_login_form input[name="login"]').val("abc@odoo.com"); + $('.oe_login_form input[name="password"]').val("1admin@admin"); + $('.oe_login_form input[name="redirect"]').val("/shop?search=Storage Box"); + $('.oe_login_form').submit(); + }, + }, + { + content: "Open product page", + trigger: '.oe_product_cart a:contains("Storage Box")', + }, + { + content: "Click on add to cart", + trigger: '#add_to_cart', + }, + { + content: "Proceed to checkout", + trigger: 'a[href*="/shop/checkout"]', + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Check selected billing address is same as typed in previous step", + trigger: '#shipping_and_billing:contains(SO1 Billing Street Edited, 33):contains(SO1BillingCityEdited):contains(Afghanistan)', + run: function () {}, // it's a check + }, + { + content: "Check selected shipping address is same as typed in previous step", + trigger: '#shipping_and_billing:contains(SO2New Shipping Street, 5):contains(SO2NewShipping):contains(Afghanistan)', + run: function () {}, // it's a check + }, + { + content: "Select `Wire Transfer` payment method", + trigger: '#payment_method label:contains("Wire Transfer")', + }, + { + content: "Pay Now", + extra_trigger: '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', + trigger: 'button[id="o_payment_form_pay"]:visible', + }]); +}); diff --git a/website_sale_product_multi_website/tests/__init__.py b/website_sale_product_multi_website/tests/__init__.py new file mode 100644 index 0000000000..cc6b6354ad --- /dev/null +++ b/website_sale_product_multi_website/tests/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook diff --git a/website_sale_product_multi_website/tests/website_sale_product_multi_website.py b/website_sale_product_multi_website/tests/website_sale_product_multi_website.py new file mode 100644 index 0000000000..da977396ff --- /dev/null +++ b/website_sale_product_multi_website/tests/website_sale_product_multi_website.py @@ -0,0 +1,22 @@ +from odoo.tests + + +class TestWebsiteSaleProductMultiWebsite(tests.HttpCase): + + def setUp(self): + super().setUp() + # Create multiple websites + self.website0 = self.env['website'].create({'name': 'web0'}) + self.website1 = self.env['website'].create({'name': 'web1'}) + self.website2 = self.env['website'].create({'name': 'web2'}) + + # create a product template + self.product_template = self.env['product.template'].create({ + 'name': 'Test Product', + 'is_published': True, + 'list_price': 750, + }) + + def test_01(self): + """ Prueba que si el producto no tiene websites dicho producto esta disponible en todos los websites + """ From c5cd3e122b3bd3f789ecf5ba21eb537b093d3b73 Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Fri, 29 Oct 2021 18:25:35 -0300 Subject: [PATCH 04/10] wip --- .../__manifest__.py | 1 + website_sale_product_multi_website/hooks.py | 7 +++++++ .../models/product_template.py | 18 ------------------ .../tests/__init__.py | 4 ++-- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/website_sale_product_multi_website/__manifest__.py b/website_sale_product_multi_website/__manifest__.py index bf33b03e5a..917a277e3d 100644 --- a/website_sale_product_multi_website/__manifest__.py +++ b/website_sale_product_multi_website/__manifest__.py @@ -11,4 +11,5 @@ "data": ["views/product_template_views.xml"], "demo": [], "post_init_hook": "post_init_hook", + "uninstall_hook": "uninstall_hook", } diff --git a/website_sale_product_multi_website/hooks.py b/website_sale_product_multi_website/hooks.py index f667849a08..ea8c9fec21 100644 --- a/website_sale_product_multi_website/hooks.py +++ b/website_sale_product_multi_website/hooks.py @@ -5,3 +5,10 @@ def post_init_hook(cr, registry): env = api.Environment(cr, SUPERUSER_ID, {}) for rec in env["product.template"].with_context(active_test=False).search([]): rec.website_ids += rec.website_id + rec.website_id = False + + +def uninstall_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + for rec in env["product.template"].with_context(active_test=False).search([]): + rec.website_id = rec.website_ids[0] diff --git a/website_sale_product_multi_website/models/product_template.py b/website_sale_product_multi_website/models/product_template.py index 140fefbaef..6fb0df39c9 100644 --- a/website_sale_product_multi_website/models/product_template.py +++ b/website_sale_product_multi_website/models/product_template.py @@ -47,21 +47,3 @@ def _search_website_published(self, operator, value): return (['!'] if value is False else []) + expression.AND([is_published, on_current_website]) else: # should be in the backend, return things that are published anywhere return is_published - - -# # TODO KZ If it works move it to new file -# class ProductPublicCategory(models.Model): -# # _inherit = ["product.public.category", "website.published.mixin"] -# # _name = "product.public.category" -# _inherit = "product.public.category" -# website_ids = fields.Many2many("website", string="Websites") - -# class Website(models.Model): - -# _inherit = "website" - -# @api.model -# def website_domain(self, website_id=False): -# res = ['|'] + [('website_ids', 'ilike', item) for item in (False, website_id or self.id)] -# print(" --- website_domain %s" % res) -# return res diff --git a/website_sale_product_multi_website/tests/__init__.py b/website_sale_product_multi_website/tests/__init__.py index cc6b6354ad..79d7d2aa85 100644 --- a/website_sale_product_multi_website/tests/__init__.py +++ b/website_sale_product_multi_website/tests/__init__.py @@ -1,2 +1,2 @@ -from . import models -from .hooks import post_init_hook +# TODO wip +# from . import website_sale_product_multi_website From f1426a6928764c821938d3ae1a8674dd46c5bc86 Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Fri, 29 Oct 2021 18:47:09 -0300 Subject: [PATCH 05/10] version2 --- .../__manifest__.py | 1 - website_sale_product_multi_website/hooks.py | 6 ------ .../models/__init__.py | 1 + .../models/product_template.py | 16 +--------------- .../models/website.py | 16 ++++++++++++++++ 5 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 website_sale_product_multi_website/models/website.py diff --git a/website_sale_product_multi_website/__manifest__.py b/website_sale_product_multi_website/__manifest__.py index 917a277e3d..bf33b03e5a 100644 --- a/website_sale_product_multi_website/__manifest__.py +++ b/website_sale_product_multi_website/__manifest__.py @@ -11,5 +11,4 @@ "data": ["views/product_template_views.xml"], "demo": [], "post_init_hook": "post_init_hook", - "uninstall_hook": "uninstall_hook", } diff --git a/website_sale_product_multi_website/hooks.py b/website_sale_product_multi_website/hooks.py index ea8c9fec21..681f893154 100644 --- a/website_sale_product_multi_website/hooks.py +++ b/website_sale_product_multi_website/hooks.py @@ -6,9 +6,3 @@ def post_init_hook(cr, registry): for rec in env["product.template"].with_context(active_test=False).search([]): rec.website_ids += rec.website_id rec.website_id = False - - -def uninstall_hook(cr, registry): - env = api.Environment(cr, SUPERUSER_ID, {}) - for rec in env["product.template"].with_context(active_test=False).search([]): - rec.website_id = rec.website_ids[0] diff --git a/website_sale_product_multi_website/models/__init__.py b/website_sale_product_multi_website/models/__init__.py index e8fa8f6bf1..eafa9a1069 100644 --- a/website_sale_product_multi_website/models/__init__.py +++ b/website_sale_product_multi_website/models/__init__.py @@ -1 +1,2 @@ from . import product_template +from . import website diff --git a/website_sale_product_multi_website/models/product_template.py b/website_sale_product_multi_website/models/product_template.py index 6fb0df39c9..1b794382c0 100644 --- a/website_sale_product_multi_website/models/product_template.py +++ b/website_sale_product_multi_website/models/product_template.py @@ -1,6 +1,5 @@ from odoo import api, fields, models from odoo.http import request -from odoo.osv import expression import logging _logger = logging.getLogger(__name__) @@ -33,17 +32,4 @@ def _compute_website_published(self): def _search_website_published(self, operator, value): """ We overwrite this method completely in order to use the website_ids logic instead of website_id """ - if not isinstance(value, bool) or operator not in ('=', '!='): - _logger.warning('unsupported search on website_published: %s, %s', operator, value) - return [()] - - if operator in expression.NEGATIVE_TERM_OPERATORS: - value = not value - - current_website_id = self._context.get('website_id') - is_published = [('is_published', '=', value)] - if current_website_id: - on_current_website = ['|'] + [('website_ids', 'ilike', item) for item in (False, current_website_id)] - return (['!'] if value is False else []) + expression.AND([is_published, on_current_website]) - else: # should be in the backend, return things that are published anywhere - return is_published + return super(ProductTemplate, self.with_context(multi_website_domain=True))._search_website_published(operator, value) diff --git a/website_sale_product_multi_website/models/website.py b/website_sale_product_multi_website/models/website.py new file mode 100644 index 0000000000..2ad40f4b84 --- /dev/null +++ b/website_sale_product_multi_website/models/website.py @@ -0,0 +1,16 @@ +from odoo import api, models + + +class Website(models.Model): + + _inherit = "website" + + @api.model + def website_domain(self, website_id=False): + if self._context.get('multi_website_domain'): + return ['|'] + [('website_ids', 'ilike', item) for item in (False, website_id or self.id)] + return super().website_domain(website_id=website_id) + + def sale_product_domain(self): + """ We add a context in order to change the way that website_domain behavies """ + return super(Website, self.with_context(multi_website_domain=True)).website_domain() From 3fc296282aebcf73166878afba066e1de192a7f8 Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Sun, 31 Oct 2021 06:23:51 -0300 Subject: [PATCH 06/10] [FIX] website_sale_product_multi_website --- website_sale_product_multi_website/hooks.py | 1 - website_sale_product_multi_website/models/website.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/website_sale_product_multi_website/hooks.py b/website_sale_product_multi_website/hooks.py index 681f893154..f667849a08 100644 --- a/website_sale_product_multi_website/hooks.py +++ b/website_sale_product_multi_website/hooks.py @@ -5,4 +5,3 @@ def post_init_hook(cr, registry): env = api.Environment(cr, SUPERUSER_ID, {}) for rec in env["product.template"].with_context(active_test=False).search([]): rec.website_ids += rec.website_id - rec.website_id = False diff --git a/website_sale_product_multi_website/models/website.py b/website_sale_product_multi_website/models/website.py index 2ad40f4b84..8ad55cbcd5 100644 --- a/website_sale_product_multi_website/models/website.py +++ b/website_sale_product_multi_website/models/website.py @@ -8,9 +8,9 @@ class Website(models.Model): @api.model def website_domain(self, website_id=False): if self._context.get('multi_website_domain'): - return ['|'] + [('website_ids', 'ilike', item) for item in (False, website_id or self.id)] + return ['|', ('website_ids', '=', False), ('website_ids', '=', website_id or self.id)] return super().website_domain(website_id=website_id) def sale_product_domain(self): """ We add a context in order to change the way that website_domain behavies """ - return super(Website, self.with_context(multi_website_domain=True)).website_domain() + return super(Website, self.with_context(multi_website_domain=True)).sale_product_domain() From 6832b0c2a9c9838bd3c115155fda64ee5ed9e402 Mon Sep 17 00:00:00 2001 From: lav-adhoc Date: Thu, 23 Nov 2023 15:20:31 -0300 Subject: [PATCH 07/10] [MIG] website_sale_product_multi_website: Migration to 16.0 --- website_sale_product_multi_website/README.rst | 98 +++ .../__manifest__.py | 3 +- .../models/product_template.py | 26 +- .../models/website.py | 14 +- .../tests/tours/website_sale_complete_flow.js | 791 +++++++++--------- .../website_sale_product_multi_website.py | 27 +- 6 files changed, 553 insertions(+), 406 deletions(-) diff --git a/website_sale_product_multi_website/README.rst b/website_sale_product_multi_website/README.rst index e69de29bb2..a47782636a 100644 --- a/website_sale_product_multi_website/README.rst +++ b/website_sale_product_multi_website/README.rst @@ -0,0 +1,98 @@ +================================== +Website sale product multi website +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0f39a547d2e1ceb92b5aa6b8751b67a1e263224a712a6519667c94d370f1a8f1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/16.0/website_sale_product_multi_website + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-16-0/e-commerce-16-0-website_sale_product_multi_website + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +By default, Odoo allows to set just one (or all) website for products to be sold on eCommerces, by setting the field product_template.website_ids (a many2one field). This module allows to set more than one value (website) in this field (convert it in a many2many field). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== +#. Just install it. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Agile Business Group + +Contributors +~~~~~~~~~~~~ + +* Simone Rubino + + +* `Tecnativa `_: + + * João Marques + * Pilar Vargas + * Stefan Ungureanu + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-stefan-tecnativa| image:: https://github.com/stefan-tecnativa.png?size=40px + :target: https://github.com/stefan-tecnativa + :alt: stefan-tecnativa +.. |maintainer-pilarvargas-tecnativa| image:: https://github.com/pilarvargas-tecnativa.png?size=40px + :target: https://github.com/pilarvargas-tecnativa + :alt: pilarvargas-tecnativa + +Current `maintainers `__: + +|maintainer-stefan-tecnativa| |maintainer-pilarvargas-tecnativa| + +This module is part of the `OCA/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_product_multi_website/__manifest__.py b/website_sale_product_multi_website/__manifest__.py index bf33b03e5a..b812eead6c 100644 --- a/website_sale_product_multi_website/__manifest__.py +++ b/website_sale_product_multi_website/__manifest__.py @@ -1,7 +1,7 @@ { "name": "Multi-website product", "summary": "Show products in many web-sites", - "version": "13.0.1.0.0", + "version": "16.0.1.0.0", "category": "Website", "author": "Odoo Community Association (OCA), Adhoc S.A.", "license": "AGPL-3", @@ -11,4 +11,5 @@ "data": ["views/product_template_views.xml"], "demo": [], "post_init_hook": "post_init_hook", + "website": "https://github.com/OCA/e-commerce", } diff --git a/website_sale_product_multi_website/models/product_template.py b/website_sale_product_multi_website/models/product_template.py index 1b794382c0..5d8ff52dcd 100644 --- a/website_sale_product_multi_website/models/product_template.py +++ b/website_sale_product_multi_website/models/product_template.py @@ -1,6 +1,7 @@ +import logging + from odoo import api, fields, models from odoo.http import request -import logging _logger = logging.getLogger(__name__) @@ -11,25 +12,32 @@ class ProductTemplate(models.Model): website_ids = fields.Many2many("website", string="Websites") def can_access_from_current_website(self, website_id=False): - """ We overwrite this method completely in order to use the website_ids logic instead of website_id """ + """We overwrite this method completely in order to + use the website_ids logic instead of website_id""" website_id = website_id or request.website.id for rec in self.filtered(lambda x: x.website_ids): if website_id not in rec.website_ids.ids: return False return True - @api.depends('is_published', 'website_ids') - @api.depends_context('website_id') + @api.depends("is_published", "website_ids") + @api.depends_context("website_id") def _compute_website_published(self): - """ We overwrite this method completely in order to use the website_ids logic instead of website_id """ - current_website_id = self._context.get('website_id') + """We overwrite this method completely in order to + use the website_ids logic instead of website_id""" + current_website_id = self._context.get("website_id") for record in self: if current_website_id: record.website_published = record.is_published and ( - not record.website_ids or current_website_id in record.website_ids.ids) + not record.website_ids + or current_website_id in record.website_ids.ids + ) else: record.website_published = record.is_published def _search_website_published(self, operator, value): - """ We overwrite this method completely in order to use the website_ids logic instead of website_id """ - return super(ProductTemplate, self.with_context(multi_website_domain=True))._search_website_published(operator, value) + """We overwrite this method completely in order to + use the website_ids logic instead of website_id""" + return super( + ProductTemplate, self.with_context(multi_website_domain=True) + )._search_website_published(operator, value) diff --git a/website_sale_product_multi_website/models/website.py b/website_sale_product_multi_website/models/website.py index 8ad55cbcd5..642c69cd1f 100644 --- a/website_sale_product_multi_website/models/website.py +++ b/website_sale_product_multi_website/models/website.py @@ -7,10 +7,16 @@ class Website(models.Model): @api.model def website_domain(self, website_id=False): - if self._context.get('multi_website_domain'): - return ['|', ('website_ids', '=', False), ('website_ids', '=', website_id or self.id)] + if self._context.get("multi_website_domain"): + return [ + "|", + ("website_ids", "=", False), + ("website_ids", "=", website_id or self.id), + ] return super().website_domain(website_id=website_id) def sale_product_domain(self): - """ We add a context in order to change the way that website_domain behavies """ - return super(Website, self.with_context(multi_website_domain=True)).sale_product_domain() + """We add a context in order to change the way that website_domain behavies""" + return super( + Website, self.with_context(multi_website_domain=True) + ).sale_product_domain() diff --git a/website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js b/website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js index 0aa9a2d250..1c86794a21 100644 --- a/website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js +++ b/website_sale_product_multi_website/static/tests/tours/website_sale_complete_flow.js @@ -1,386 +1,419 @@ -odoo.define('website_sale_tour.tour', function (require) { - 'use strict'; +odoo.define("website_sale_tour.tour", function (require) { + "use strict"; var tour = require("web_tour.tour"); var rpc = require("web.rpc"); - tour.register('website_sale_tour', { - test: true, - url: '/shop?search=Storage Box', - }, [ - // Testing b2c with Tax-Excluded Prices - { - content: "Open product page", - trigger: '.oe_product_cart a:contains("Storage Box")', - }, - { - content: "Add one more storage box", - trigger: '.js_add_cart_json:eq(1)', - }, - { - content: "Check b2b Tax-Excluded Prices", - trigger: '.product_price .oe_price .oe_currency_value:containsExact(79.00)', - run: function () {}, // it's a check - }, - { - content: "Click on add to cart", - trigger: '#add_to_cart', - }, - { - content: "Check for 2 products in cart and proceed to checkout", - extra_trigger: '#cart_products tr:contains("Storage Box") input.js_quantity:propValue(2)', - trigger: 'a[href*="/shop/checkout"]', - }, - { - content: "Check Price b2b subtotal", - trigger: 'tr#order_total_untaxed .oe_currency_value:containsExact(158.00)', - run: function () {}, // it's a check - }, - { - content: "Check Price b2b Sale Tax(15%)", - trigger: 'tr#order_total_taxes .oe_currency_value:containsExact(23.70)', - run: function () {}, // it's a check - }, - { - content: "Check Price b2b Total amount", - trigger: 'tr#order_total .oe_currency_value:containsExact(181.70)', - run: function () {}, // it's a check - }, - { - content: "Fulfill billing address form", - trigger: 'select[name="country_id"]', - run: function () { - $('input[name="name"]').val('abc'); - $('input[name="phone"]').val('99999999'); - $('input[name="email"]').val('abc@odoo.com'); - $('input[name="street"]').val('SO1 Billing Street, 33'); - $('input[name="city"]').val('SO1BillingCity'); - $('#country_id option:eq(1)').attr('selected', true); + tour.register( + "website_sale_tour", + { + test: true, + url: "/shop?search=Storage Box", }, - }, - { - content: "Shipping address is not same as billing address", - trigger: '#shipping_use_same', - }, - { - content: "Click on next button", - trigger: '.oe_cart .btn:contains("Next")', - }, - { - content: "Fulfill shipping address form", - trigger: 'select[name="country_id"]', - extra_trigger: 'h2:contains("Shipping Address")', - run: function () { - $('input[name="name"]').val('def'); - $('input[name="phone"]').val('8888888888'); - $('input[name="street"]').val('17, SO1 Shipping Road'); - $('input[name="city"]').val('SO1ShippingCity'); - $('#country_id option:eq(1)').attr('selected', true); - }, - }, - { - content: "Click on next button", - trigger: '.oe_cart .btn:contains("Next")', - }, - { - content: "Check selected billing address is same as typed in previous step", - trigger: '#shipping_and_billing:contains(SO1 Billing Street, 33):contains(SO1BillingCity):contains(Afghanistan)', - run: function () {}, // it's a check - }, - { - content: "Check selected shipping address is same as typed in previous step", - trigger: '#shipping_and_billing:contains(17, SO1 Shipping Road):contains(SO1ShippingCity):contains(Afghanistan)', - run: function () {}, // it's a check - }, - { - content: "Click for edit address", - trigger: 'a:contains("Edit") i', - }, - { - content: "Click for edit billing address", - trigger: '.js_edit_address:first', - }, - { - content: "Change billing address form", - trigger: 'select[name="country_id"]', - extra_trigger: 'h2:contains("Your Address")', - run: function () { - $('input[name="name"]').val('abcd'); - $('input[name="phone"]').val('11111111'); - $('input[name="street"]').val('SO1 Billing Street Edited, 33'); - $('input[name="city"]').val('SO1BillingCityEdited'); - }, - }, - { - content: "Click on next button", - trigger: '.oe_cart .btn:contains("Next")', - }, - { - content: "Confirm Address", - trigger: 'a.btn:contains("Confirm")', - }, - { - content: "Check selected billing address is same as typed in previous step", - trigger: '#shipping_and_billing:contains(SO1 Billing Street Edited, 33):contains(SO1BillingCityEdited):contains(Afghanistan)', - run: function () {}, // it's a check - }, - { - content: "Select `Wire Transfer` payment method", - trigger: '#payment_method label:contains("Wire Transfer")', - }, - { - content: "Pay Now", - extra_trigger: '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', - trigger: 'button[id="o_payment_form_pay"]:visible:not(:disabled)', - }, - { - content: "Sign up", - trigger: '.oe_cart a:contains("Sign Up")', - }, - { - content: "Submit login", - trigger: '.oe_signup_form', - run: function () { - $('.oe_signup_form input[name="password"]').val("1admin@admin"); - $('.oe_signup_form input[name="confirm_password"]').val("1admin@admin"); - $('.oe_signup_form').submit(); - }, - }, - { - content: "See Quotations", - trigger: '.o_portal_docs a:contains("Quotations")', - }, - // Sign in as admin change config auth_signup -> b2b, sale_show_tax -> total and Logout - { - content: "Open Dropdown for logout", - trigger: '#top_menu li.dropdown:visible a:contains("abcd")', - }, - { - content: "Logout", - trigger: '#o_logout:contains("Logout")', - }, - { - content: "Sign in as admin", - trigger: '#top_menu li a b:contains("Sign in")', - }, - { - content: "Submit login", - trigger: '.oe_login_form', - run: function () { - $('.oe_login_form input[name="login"]').val("admin"); - $('.oe_login_form input[name="password"]').val("admin"); - $('.oe_login_form input[name="redirect"]').val("/"); - $('.oe_login_form').submit(); - }, - }, - { - content: "Configuration Settings for 'Tax Included' and sign up 'On Invitation'", - extra_trigger: '.o_connected_user #wrapwrap', - trigger: '#wrapwrap', - run: function () { - var def1 = rpc.query({ - model: 'res.config.settings', - method: 'create', - args: [{ - 'auth_signup_uninvited': 'b2b', - 'show_line_subtotals_tax_selection': 'tax_included', - 'group_show_line_subtotals_tax_excluded': false, - 'group_show_line_subtotals_tax_included': true, - }], - }); - var def2 = def1.then(function (resId) { - return rpc.query({ - model: 'res.config.settings', - method: 'execute', - args: [[resId]], - }); - }); - def2.then(function () { - window.location.href = '/web/session/logout?redirect=/shop?search=Storage Box'; - }); - }, - }, - // Testing b2b with Tax-Included Prices - { - content: "Open product page", - trigger: '.oe_product_cart a:contains("Storage Box")', - }, - { - content: "Add one more Storage Box", - trigger: '.js_add_cart_json:eq(1)', - }, - { - content: "Check b2c Tax-Included Prices", - trigger: '.product_price .oe_price .oe_currency_value:containsExact(90.85)', - run: function () {}, // it's a check - }, - { - content: "Click on add to cart", - trigger: '#add_to_cart', - }, - { - content: "Check for 2 products in cart and proceed to checkout", - extra_trigger: '#cart_products tr:contains("Storage Box") input.js_quantity:propValue(2)', - trigger: 'a[href*="/shop/checkout"]', - }, - { - content: "Check Price b2c total", - trigger: 'tr#order_total_untaxed .oe_currency_value:containsExact(158.00)', - run: function () {}, // it's a check - }, - { - content: "Check Price b2c Sale Tax(15%)", - trigger: 'tr#order_total_taxes .oe_currency_value:containsExact(23.70)', - run: function () {}, // it's a check - }, - { - content: "Check Price b2c Total amount", - trigger: 'tr#order_total .oe_currency_value:containsExact(181.70)', - run: function () {}, // it's a check - }, - { - content: "Click on Login Button", - trigger: '.oe_cart a.btn:contains("Log In")', - }, - { - content: "Submit login", - trigger: '.oe_login_form', - run: function () { - $('.oe_login_form input[name="login"]').val("abc@odoo.com"); - $('.oe_login_form input[name="password"]').val("1admin@admin"); - $('.oe_login_form').submit(); - }, - }, - { - content: "Add new shipping address", - trigger: '.one_kanban form[action^="/shop/address"] .btn', - }, - { - content: "Fulfill shipping address form", - trigger: 'select[name="country_id"]', - run: function () { - $('input[name="name"]').val('ghi'); - $('input[name="phone"]').val('7777777777'); - $('input[name="street"]').val('SO2New Shipping Street, 5'); - $('input[name="city"]').val('SO2NewShipping'); - $('#country_id option:eq(1)').attr('selected', true); - }, - }, - { - content: "Click on next button", - trigger: '.oe_cart .btn:contains("Next")', - }, - { - content: "Select `Wire Transfer` payment method", - trigger: '#payment_method label:contains("Wire Transfer")', - }, - { - content: "Pay Now", - extra_trigger: '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', - trigger: 'button[id="o_payment_form_pay"]:visible:not(:disabled)', - }, - { - content: "Open Dropdown for See quotation", - extra_trigger: '.oe_cart .oe_website_sale_tx_status', - trigger: '#top_menu li.dropdown:visible a:contains("abc")', - }, - { - content: "My account", - extra_trigger: '#top_menu li.dropdown .js_usermenu.show', - trigger: '#top_menu .dropdown-menu a[href="/my/home"]:visible', - }, - { - content: "See Quotations", - trigger: '.o_portal_docs a:contains("Quotations") .badge:containsExact(2)', - }, + [ + // Testing b2c with Tax-Excluded Prices + { + content: "Open product page", + trigger: '.oe_product_cart a:contains("Storage Box")', + }, + { + content: "Add one more storage box", + trigger: ".js_add_cart_json:eq(1)", + }, + { + content: "Check b2b Tax-Excluded Prices", + trigger: + ".product_price .oe_price .oe_currency_value:containsExact(79.00)", + run: function () {}, // It's a check + }, + { + content: "Click on add to cart", + trigger: "#add_to_cart", + }, + { + content: "Check for 2 products in cart and proceed to checkout", + extra_trigger: + '#cart_products tr:contains("Storage Box") input.js_quantity:propValue(2)', + trigger: 'a[href*="/shop/checkout"]', + }, + { + content: "Check Price b2b subtotal", + trigger: + "tr#order_total_untaxed .oe_currency_value:containsExact(158.00)", + run: function () {}, // It's a check + }, + { + content: "Check Price b2b Sale Tax(15%)", + trigger: "tr#order_total_taxes .oe_currency_value:containsExact(23.70)", + run: function () {}, // It's a check + }, + { + content: "Check Price b2b Total amount", + trigger: "tr#order_total .oe_currency_value:containsExact(181.70)", + run: function () {}, // It's a check + }, + { + content: "Fulfill billing address form", + trigger: 'select[name="country_id"]', + run: function () { + $('input[name="name"]').val("abc"); + $('input[name="phone"]').val("99999999"); + $('input[name="email"]').val("abc@odoo.com"); + $('input[name="street"]').val("SO1 Billing Street, 33"); + $('input[name="city"]').val("SO1BillingCity"); + $("#country_id option:eq(1)").attr("selected", true); + }, + }, + { + content: "Shipping address is not same as billing address", + trigger: "#shipping_use_same", + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Fulfill shipping address form", + trigger: 'select[name="country_id"]', + extra_trigger: 'h2:contains("Shipping Address")', + run: function () { + $('input[name="name"]').val("def"); + $('input[name="phone"]').val("8888888888"); + $('input[name="street"]').val("17, SO1 Shipping Road"); + $('input[name="city"]').val("SO1ShippingCity"); + $("#country_id option:eq(1)").attr("selected", true); + }, + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: + "Check selected billing address is same as typed in previous step", + trigger: + "#shipping_and_billing:contains(SO1 Billing Street, 33):contains(SO1BillingCity):contains(Afghanistan)", + run: function () {}, // It's a check + }, + { + content: + "Check selected shipping address is same as typed in previous step", + trigger: + "#shipping_and_billing:contains(17, SO1 Shipping Road):contains(SO1ShippingCity):contains(Afghanistan)", + run: function () {}, // It's a check + }, + { + content: "Click for edit address", + trigger: 'a:contains("Edit") i', + }, + { + content: "Click for edit billing address", + trigger: ".js_edit_address:first", + }, + { + content: "Change billing address form", + trigger: 'select[name="country_id"]', + extra_trigger: 'h2:contains("Your Address")', + run: function () { + $('input[name="name"]').val("abcd"); + $('input[name="phone"]').val("11111111"); + $('input[name="street"]').val("SO1 Billing Street Edited, 33"); + $('input[name="city"]').val("SO1BillingCityEdited"); + }, + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Confirm Address", + trigger: 'a.btn:contains("Confirm")', + }, + { + content: + "Check selected billing address is same as typed in previous step", + trigger: + "#shipping_and_billing:contains(SO1 Billing Street Edited, 33):contains(SO1BillingCityEdited):contains(Afghanistan)", + run: function () {}, // It's a check + }, + { + content: "Select `Wire Transfer` payment method", + trigger: '#payment_method label:contains("Wire Transfer")', + }, + { + content: "Pay Now", + extra_trigger: + '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', + trigger: 'button[id="o_payment_form_pay"]:visible:not(:disabled)', + }, + { + content: "Sign up", + trigger: '.oe_cart a:contains("Sign Up")', + }, + { + content: "Submit login", + trigger: ".oe_signup_form", + run: function () { + $('.oe_signup_form input[name="password"]').val("1admin@admin"); + $('.oe_signup_form input[name="confirm_password"]').val( + "1admin@admin" + ); + $(".oe_signup_form").submit(); + }, + }, + { + content: "See Quotations", + trigger: '.o_portal_docs a:contains("Quotations")', + }, + // Sign in as admin change config auth_signup -> b2b, sale_show_tax -> total and Logout + { + content: "Open Dropdown for logout", + trigger: '#top_menu li.dropdown:visible a:contains("abcd")', + }, + { + content: "Logout", + trigger: '#o_logout:contains("Logout")', + }, + { + content: "Sign in as admin", + trigger: '#top_menu li a b:contains("Sign in")', + }, + { + content: "Submit login", + trigger: ".oe_login_form", + run: function () { + $('.oe_login_form input[name="login"]').val("admin"); + $('.oe_login_form input[name="password"]').val("admin"); + $('.oe_login_form input[name="redirect"]').val("/"); + $(".oe_login_form").submit(); + }, + }, + { + content: + "Configuration Settings for 'Tax Included' and sign up 'On Invitation'", + extra_trigger: ".o_connected_user #wrapwrap", + trigger: "#wrapwrap", + run: function () { + var def1 = rpc.query({ + model: "res.config.settings", + method: "create", + args: [ + { + auth_signup_uninvited: "b2b", + show_line_subtotals_tax_selection: "tax_included", + group_show_line_subtotals_tax_excluded: false, + group_show_line_subtotals_tax_included: true, + }, + ], + }); + var def2 = def1.then(function (resId) { + return rpc.query({ + model: "res.config.settings", + method: "execute", + args: [[resId]], + }); + }); + def2.then(function () { + window.location.href = + "/web/session/logout?redirect=/shop?search=Storage Box"; + }); + }, + }, + // Testing b2b with Tax-Included Prices + { + content: "Open product page", + trigger: '.oe_product_cart a:contains("Storage Box")', + }, + { + content: "Add one more Storage Box", + trigger: ".js_add_cart_json:eq(1)", + }, + { + content: "Check b2c Tax-Included Prices", + trigger: + ".product_price .oe_price .oe_currency_value:containsExact(90.85)", + run: function () {}, // It's a check + }, + { + content: "Click on add to cart", + trigger: "#add_to_cart", + }, + { + content: "Check for 2 products in cart and proceed to checkout", + extra_trigger: + '#cart_products tr:contains("Storage Box") input.js_quantity:propValue(2)', + trigger: 'a[href*="/shop/checkout"]', + }, + { + content: "Check Price b2c total", + trigger: + "tr#order_total_untaxed .oe_currency_value:containsExact(158.00)", + run: function () {}, // It's a check + }, + { + content: "Check Price b2c Sale Tax(15%)", + trigger: "tr#order_total_taxes .oe_currency_value:containsExact(23.70)", + run: function () {}, // It's a check + }, + { + content: "Check Price b2c Total amount", + trigger: "tr#order_total .oe_currency_value:containsExact(181.70)", + run: function () {}, // It's a check + }, + { + content: "Click on Login Button", + trigger: '.oe_cart a.btn:contains("Log In")', + }, + { + content: "Submit login", + trigger: ".oe_login_form", + run: function () { + $('.oe_login_form input[name="login"]').val("abc@odoo.com"); + $('.oe_login_form input[name="password"]').val("1admin@admin"); + $(".oe_login_form").submit(); + }, + }, + { + content: "Add new shipping address", + trigger: '.one_kanban form[action^="/shop/address"] .btn', + }, + { + content: "Fulfill shipping address form", + trigger: 'select[name="country_id"]', + run: function () { + $('input[name="name"]').val("ghi"); + $('input[name="phone"]').val("7777777777"); + $('input[name="street"]').val("SO2New Shipping Street, 5"); + $('input[name="city"]').val("SO2NewShipping"); + $("#country_id option:eq(1)").attr("selected", true); + }, + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: "Select `Wire Transfer` payment method", + trigger: '#payment_method label:contains("Wire Transfer")', + }, + { + content: "Pay Now", + extra_trigger: + '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', + trigger: 'button[id="o_payment_form_pay"]:visible:not(:disabled)', + }, + { + content: "Open Dropdown for See quotation", + extra_trigger: ".oe_cart .oe_website_sale_tx_status", + trigger: '#top_menu li.dropdown:visible a:contains("abc")', + }, + { + content: "My account", + extra_trigger: "#top_menu li.dropdown .js_usermenu.show", + trigger: '#top_menu .dropdown-menu a[href="/my/home"]:visible', + }, + { + content: "See Quotations", + trigger: + '.o_portal_docs a:contains("Quotations") .badge:containsExact(2)', + }, - // enable extra step on website checkout and check extra step on checkout process - { - content: "Open Dropdown for logout", - trigger: '#top_menu li.dropdown:visible a:contains("abc")', - }, - { - content: "Logout", - trigger: '#o_logout:contains("Logout")', - }, - { - content: "Sign in as admin", - trigger: '#top_menu li a b:contains("Sign in")', - }, - { - content: "Submit login", - trigger: '.oe_login_form', - run: function () { - $('.oe_login_form input[name="login"]').val("admin"); - $('.oe_login_form input[name="password"]').val("admin"); - $('.oe_login_form input[name="redirect"]').val("/shop/cart"); - $('.oe_login_form').submit(); - }, - }, - { - content: "Open Customize menu", - trigger: '.o_menu_sections a:contains("Customize")', - }, - { - content: "Enable Extra step", - trigger: 'a.dropdown-item label:contains("Extra Step Option")', - }, - { - content: "Open Dropdown for logout", - extra_trigger: '.progress-wizard-step:contains("Extra Info")', - trigger: '#top_menu li.dropdown:visible a:contains("Mitchell Admin")', - }, - { - content: "Logout", - trigger: '#o_logout:contains("Logout")', - }, - { - content: "Sign in as abc", - trigger: '#top_menu li a b:contains("Sign in")', - }, - { - content: "Submit login", - trigger: '.oe_login_form', - run: function () { - $('.oe_login_form input[name="login"]').val("abc@odoo.com"); - $('.oe_login_form input[name="password"]').val("1admin@admin"); - $('.oe_login_form input[name="redirect"]').val("/shop?search=Storage Box"); - $('.oe_login_form').submit(); - }, - }, - { - content: "Open product page", - trigger: '.oe_product_cart a:contains("Storage Box")', - }, - { - content: "Click on add to cart", - trigger: '#add_to_cart', - }, - { - content: "Proceed to checkout", - trigger: 'a[href*="/shop/checkout"]', - }, - { - content: "Click on next button", - trigger: '.oe_cart .btn:contains("Next")', - }, - { - content: "Check selected billing address is same as typed in previous step", - trigger: '#shipping_and_billing:contains(SO1 Billing Street Edited, 33):contains(SO1BillingCityEdited):contains(Afghanistan)', - run: function () {}, // it's a check - }, - { - content: "Check selected shipping address is same as typed in previous step", - trigger: '#shipping_and_billing:contains(SO2New Shipping Street, 5):contains(SO2NewShipping):contains(Afghanistan)', - run: function () {}, // it's a check - }, - { - content: "Select `Wire Transfer` payment method", - trigger: '#payment_method label:contains("Wire Transfer")', - }, - { - content: "Pay Now", - extra_trigger: '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', - trigger: 'button[id="o_payment_form_pay"]:visible', - }]); + // Enable extra step on website checkout and check extra step on checkout process + { + content: "Open Dropdown for logout", + trigger: '#top_menu li.dropdown:visible a:contains("abc")', + }, + { + content: "Logout", + trigger: '#o_logout:contains("Logout")', + }, + { + content: "Sign in as admin", + trigger: '#top_menu li a b:contains("Sign in")', + }, + { + content: "Submit login", + trigger: ".oe_login_form", + run: function () { + $('.oe_login_form input[name="login"]').val("admin"); + $('.oe_login_form input[name="password"]').val("admin"); + $('.oe_login_form input[name="redirect"]').val("/shop/cart"); + $(".oe_login_form").submit(); + }, + }, + { + content: "Open Customize menu", + trigger: '.o_menu_sections a:contains("Customize")', + }, + { + content: "Enable Extra step", + trigger: 'a.dropdown-item label:contains("Extra Step Option")', + }, + { + content: "Open Dropdown for logout", + extra_trigger: '.progress-wizard-step:contains("Extra Info")', + trigger: '#top_menu li.dropdown:visible a:contains("Mitchell Admin")', + }, + { + content: "Logout", + trigger: '#o_logout:contains("Logout")', + }, + { + content: "Sign in as abc", + trigger: '#top_menu li a b:contains("Sign in")', + }, + { + content: "Submit login", + trigger: ".oe_login_form", + run: function () { + $('.oe_login_form input[name="login"]').val("abc@odoo.com"); + $('.oe_login_form input[name="password"]').val("1admin@admin"); + $('.oe_login_form input[name="redirect"]').val( + "/shop?search=Storage Box" + ); + $(".oe_login_form").submit(); + }, + }, + { + content: "Open product page", + trigger: '.oe_product_cart a:contains("Storage Box")', + }, + { + content: "Click on add to cart", + trigger: "#add_to_cart", + }, + { + content: "Proceed to checkout", + trigger: 'a[href*="/shop/checkout"]', + }, + { + content: "Click on next button", + trigger: '.oe_cart .btn:contains("Next")', + }, + { + content: + "Check selected billing address is same as typed in previous step", + trigger: + "#shipping_and_billing:contains(SO1 Billing Street Edited, 33):contains(SO1BillingCityEdited):contains(Afghanistan)", + run: function () {}, // It's a check + }, + { + content: + "Check selected shipping address is same as typed in previous step", + trigger: + "#shipping_and_billing:contains(SO2New Shipping Street, 5):contains(SO2NewShipping):contains(Afghanistan)", + run: function () {}, // It's a check + }, + { + content: "Select `Wire Transfer` payment method", + trigger: '#payment_method label:contains("Wire Transfer")', + }, + { + content: "Pay Now", + extra_trigger: + '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))', + trigger: 'button[id="o_payment_form_pay"]:visible', + }, + ] + ); }); diff --git a/website_sale_product_multi_website/tests/website_sale_product_multi_website.py b/website_sale_product_multi_website/tests/website_sale_product_multi_website.py index da977396ff..255039db66 100644 --- a/website_sale_product_multi_website/tests/website_sale_product_multi_website.py +++ b/website_sale_product_multi_website/tests/website_sale_product_multi_website.py @@ -1,22 +1,23 @@ -from odoo.tests +import odoo.tests -class TestWebsiteSaleProductMultiWebsite(tests.HttpCase): - +class TestWebsiteSaleProductMultiWebsite(odoo.tests.HttpCase): def setUp(self): super().setUp() # Create multiple websites - self.website0 = self.env['website'].create({'name': 'web0'}) - self.website1 = self.env['website'].create({'name': 'web1'}) - self.website2 = self.env['website'].create({'name': 'web2'}) + self.website0 = self.env["website"].create({"name": "web0"}) + self.website1 = self.env["website"].create({"name": "web1"}) + self.website2 = self.env["website"].create({"name": "web2"}) # create a product template - self.product_template = self.env['product.template'].create({ - 'name': 'Test Product', - 'is_published': True, - 'list_price': 750, - }) + self.product_template = self.env["product.template"].create( + { + "name": "Test Product", + "is_published": True, + "list_price": 750, + } + ) def test_01(self): - """ Prueba que si el producto no tiene websites dicho producto esta disponible en todos los websites - """ + """Prueba que si el producto no tiene websites + dicho producto esta disponible en todos los websites""" From 1b86ce1b1a02160f0e1789968ad5bfbd223fc18a Mon Sep 17 00:00:00 2001 From: Manuela Cepeda Date: Tue, 28 May 2024 10:37:47 -0300 Subject: [PATCH 08/10] [IMP] website_sale_product_multi_website: pre-commit execution --- website_sale_product_multi_website/models/website.py | 1 - website_sale_product_multi_website/pyproject.toml | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 website_sale_product_multi_website/pyproject.toml diff --git a/website_sale_product_multi_website/models/website.py b/website_sale_product_multi_website/models/website.py index 642c69cd1f..7eb587bb8e 100644 --- a/website_sale_product_multi_website/models/website.py +++ b/website_sale_product_multi_website/models/website.py @@ -2,7 +2,6 @@ class Website(models.Model): - _inherit = "website" @api.model diff --git a/website_sale_product_multi_website/pyproject.toml b/website_sale_product_multi_website/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_product_multi_website/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" From 9104d710c72fcb9f38f4bb4f351d42ae91cbe73d Mon Sep 17 00:00:00 2001 From: Manuela Cepeda Date: Tue, 28 May 2024 10:37:49 -0300 Subject: [PATCH 09/10] [MIG] website_sale_product_multi_website: Migration to 17.0 --- website_sale_product_multi_website/__manifest__.py | 2 +- website_sale_product_multi_website/hooks.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/website_sale_product_multi_website/__manifest__.py b/website_sale_product_multi_website/__manifest__.py index b812eead6c..2d8c6ee60e 100644 --- a/website_sale_product_multi_website/__manifest__.py +++ b/website_sale_product_multi_website/__manifest__.py @@ -1,7 +1,7 @@ { "name": "Multi-website product", "summary": "Show products in many web-sites", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "category": "Website", "author": "Odoo Community Association (OCA), Adhoc S.A.", "license": "AGPL-3", diff --git a/website_sale_product_multi_website/hooks.py b/website_sale_product_multi_website/hooks.py index f667849a08..1e54f97c06 100644 --- a/website_sale_product_multi_website/hooks.py +++ b/website_sale_product_multi_website/hooks.py @@ -1,7 +1,3 @@ -from odoo import SUPERUSER_ID, api - - -def post_init_hook(cr, registry): - env = api.Environment(cr, SUPERUSER_ID, {}) +def post_init_hook(env): for rec in env["product.template"].with_context(active_test=False).search([]): rec.website_ids += rec.website_id From e17c86fd7d69d9ab957ada2463964d62ab9d3125 Mon Sep 17 00:00:00 2001 From: Manuela Cepeda Date: Wed, 30 Oct 2024 15:56:33 -0300 Subject: [PATCH 10/10] [MIG] website_sale_product_multi_website: Migration to 18.0 --- website_sale_product_multi_website/__manifest__.py | 2 +- .../views/product_template_views.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website_sale_product_multi_website/__manifest__.py b/website_sale_product_multi_website/__manifest__.py index 2d8c6ee60e..07eaffda4f 100644 --- a/website_sale_product_multi_website/__manifest__.py +++ b/website_sale_product_multi_website/__manifest__.py @@ -1,7 +1,7 @@ { "name": "Multi-website product", "summary": "Show products in many web-sites", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "category": "Website", "author": "Odoo Community Association (OCA), Adhoc S.A.", "license": "AGPL-3", diff --git a/website_sale_product_multi_website/views/product_template_views.xml b/website_sale_product_multi_website/views/product_template_views.xml index 3291907205..2756ff0ef5 100644 --- a/website_sale_product_multi_website/views/product_template_views.xml +++ b/website_sale_product_multi_website/views/product_template_views.xml @@ -18,7 +18,7 @@ - product.product.website.inherit.view.tree + product.product.website.inherit.view.list product.product @@ -36,7 +36,7 @@ - product_template_view_tree.view.tree + product_template_view_tree.view.list product.template