Skip to content

Commit

Permalink
[NEW] Add organization application form page from website
Browse files Browse the repository at this point in the history
An organization can apply to membership without creation of portal account
  • Loading branch information
Stéphan Sainléger committed May 13, 2022
1 parent 05e04c8 commit 803b663
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 34 deletions.
34 changes: 19 additions & 15 deletions lcc_members/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,25 @@ def _compute_odoo_user_id(self):

@api.model
def create(self, vals):
"""When creating, if partner_profile is not defined by a previous process, the defaut value is Main"""
modified_self = self._basecontact_check_context("create")
if not vals.get("partner_profile") and not vals.get("contact_id"):
profile = self.env.ref("lcc_members.partner_profile_main").read()[0]
vals["partner_profile"] = profile["id"]
res = super(res_partner, modified_self).create(vals)
if (
res.partner_profile.ref == "partner_profile_main"
and not res.public_profile_id
):
res.create_public_profile()
if res.partner_profile.ref == "partner_profile_public":
# Public profile can't be customer or supplier. Only main or position profiles can
res.customer = False
res.supplier = False
if vals["type"] == "contact":
"""When creating, if partner_profile is not defined by a previous process, the defaut value is Main"""
modified_self = self._basecontact_check_context("create")
if not vals.get("partner_profile") and not vals.get("contact_id"):
profile = self.env.ref("lcc_members.partner_profile_main").read()[0]
vals["partner_profile"] = profile["id"]
res = super(res_partner, modified_self).create(vals)
if (
res.partner_profile.ref == "partner_profile_main"
and not res.public_profile_id
):
res.create_public_profile()
if res.partner_profile.ref == "partner_profile_public":
# Public profile can't be customer or supplier. Only main or position profiles can
res.customer = False
res.supplier = False
else:
modified_self = self._basecontact_check_context("create")
res = super(res_partner, modified_self).create(vals)
return res

@api.constrains("email")
Expand Down
1 change: 1 addition & 0 deletions lcc_members_portal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"views/portal_my_home.xml",
"views/portal_private_registration.xml",
"views/portal_organization_registration.xml",
"views/website_organization_registration.xml",
"views/portal_organization_renewal.xml",
"views/portal_affiliation_request.xml",
"views/product_template_view.xml",
Expand Down
1 change: 1 addition & 0 deletions lcc_members_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from . import portal_private_registration
from . import portal_organization_registration
from . import website_organization_registration
from . import portal_organization_renewal
from . import portal_affiliation_request
from . import custom_website_sale
Expand Down
129 changes: 129 additions & 0 deletions lcc_members_portal/controllers/website_organization_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Copyright 2020 Lokavaluto ()
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import http
from odoo.http import request


class WebsiteOrganizationRegistration(http.Controller):
_ORGANIZATION_REGISTRATION_FIELDS = [
"company_name",
"commercial_company_name",
"website_description",
"street",
"street2",
"city",
"zipcode",
"country_id",
# "team_id", # TODO: issue occuring when this field is added. INVESTIGATION NEEDED
"phone",
"company_email",
"website_url",
"industry_id",
"detailed_activity",
"reasons_choosing_mlc",
"opening_time",
"discount",
"contact_name",
"function",
"email_pro",
"phone_pro",
"message_from_candidate",
]

# Variable to update to add other fields in child classes
_EXTRA_FIELDS = []

def get_organization_membership_product(self):
product_obj = request.env["product.template"]
product = product_obj.sudo().get_organization_membership_product(
request.website.company_id.id
)
return product

@http.route(
["/web/organization_registration"],
type="http",
auth="public",
website=True,
)
def portal_organization_registration(self, access_token=None, redirect=None, **kw):

product = self.get_organization_membership_product()
titles = request.env["res.partner.title"].sudo().search([])
countries = request.env["res.country"].sudo().search([])
teams = (
request.env["crm.team"]
.sudo()
.search(
[
("local_group", "=", True),
("company_id", "=", request.website.company_id.id),
]
)
)
industries = request.env["res.partner.industry"].sudo().search([])
error = dict()
error_message = []

values = {
"product": product,
"total_membership": product.list_price,
"dynamic_price": product.dynamic_price,
"titles": titles,
"countries": countries,
"industries": industries,
"teams": teams,
"error": error,
"error_message": error_message,
}

return request.render(
"lcc_members_portal.website_organization_registration", values
)

