Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Extension of portal user information not working well

Naroči se

Get notified when there's activity on this post

This question has been flagged
userportalextensionecommerce
2 Odgovori
814 Prikazi
Avatar
Chijioke Kanu

I heve been trying to extend the portal user information by adding some fields. At the odoo backend it works propery but at the frontend user dashboard when you want to save the data, it raises an error that says "Unknown field 'company_cac_number,company_registration_type,industry,business_description,company_website,company_email,company_phone,company_logo'"

Here are my codes:
1. __manifest__ 

{
'name': 'Partner Company Extension',
'version': '1.1',
'category': 'Contacts',
'summary': 'Adds company details fields to res.partner',
'depends': ['base', 'portal'],
'data': [
'views/partner_view.xml',
'views/portal_templates.xml',
],
'installable': True,
'application': False,
}

2. /controllers/portal .py

from odoo.addons.portal.controllers.portal import CustomerPortal
from odoo import http
from odoo.http import request


class CustomerPortalExtended(CustomerPortal):

def details_form_fields(self):
"""Extend portal details form fields with custom fields"""
fields = super().details_form_fields()
fields.extend([
'company_cac_number',
'company_registration_type',
'industry',
'business_description',
'company_website',
'company_email',
'company_phone',
'company_logo',
])
return fields

@http.route(['/my/account'], type='http', auth="user", website=True, methods=['POST'])
def details_form_submit(self, **kwargs):
# allow default processing first
response = super(CustomerPortalExtended, self).details_form_submit(**kwargs)
# then explicitly write our custom fields
partner = request.env.user.partner_id.sudo()
values = {k: v for k, v in kwargs.items() if k in self.details_form_fields()}
if values:
partner.write(values)
return response

3. models/partner .py

from odoo import models, fields

class ResPartner(models.Model):
_inherit = 'res.partner'

company_cac_number = fields.Char(string="Company CAC Number")
company_registration_type = fields.Selection([
('business_name', 'Business Name'),
('limited_liability', 'Limited Liability'),
('limited_by_guarantee', 'Limited by Guarantee'),
('incorporated_trustee', 'Incorporated Trustee')
], string="Company Type")
industry = fields.Char(string="Industry")
business_description = fields.Text(string="Business Description")
company_website = fields.Char(string="Company Website")
company_email = fields.Char(string="Company Email")
company_phone = fields.Char(string="Company Phone")
company_logo = fields.Binary(string="Company Logo")

4. /views/partner_view .xml

 

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_partner_form_inherit_company" model="ir.ui.view">
<field name="name">res.partner.form.company.extension</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<sheet position="inside">
<group string="Company Information">
<field name="company_cac_number"/>
<field name="company_registration_type"/>
<field name="industry"/>
<field name="business_description"/>
<field name="company_website"/>
<field name="company_email"/>
<field name="company_phone"/>
</group>
</sheet>
</field>
</record>
</odoo>

5. /views/portal_template .xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="portal_my_details_inherit" inherit_id="portal.portal_my_details">
<xpath expr="//div[@class='row o_portal_details']//div[@class='row']" position="inside">
<div class="form-group">
<label for="company_cac_number">CAC Number</label>
<input type="text" name="company_cac_number"
t-att-value="partner.company_cac_number or ''"
class="form-control"/>
</div>

<div class="form-group">
<label for="company_registration_type">Registration Type</label>
<select name="company_registration_type" class="form-select">
<option value="ltd" t-att-selected="partner.company_registration_type == 'ltd'">Limited</option>
<option value="enterprise" t-att-selected="partner.company_registration_type == 'enterprise'">Enterprise</option>
<option value="ngo" t-att-selected="partner.company_registration_type == 'ngo'">NGO</option>
</select>
</div>

<div class="form-group">
<label for="industry">Industry</label>
<input type="text" name="industry" t-att-value="partner.industry or ''" class="form-control"/>
</div>

