Skip to content

Commit

Permalink
⚡ portal extension
Browse files Browse the repository at this point in the history
  • Loading branch information
KolushovAlexandr committed Dec 13, 2019
1 parent a8d82fa commit c3461f5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
1 change: 1 addition & 0 deletions website_multi_company_separate_orders/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"depends": [
"website_multi_company_sale",
"website_sale",
"portal"
],
"external_dependencies": {"python": [], "bin": []},
"data": [
Expand Down
29 changes: 29 additions & 0 deletions website_multi_company_separate_orders/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from odoo import http
from odoo.http import request
from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo.addons.portal.controllers.portal import CustomerPortal

_logger = logging.getLogger(__name__)

Expand All @@ -29,12 +30,14 @@ def _check_and_update_child_order(self, sale_order, product_id, add_qty, set_qty
return False
sale_order_child = sale_order.order_child_ids.filtered(lambda so: so.company_id.id == product_company_id)
if not sale_order_child:
pricelist_id = sale_order.pricelist_id.id
sale_order_child = sale_order.sudo().create({
'order_parent_id': sale_order.id,
'company_id': product_company_id,
'partner_id': sale_order.partner_id.id,
'partner_invoice_id': sale_order.partner_invoice_id.id,
'partner_shipping_id': sale_order.partner_shipping_id.id,
'pricelist_id': pricelist_id
})
sale_order.write({
'order_child_ids': [(4, sale_order_child.id)]
Expand Down Expand Up @@ -95,3 +98,29 @@ def duplicate_orders_for_daughter_companies(self, company_id=False):
prod = line.product_id
result.append(self._check_and_update_child_order(order, prod, False, line.product_uom_qty, 'Force'))
return all(result)


# class MultiCompanyPortal(CustomerPortal):
# def _prepare_portal_layout_values(self):
# res = super(MultiCompanyPortal, self)._prepare_portal_layout_values()
# user = request.env.user
# partner = user.partner_id
# company_id = request.env.user.company_id
#
# SaleOrder = request.env['sale.order'].sudo()
# quotation_count = SaleOrder.search_count([
# ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]),
# ('state', 'in', ['sent', 'cancel']),
# ('company_id', 'in', [company_id.id] + company_id.child_ids.ids)
# ])
# order_count = SaleOrder.search_count([
# ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]),
# ('state', 'in', ['sale', 'done']),
# ('company_id', 'in', [company_id.id] + company_id.child_ids.ids)
# ])
# res.update({
# 'quotation_count': quotation_count,
# 'order_count': order_count,
# })
# import wdb; wdb.set_trace()
# return res
32 changes: 32 additions & 0 deletions website_multi_company_separate_orders/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from odoo import models, api, tools, fields
from odoo.addons.website_sale.models.website import Website as WebsiteOriginal
from odoo.http import request
from odoo.exceptions import AccessDenied, AccessError, UserError, ValidationError
from odoo import api, fields, models, tools, SUPERUSER_ID, _

from odoo import models, api, tools, fields


class Website(models.Model):
Expand All @@ -13,3 +17,31 @@ class Website(models.Model):
help='Duplicate orders for Daughter companies')
order_duplicating_companies = fields.Many2many('res.company', string='Order Duplicating Companies',
help='Daughter companies where order is being automatically duplicated to')

@api.model
def website_domain(self, website_id=False):
res = super(Website, self).website_domain(website_id)
website_id = website_id or self.get_current_website()
if not website_id or self.env.context and self.env.context.get('website_id', False):
return res

if type(website_id) == int:
website_id = self.env['website'].browse(website_id)
website_company_parent_id = website_id.sudo().company_id.sudo().parent_id
if website_company_parent_id:
child_websites = self.env['website'].search([('company_id', '=', website_company_parent_id.id)]).ids
upd_tuple = res[0][2] + tuple(child_websites)
upd_res_0 = list(res[0])
upd_res_0[2] = upd_tuple
res[0] = tuple(upd_res_0)
return res


# class Users(models.Model):
# _inherit = 'res.users'
#
# @classmethod
# def _login(cls, db, login, password):
# res = super(Users, cls)._login(db, login, password)
# import wdb; wdb.set_trace()
# return res
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
<field name="domain_force">['|', '|', ('company_id', '=', user.company_id.id), ('company_id', '=', False), ('company_id', 'in', user.company_id.child_ids.ids)]</field>
</record>

<!-- <delete model="ir.rule" id="website_multi_company_sale.website_multi_company_sale_order_all"/>-->
<delete model="ir.rule" id="website_multi_company_sale.website_multi_company_sale_order_all"/>
<record id="website_multi_company_sale_order_all" model="ir.rule">
<field name="name">Users with backend_website_id field specified have access only for sale orders from specied website</field>
<field name="model_id" ref="model_sale_order"/>
<field name="domain_force">['|', ('website_id', 'in', [user.backend_website_id.id]), ('website_id', '=', False)]</field>
<field name="domain_force">[('website_id', 'in', [user.backend_website_id.id, user.website_id.id, False])]</field>
<field name="backend_behaviour">true</field>
</record>
<!--Not sure that it's needed smh works with websites rules only-->
<record id="website_multi_company_sale_order_company" model="ir.rule">
<field name="name">Users with current company_id field specified have access only for sale orders from specified company and child companies</field>
<field name="model_id" ref="model_sale_order"/>
<field name="domain_force">['|', '|', ('company_id', '=', user.company_id.id), ('company_id', '=', False), ('company_id', 'in', user.company_id.child_ids.ids)]</field>
<field name="domain_force">[('company_id', 'in', [user.company_id.id, False] + user.company_id.child_ids.ids)]</field>
</record>

<record id="website_multi_company_sale_product_public_categoey_rule_company" model="ir.rule">
Expand Down

0 comments on commit c3461f5

Please sign in to comment.