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 set a filter for customers who have at least 1 sales order with order date in this year or last 365 days with a value greater than £0

Subscribe

Get notified when there's activity on this post

This question has been flagged
marketingautomation
14 Replies
9234 Views
Avatar
Lampfix

I would like to set a scenario in Marketing Automation and would like to know what fields to use for the following criteria:


- Target: Partner

-Filter - has a sales order confirmed this year (2020) or in the last 365 days, with untaxed total with a value greater than £0

0
Avatar
Discard
Lampfix
Author

Thanks for this Chris. Can you help me also find sales orders confirmed in the last 365 days? This kind of filter would then allow a rolling year in automation.

Lampfix
Author

Thank you Chris,

So you are saying I need to create a new field and a new extension view with that code?


Chris TRINGHAM

Yes, that's the idea. I have added more details (see below).

Avatar
Paresh Wagh
Best Answer

You will need to add a custom related field (sale_order_ids.date_order) to the res.partner model. This field will then be available in the filter and you will be able to select a date range.

EDIT:

Added screenshot as requested.

Custom Field definition:



What the Filter will look like on the Contacts screen:



What the results will look like (sample using demo data):


2
Avatar
Discard
Lampfix
Author

Great answer!

Chris TRINGHAM

Hi Paresh,

It is a good solution, but to help anyone who wants to use it I think this is going to select both quotations and confirmed sales orders in the date range. It should be easy to add selection of confirmed sales orders only to the user-defined filter.

Paresh Wagh

Nice catch Chris. I didn't see the "confirmed sales order" part of the requirement. You're right, this will select both quotations and sales orders.

Since a "related field" was used for this, the domain field is not available in the configuration screen of the field definition. Also tried adding a second filter field for the order state but using both criteria to filter the partners does not work as expected and seems to use an OR instead of an AND condition. Looks like a custom filter will need to be developed for this requirement.

Paresh Wagh

Looked into this a little more. It seems like a customization is required to handle the "confirmed orders only" part of the requirement.

Chris TRINGHAM

Yes, I think it can be done by adding a filter to the search view..

Chris TRINGHAM

Here's how to setup a custom filter for this: https://odootricks.tips/odoo-date-filters/#select

Peat Biby

hi! This is absolutely wonderful, thanks!! How would I be able to sort by this related field? That's the only thing I can't figure out. Thanks again! Peat

Paresh Wagh

Hi Peat: If you make the related field a stored field you should be able to sort on it.

TEOS

Hi @Patresh,
thank you for the solution. Right know i'm working on function to filter and deactivate automatically customers with invoice date more than 365days. Can you help me please. Thank you.

Paresh Wagh

Hi Imad: You can define a server action to do this. What is the specific help you are looking for?

Avatar
Chris TRINGHAM
Best Answer

Building on what Paresh has suggested, you can use the field he described and create an Extension View like this:

<?xml version="1.0"?>
<xpath expr="//filter[@name='inactive']" position="before">
      <filter string="Orders this year" name="orders"
        domain="[('x_sales_order_dates','&lt;=', time.strftime('%%Y-12-31')),
                 ('x_sales_order_dates','&gt;=',time.strftime('%%Y-01-01')),
                 ('sale_order_ids.state', 'not in', ('draft', 'sent', 'cancel'))]"/>
    <separator/>
</xpath>

This will display a filter like this:

To select orders in the last 12 months, you can have another filter with a different domain:

 <filter string="Orders last 12 months" name="orders_12m" 
domain="[('x_sales_order_dates','&gt;=',(context_today() + relativedelta(months=-12, weekday=0)).strftime('%Y-%m-%d')),
('sale_order_ids.state', 'not in', ('draft', 'sent', 'cancel'))]"/>

======

If you want to filter this in Marketing Automation you can

1. Create a new boolean field x_recent_sales_orders

2. Create an automated action


Enable Developer Mode and navigate to Settings / Technical / (Automation) / Automated Actions:


for rec in records:
  rec['x_recent_sales_orders'] = False
  if rec.x_sales_order_dates:
    if rec.x_sales_order_dates > (datetime.datetime.today() - datetime.timedelta(days=5)):
      rec['x_recent_sales_orders'] = True
What's missing here is the automatic update to reset this flag.

To do it properly, I think you'd need a developer to setup a Scheduled Action to run this code daily (or weekly).  

As a workaround, it is also possible to create a Contextual Action and then you could manually run this (by selecting all orders).

After creating this field and adding the Automated Action you can use it as a filter in Marketing Automation.
1
Avatar
Discard
Lampfix
Author

Thank you Chris, I really appreciate your help on this.

Could you update the code to exclude 'zero' value sales orders, and also could you show me a screen shot of the Scheduled Action to set up for this?

Avatar
Lampfix
Author Best Answer

Thank you Chris that works incredibly well in the Customers view.

Could you give some guidance as to when setting and finding this filter in an Automation?  Whilst I can find the filter in Customers, I cannot find it here:




I would like to edit this post once it is done to make it clear for all users - thanks for your help.

0
Avatar
Discard
Chris TRINGHAM

Odoo has a "simplified" version of the filter in various places and that only allows specific dates to be entered. There is a workaround for this as described here: https://odootricks.tips/domain-in-odoo/#problem but it seems that doesn't work for Marketing Automation.

Another solution is to create a boolean field that will identify customers who have placed orders recently (e.g. last 12 months) and update this every day using a Scheduled Action (then you can easily add a filter).

I have some general information here: https://odootricks.tips/server-actions and I'll try to add a more specific example later.

Chris TRINGHAM

I updated my answer.

Lampfix
Author

From what you say I realised I don't need to use Marketing Automation to sort my database contacts and their opportunities. I can use scheduled actions instead.

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
Double Opt-in - Marketing automation
marketing automation
Avatar
0
May 25
1636
Marketing Automation
marketing automation
Avatar
1
Feb 25
8189
Connect Marketing Automation with Social media marketing
marketing automation socialmarketing
Avatar
Avatar
1
Jan 23
3881
How to avoid non-literal domain
automation
Avatar
Avatar
Avatar
2
Aug 25
1561
Will Odoo 19 support Instagram Stories/Reels?
marketing
Avatar
Avatar
1
Aug 25
1788
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