<div class="form-group">
<label for="business_description">Business Description</label>
<textarea name="business_description" class="form-control"><t t-esc="partner.business_description"/></textarea>
</div>

<div class="form-group">
<label for="company_website">Website</label>
<input type="url" name="company_website" t-att-value="partner.company_website or ''" class="form-control"/>
</div>

<div class="form-group">
<label for="company_email">Email</label>
<input type="email" name="company_email" t-att-value="partner.company_email or ''" class="form-control"/>
</div>

<div class="form-group">
<label for="company_phone">Phone</label>
<input type="text" name="company_phone" t-att-value="partner.company_phone or ''" class="form-control"/>
</div>

<div class="form-group">
<label for="company_logo">Company Logo</label>
<input type="file" name="company_logo" class="form-control"/>
</div>
</xpath>
</template>
</odoo>


Thanks in anticipation!




0
Avatar
Opusti
Dawid Gacek

I have deleted my post @Chijoke, as I misunderstood your question. I though it was related to Partner Form.

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,



Try the following,


1-Align the selection values


Update your portal template options to match your model’s selection keys:


<select name="company_registration_type" class="form-select">

    <option value="business_name" t-att-selected="partner.company_registration_type == 'business_name'">Business Name</option>

    <option value="limited_liability" t-att-selected="partner.company_registration_type == 'limited_liability'">Limited Liability</option>

    <option value="limited_by_guarantee" t-att-selected="partner.company_registration_type == 'limited_by_guarantee'">Limited by Guarantee</option>

    <option value="incorporated_trustee" t-att-selected="partner.company_registration_type == 'incorporated_trustee'">Incorporated Trustee</option>

</select>



2- Handle file upload for company_logo



In your controller:


import base64

@http.route(['/my/account'], type='http', auth="user", website=True, methods=['POST'])

def details_form_submit(self, **kwargs):

    response = super(CustomerPortalExtended, self).details_form_submit(**kwargs)

    partner = request.env.user.partner_id.sudo()

    values = {k: v for k, v in kwargs.items() if k in self.details_form_fields()}


    # Handle file upload

    file = request.httprequest.files.get('company_logo')

    if file:

        values['company_logo'] = base64.b64encode(file.read())


    if values:

        partner.write(values)

    return response


Hope it helps

0
Avatar
Opusti
Avatar
Christoph Farnleitner
Best Answer

I don't know where you've got the idea of

def details_form_fields(self):
    super().details_form_fields()
    ...

from. Certainly not a thing since Odoo 16 - haven't checked earlier versions though. You're actually looking for _get_optional_fields() - or _get_mandatory_fields() if necessary, i.e.:

class CustomerPortalExtended(CustomerPortal):

    def _get_optional_fields(self):
        """Extend portal details form fields with custom fields"""
        fields = super()._get_optional_fields()
        fields.append(
            'company_cac_number',
            'company_registration_type',
            'industry',
            'business_description',
            'company_website',
            'company_email',
            'company_phone',
            'company_logo',
        )
        return fields

...

Also, the Registration Type in your portal template does not match the actual options of that selection field.

0
Avatar
Opusti
Chijioke Kanu
Avtor

@Christoph Farnleitner, please can you guide me exacly on how to achieve this?

Christoph Farnleitner

Just add that method to your controller file.

Chijioke Kanu
Avtor

I did, upgraded the module then tried it again but still the same.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
IndexError: list index out of range from Customer Portal from invoice
portal ecommerce
Avatar
Avatar
Avatar
Avatar
Avatar
4
feb. 17
8662
Query Releted to Portal user openerp 7
user portal
Avatar
0
mar. 15
4265
Portal User Spam Solved
user portal spam
Avatar
Avatar
Avatar
Avatar
Avatar
6
maj 25
2628
How to make portal users see navigation bar in website Solved
portal ecommerce navigation
Avatar
Avatar
1
jul. 19
6888
Odoo 9 Public and Portal 500: Internal Server Error on Product Pages.
public portal ecommerce
Avatar
0
nov. 16
3778
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now