@http.route(
["/web/send_request"],
type="http",
auth="public",
website=True,
)
def send_registration_request(self, **kwargs):
# Create a new lead
values = {}
for field in self._ORGANIZATION_REGISTRATION_FIELDS:
if kwargs.get(field):
values[field] = kwargs.pop(field)
for field in self._EXTRA_FIELDS:
if kwargs.get(field):
values[field] = kwargs.pop(field)
values["name"] = "[NEW APPLICATION] " + values["company_name"]
values["partner_id"] = 2 # OdooBot-s ID
values["company_id"] = request.website.company_id.id
values["type"] = "opportunity"
values["lead_type"] = "membership_web_application"
values.update({"zip": values.pop("zipcode", "")})
values.update({"website": values.pop("website_url", "")})
values["accept_coupons"] = kwargs.get("accept_coupons", "off") == "on"
values["accept_digital_currency"] = (
kwargs.get("accept_digital_currency", "off") == "on"
)
values["from_website"] = True
values["itinerant"] = kwargs.get("itinerant", "off") == "on"
values["want_newsletter_subscription"] = (
kwargs.get("want_newsletter_subscription", "off") == "on"
)
values["accept_policy"] = kwargs.get("accept_policy", "off") == "on"
if float(kwargs.get("total_membership", False)):
values["total_membership"] = float(kwargs.get("total_membership"))
else:
values[
"total_membership"
] = self.get_organization_membership_product().list_price

lead = request.env["crm.lead"].sudo().create(values)
lead.team_id = kwargs.pop(
"team_id"
) # TODO: see remark above concerning team_id
return request.render(
"lcc_members_portal.website_organization_registration_saved", {}
)
58 changes: 39 additions & 19 deletions lcc_members_portal/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Lead(models.Model):

_POSITION_PROFILE_FIELDS = [
"function",
"street",
"street2",
"city",
"zip",
"country_id",
"email_pro",
"phone_pro",
]
Expand Down Expand Up @@ -62,6 +67,7 @@ class Lead(models.Model):
accept_digital_currency = fields.Boolean(string=_("Accept digital currency"))
accept_coupons = fields.Boolean(string=_("Accept coupons"))
itinerant = fields.Boolean(string=_("Itinerant"))
email_pro = fields.Char(string=_("Email Pro"))
function = fields.Char(string=_("Job Position"))
phone_pro = fields.Char(string=_("Phone Pro"))
want_newsletter_subscription = fields.Boolean(
Expand All @@ -82,9 +88,9 @@ class Lead(models.Model):
domain=[("membership", "=", True), ("type", "=", "service")],
)
invoice_url = fields.Char(string=_("Invoice link"))
from_website = fields.Boolean(default=False)
application_accepted = fields.Boolean(default=False)
application_refused = fields.Boolean(default=False)

affiliated_company = fields.Many2one(
"res.partner",
string="Affiliated organization",
Expand Down Expand Up @@ -133,24 +139,38 @@ def action_validate_organization_application(self):
main_partner = self.env["res.partner"].create(values)
# Organization's public profile is automaticcaly created

# Organization's contact's position partner creation
values = {}
for field_name in self._POSITION_PROFILE_FIELDS:
values[field_name] = self._get_field_value(field_name)
values["name"] = self.contact_name
values["is_company"] = False
values["contact_id"] = self.partner_id.id
values["parent_id"] = main_partner.id
values["partner_profile"] = (
self.env["partner.profile"]
.search([("ref", "=", "partner_profile_position")], limit=1)
.id
)
values["type"] = "contact"
values["edit_structure_main_profile"] = True
values["edit_structure_public_profile"] = True
values.update({"phone": values.pop("phone_pro", "")})
self.env["res.partner"].create(values)
if self.from_website:
# Organization created from website, we create only a billing contact
values = {}
for field_name in self._POSITION_PROFILE_FIELDS:
values[field_name] = self._get_field_value(field_name)
values["name"] = self.contact_name
values.update({"phone": values.pop("phone_pro", "")})
values.update({"email": values.pop("email_pro", "")})
values["is_company"] = False
values["type"] = "invoice"
values["parent_id"] = main_partner.id
self.env["res.partner"].create(values)
else:
# Organization's contact's position partner creation
values = {}
for field_name in self._POSITION_PROFILE_FIELDS:
values[field_name] = self._get_field_value(field_name)
values["name"] = self.contact_name
values["is_company"] = False
values["contact_id"] = self.partner_id.id
values["parent_id"] = main_partner.id
values["partner_profile"] = (
self.env["partner.profile"]
.search([("ref", "=", "partner_profile_position")], limit=1)
.id
)
values["type"] = "contact"
values["edit_structure_main_profile"] = True
values["edit_structure_public_profile"] = True
values.update({"phone": values.pop("phone_pro", "")})
values.update({"email": values.pop("email_pro", "")})
self.env["res.partner"].create(values)

# Create sale order and invoice to finalize the registration process
values = {}
Expand Down
2 changes: 2 additions & 0 deletions lcc_members_portal/views/crm_lead_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@
<field name="invoice_url" attrs="{'invisible': [('application_accepted', '=', False)]}" widget='url' />
</group>
<group name="organization_contact" string="Organization's Contact">
<field name="from_website" invisible="1" />
<field name="contact_name" />
<field name="function" />
<field name="email_pro" widget="email" />
<field name="phone_pro" widget="phone" />
<field name="mobile" invisible="1" />
</group>
Expand Down
Loading

0 comments on commit 803b663

Please sign in to comment.