Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

How to validate required fields on CRM stage change?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
validatechangestagecrm_leadodooV12
6 Besvarelser
11316 Visninger
Avatar
Muhammad Anees

Hii,

I have made some fields as required through xpath in xml on CRM Pipeline form. I dont want to set required in python.
When I change stage this validation dont apply. I tried on stage_id onchange function but crm.lead fields are not available.
I tried overriding write method, in this case when creating new lead in Kanban quick create dont work.

How to validate required fields on CRM stage change?

Thanks,

 


2
Avatar
Kassér
Ermin Trevisan

Please refrain from obviously boosting your own karma with your "fake" Q&A games, especially when your answers are questionable.

Muhammad Anees
Forfatter

twanda AG, Ermin Trevisan Switzerland, very disgraceful remarks. I am helping me and the community and for you its answer and question game?

Avatar
Muhammad Anees
Forfatter Bedste svar

I done it by overriding the write() method. Here is the code.

class AbcCrmLead(models.Model):     
    _inherit = 'crm.lead' 
@api.multi
def write(self, values):
result = super(AbcCrmLead, self).write(values)
for record in self:
if not record.partner_id:
raise UserError(_('Customer is required'))
if not record.mobile:
raise UserError(_('Mobile is required'))
if record.stage_id.need_quotation and record.sale_number <= 0:
raise UserError(_('Opportunity with No Quotation can\'t be moved to %s stage. Please add quotation(s) to move to next stage.' % record.stage_id.name))
return result

The issue was when creating new opportunity from Kanban Quick Create Form. So I inherited the Kanban Quick Create Form and added required fields. 

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="abc_quick_create_opportunity_form" model="ir.ui.view">
<field name="name">abc.crm.lead.form.quick_create</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.quick_create_opportunity_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="required">1</attribute>
</xpath>
<xpath expr="//field[@name='partner_id']" position="after">
<field name="mobile" required="1"/>
<field name="date_deadline" required="1"/>
<field name="user_id" required="1"/>
<field name="team_id" required="1"/>
</xpath>
<xpath expr="//field[@name='planned_revenue']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='priority']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>
</odoo>

Now all validation is working by drag and drop from kanabn view, changing stage from form view.

4
Avatar
Kassér
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Bedste svar

You can use attrs to make the fields required based on condition.

Create a related name field of the stage_id and use it in the attrs.

stage_name = fields.Char(related='stage_id.name', string='Stage') # Create this field in the py file

<field name="stage_name" invisible="1"/>
<field name="field1" attrs="{'required': [('stage_name', '=', 'Draft')]}"/>


5
Avatar
Kassér
Muhammad Anees
Forfatter

Thanks Arya,

<xpath expr="//field[@name='partner_id']" position="attributes">

<attribute name="attrs">{'required': [('stage_id.name', '=', 'New')]}</attribute>

</xpath>

Getting following error...

Error: Unknown field stage_id.name in domain

Sudhir Arya (ERP Harbor Consulting Services)

You need to create a related field of the stage name:

stage_name = fields.Char(related="stage_id.name", string='Stage Name')

<field name="stage_name" invisible="1"/>

<field name="field1" attrs="{'required': [('stage_name', '=', 'Draft')]}"/>

Muhammad Anees
Forfatter

I added the stage_name related field updated required domain as you said. But in following two cases validation dont apply.

1. Drag and Drop from kanban to next stage validation dont apply.

2. On the opportunity form, if I click on the next stage, opportunity stage changes to next and validation dont apply

3. On the opportunity form, if I edit and click on next stage, validation applied, on save also applied

I think solution id somewhere in the python code by overriding write method?

What you say Arya.

Sudhir Arya (ERP Harbor Consulting Services)

Ok in that case, you would need to override the write method, check the stage and the fields values in the vals dict, and raise exception as per your condition.

Muhammad Anees
Forfatter

Thanks Arya, your support was helpful.

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

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
How can I send an email notification when a Document changes stage?
email notification change stage
Avatar
Avatar
1
aug. 22
4270
edited invoice doesn't show the changes when printed
invoice validate print change edit
Avatar
Avatar
1
mar. 15
6091
uniqe phone number odoo v15
crm_lead
Avatar
Avatar
Avatar
2
aug. 24
245
uniqe phone number odoo v15
crm_lead
Avatar
0
aug. 24
12
Data Exceeded error while importing data in Odoo v12 Løst
odooV12
Avatar
Avatar
Avatar
Avatar
Avatar
4
maj 24
8314
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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