In a mutli-company account with multiple websites for the differents companies, the 'contact us' form creates leads in the company of the admin instead of the one linked to the website. This PR corrects that behavior by setting a 'company_id' field to the company_id of the user in case that field is missing on models that require it. opw-1907375 closes odoo/odoo#28749
27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.addons.website_form.controllers.main import WebsiteForm
|
|
|
|
class WebsiteForm(WebsiteForm):
|
|
|
|
# Check and insert values from the form on the model <model>
|
|
@http.route('/website_form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True)
|
|
def website_form(self, model_name, **kwargs):
|
|
if model_name == 'crm.lead' and not request.params.get('state_id'):
|
|
geoip_country_code = request.session.get('geoip', {}).get('country_code')
|
|
geoip_state_code = request.session.get('geoip', {}).get('region')
|
|
if geoip_country_code and geoip_state_code:
|
|
State = request.env['res.country.state']
|
|
request.params['state_id'] = State.search([('code', '=', geoip_state_code), ('country_id.code', '=', geoip_country_code)]).id
|
|
|
|
return super(WebsiteForm, self).website_form(model_name, **kwargs)
|
|
|
|
def insert_record(self, request, model, values, custom, meta=None):
|
|
if model.model == 'crm.lead':
|
|
if 'company_id' not in values:
|
|
values['company_id'] = request.website.company_id.id
|
|
return super(WebsiteForm, self).insert_record(request, model, values, custom, meta=meta)
|