Skip to Content
Odoo Menu
  • Sign in
  • 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
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to validate required fields on CRM stage change?

Subscribe

Get notified when there's activity on this post

This question has been flagged
validatechangestagecrm_leadodooV12
6 Replies
11251 Views
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
Discard
Ermin Trevisan

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

Muhammad Anees
Author

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
Author Best Answer

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
Discard
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Best Answer

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
Discard
Muhammad Anees
Author

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
Author

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
Author

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!

Sign up
Related Posts Replies Views Activity
How can I send an email notification when a Document changes stage?
email notification change stage
Avatar
Avatar
1
Aug 22
4239
edited invoice doesn't show the changes when printed
invoice validate print change edit
Avatar
Avatar
1
Mar 15
6052
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 Solved
odooV12
Avatar
Avatar
Avatar
Avatar
Avatar
4
May 24
8285
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