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!
I have deleted my post @Chijoke, as I misunderstood your question. I though it was related to Partner Form.