Reputation: 1725
how hidden odoo crm plugin fields with this code:
models.py
# -*- coding: utf-8 -*-
from odoo import models, api, fields
import logging
_logger = logging.getLogger(__name__)
class PrivacyConsent(models.Model):
_name = "spekno.crm.privacy.consent"
_description = "Privacy Consent"
name = fields.Char("Nome Consenso", required=True)
type = fields.Selection([('marketing', 'Marketing'), ('3rdparty', 'Terze Parti')], string="Tipo consenso")
ext_ref = fields.Char("ID esterno")
internal = fields.Boolean(string="Interno", default=False)
active = fields.Boolean(string="Attivo", default=True)
class CrmLead(models.Model):
_inherit = 'crm.lead'
my_text_field = fields.Text(string='Anagrafica suggerita')
ext_portal = fields.Selection([('toshiko', 'Toshiko'), ('tcar', 'Tcar'), ('jeep', 'Jeep')],
string="Portale di provenienza")
ext_ref = fields.Char("Id Lead Portale", help="Codice lead Portale")
privacy = fields.Many2many('spekno.crm.privacy.consent', 'crm_lead_privacy_consent_rel', string="Privacy",
tracking=True)
ext_create_date = fields.Datetime(string="Data creazione su portale esterno")
ext_customer_request = fields.Html(string="Richiesta Cliente Portale")
suggested_partner_id = fields.Many2many('res.partner', 'crm_lead_suggested_partner_rel', string="Partner Suggeriti",
tracking=True)
@api.model
def create(self, vals):
lead = super(CrmLead, self).create(vals)
success = lead.validate_contact_info()
if not success:
_logger.error('Failed to validate contact info for Lead ID: %s', lead.id)
return lead
def validate_contact_info(self):
if not self:
return False
updated = False
for lead in self:
_logger.info('Starting validation for Lead ID: %s', lead.id)
if lead.suggested_partner_id:
suggested_partner_ids = lead.suggested_partner_id.ids
partners = self.env['res.partner'].browse(suggested_partner_ids)
for partner in partners:
if lead.phone and partner.phone != lead.phone:
_logger.info('Updating phone for Partner ID: %s', partner.id)
partner.phone = lead.phone
updated = True
if lead.email and partner.email != lead.email:
_logger.info('Updating email for Partner ID: %s', partner.id)
partner.email = lead.email
updated = True
if updated:
_logger.info('Contact info updated for Lead ID: %s', self.id)
return True
else:
_logger.info('No updates necessary for Lead ID: %s', self.id)
return True
view.xml:
<odoo>
<data>
<record id="action_validate_contact_info" model="ir.actions.server">
<field name="name">Validate Contact Info</field>
<field name="model_id" ref="crm.model_crm_lead" />
<field name="state">code</field>
<field name="code">model.validate_contact_info()</field>
</record>
<record id="crm_lead_view_form_lead_fields" model="ir.ui.view">
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_lead_view_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='tag_ids']" position="after">
<button name="%(action_validate_contact_info)d" string="Valida Anagrafica" type="action" class="oe_highlight" />
<group name="my_section" style="{'invisible': [('some_field', '=', False)]}">
<field name="ext_portal" />
<field name="ext_ref" />
<field name="privacy" />
<field name="ext_create_date" />
<field name="ext_customer_request" />
<field name="my_text_field" placeholder="Inserisci il tuo testo qui" />
</group>
</xpath>
</field>
</record>
</data>
</odoo>
Upvotes: 0
Views: 40