diff --git a/lcc_members/models/res_partner.py b/lcc_members/models/res_partner.py index 3113acfa..b0c1e89e 100644 --- a/lcc_members/models/res_partner.py +++ b/lcc_members/models/res_partner.py @@ -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") diff --git a/lcc_members_portal/__manifest__.py b/lcc_members_portal/__manifest__.py index cb9b6ed2..244835ba 100644 --- a/lcc_members_portal/__manifest__.py +++ b/lcc_members_portal/__manifest__.py @@ -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", diff --git a/lcc_members_portal/controllers/__init__.py b/lcc_members_portal/controllers/__init__.py index 764bf6d2..3fb26996 100644 --- a/lcc_members_portal/controllers/__init__.py +++ b/lcc_members_portal/controllers/__init__.py @@ -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 diff --git a/lcc_members_portal/controllers/website_organization_registration.py b/lcc_members_portal/controllers/website_organization_registration.py new file mode 100644 index 00000000..b6ae9c57 --- /dev/null +++ b/lcc_members_portal/controllers/website_organization_registration.py @@ -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", {} + ) diff --git a/lcc_members_portal/models/crm_lead.py b/lcc_members_portal/models/crm_lead.py index 5b0c5f81..ad7a2ed8 100644 --- a/lcc_members_portal/models/crm_lead.py +++ b/lcc_members_portal/models/crm_lead.py @@ -32,6 +32,11 @@ class Lead(models.Model): _POSITION_PROFILE_FIELDS = [ "function", + "street", + "street2", + "city", + "zip", + "country_id", "email_pro", "phone_pro", ] @@ -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( @@ -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", @@ -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 = {} diff --git a/lcc_members_portal/views/crm_lead_view.xml b/lcc_members_portal/views/crm_lead_view.xml index 7eb8b9fb..d35b798e 100644 --- a/lcc_members_portal/views/crm_lead_view.xml +++ b/lcc_members_portal/views/crm_lead_view.xml @@ -93,8 +93,10 @@ + + diff --git a/lcc_members_portal/views/website_organization_registration.xml b/lcc_members_portal/views/website_organization_registration.xml new file mode 100644 index 00000000..74d734ea --- /dev/null +++ b/lcc_members_portal/views/website_organization_registration.xml @@ -0,0 +1,258 @@ + + + + + + + + + + + + Organization registration Form + + + + What is your organization? + + + + Legal Name + * + + + + Commercial Name + * + + + + + + Description + + + + + + Contact information + + + + Street + * + + + + Street 2 + + + + Zip / Postal Code + * + + + + City + * + + + + Country + * + + Country... + + + + + + + + + + + + Phone + * + + + + Email + * + + + + Website + + + + + + Organization information + + + + Main activity + + Activity... + + + + + + + + + + + Detailed activity + + + + Subscription reason + * + + + + + + Opening time + + + + Discount + + + + + + Accept coupons + + + Accept digital currency + + + + + Itinerant + + + + + Billing information + + + + Name + * + + + + Job position + * + + + + Email pro + * + + + + Professional phone + * + + + + + + Membership information + + + + Local group + * + + Local group... + + + + + + + + + Registration fee amount + * + + + + + + A message to the team? + + + + + + + + + + Subscribe to our newsletters + + + Accept Policy + * + + + + + + Submit + + + + + + + + + + + + + + + + + + Registration sent + + + + Thanks for applying! + + Your membership application has been saved and will be assess by our team. + + You will be contacted soon. + + + + + + + Back to Home page + + + + + + + + + \ No newline at end of file
+ Thanks for applying! + + Your membership application has been saved and will be assess by our team. + + You will be contacted soon. + +