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

[IMP] super_portal: Implement Super Portal User access #642

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions super_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
20 changes: 20 additions & 0 deletions super_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
'name': 'Super Portal User',
'category': 'Portal',
'summary': 'Portal access for multi-branch management',
'depends': ['contacts', 'website_sale'],
'data': [
'security/portal_security.xml',
'views/res_partner_views.xml',
'views/portal_wizard_views.xml',
'views/templates.xml',
],
'assets': {
'web.assets_frontend': [
'super_portal/static/src/js/website_sale.js',
'super_portal/static/src/js/address_search.js'
],
},
'license': 'LGPL-3',
'installable': True,
}
2 changes: 2 additions & 0 deletions super_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import main
from . import portal
115 changes: 115 additions & 0 deletions super_portal/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from odoo import http
from odoo.http import request
from odoo.addons.website_sale.controllers.main import WebsiteSale
from werkzeug.exceptions import Forbidden

class WebsiteSalePortal(WebsiteSale):

#-------------------------------------------------------------------------------#
# Arrange branches in order the display of address options available
#-------------------------------------------------------------------------------#
def checkout_values(self, order, **kw):
order = order or request.website.sale_get_order(force_create=True)
bill_partners = []
ship_partners = []

if not order._is_public_order():
Partner = order.partner_id.with_context(show_address=1).sudo()
commercial_partner = order.partner_id.commercial_partner_id
bill_partners = Partner.search([
'|', ("type", "in", ["invoice", "other"]), ("id", "=", commercial_partner.id),
("id", "child_of", commercial_partner.ids)
], order='id asc, parent_id asc') | order.partner_id
ship_partners = Partner.search([
'|', ("type", "in", ["delivery", "other"]), ("id", "=", commercial_partner.id),
("id", "child_of", commercial_partner.ids)
], order='id asc, parent_id asc') | order.partner_id

if commercial_partner != order.partner_id:
if not self._check_billing_partner_mandatory_fields(commercial_partner):
bill_partners = bill_partners.filtered(lambda p: p.id != commercial_partner.id)
if not self._check_shipping_partner_mandatory_fields(commercial_partner):
ship_partners = ship_partners.filtered(lambda p: p.id != commercial_partner.id)

return {
'order': order,
'website_sale_order': order,
'shippings': ship_partners,
'billings': bill_partners,
'only_services': order and order.only_services or False
}

#----------------------------------------------------------------------------------------------#
# Recompute the prices according to the price list associated with the selected billing address
#----------------------------------------------------------------------------------------------#
@http.route(
'/shop/cart/update_address', type='http', auth='public',
methods=['POST'], website=True, csrf=False
)
def update_cart_address(self, partner_id, mode='billing', **kw):
response = super().update_cart_address(partner_id, mode, **kw)

order_sudo = request.website.sale_get_order()
if not order_sudo:
return response

partner_sudo = request.env['res.partner'].sudo().browse(int(partner_id)).exists()
if not partner_sudo:
raise Forbidden()

new_pricelist = partner_sudo.property_product_pricelist
if new_pricelist and new_pricelist != order_sudo.pricelist_id:
order_sudo.write({'pricelist_id': new_pricelist.id})

order_sudo._recompute_prices()
order_sudo._compute_amounts()
order_sudo.sudo().write({
'amount_total': order_sudo.amount_total,
'amount_tax': order_sudo.amount_tax,
'amount_untaxed': order_sudo.amount_untaxed
})

return response

@http.route(
['/shop/cart/update_total'], type='json', auth='public',
methods=['POST'], website=True, csrf=False
)
def cart_update_total(self):
order_sudo = request.website.sale_get_order()
if not order_sudo:
return {"error": "No active order found"}

line_items = [
{
"unit_price": line.price_unit,
"subtotal": line.price_subtotal,
}
for line in order_sudo.order_line
]

return {
"amount_untaxed": order_sudo.amount_untaxed,
"amount_tax": order_sudo.amount_tax,
"amount_total": order_sudo.amount_total,
"cart_quantity": order_sudo.cart_quantity,
"line_items": line_items,
}

@http.route(['/shop/confirm_order'], type='http', auth="public", website=True, sitemap=False)
def confirm_order(self, **post):
order = request.website.sale_get_order()

redirection = self.checkout_redirection(order) or self.checkout_check_address(order)
if redirection:
return redirection

order.order_line._compute_tax_id()
# Disable to update pricelist based on Website Pricelist

# request.website.sale_get_order(update_pricelist=True)
extra_step = request.website.viewref('website_sale.extra_info')
if extra_step.active:
return request.redirect("/shop/extra_info")

return request.redirect("/shop/payment")
Loading