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

[v14] How can I create a Tree View that shows ONLY the last 5 records?

Subscribe

Get notified when there's activity on this post

This question has been flagged
domainlimitv14
2 Replies
4262 Views
Avatar
Hugo

Hi,


I want to create a custom tree view (list view) of sale.order that displays ONLY the last 5 sales.


I've tried using 5 but that limits the number of records per page, meaning users can still go to the next pages and see the whole data.


I believe I should be using "domain" to do that, but I don't know how.


Can anyone help?


Thanks in advance!    

0
Avatar
Discard
Avatar
CandidRoot Solutions Private Limited
Best Answer


Hello

You should create new menu with new window action where you can pass context as define in below screenshot to identify action in search_read method.

please find below search_read method for sale.order model, i assume that we need to find last 5 record based on create_date desc order.  you can apply and modify domain as per your needs.


@api.model
def search_read
(self, domain=None, fields=None, offset=0, limit=None, order=None):
if 'display_last_five_records' in self.env.context:
order = 'create_date desc'
res = super().search_read(domain=domain, fields=fields, offset=offset, limit=limit, order=order)
if 'display_last_five_records' in self.env.context:return res[:5]
return res




Thanks & Regards,

​

CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229 - 1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat 380015
    

3
Avatar
Discard
Avatar
Ray Carnes (ray)
Best Answer

A domain is the right approach, the challenge is defining "the last 5 sales".

Is it the last five created, confirmed, by sequence, etc?

You would want a new Menu, connected to Window Action, that uses an existing View.  The Window Action is where the domain would go. 

If you create (and save to Favorites) a Custom Filter (to help you define your definition of the last 5), you can see the domain syntax when you view it in the User Defined Filters Menu. The black "code editor" section is what you can copy (edit) and paste into the Window Action.

https://www.odoo.com/documentation/14.0/applications/productivity/studio/use_cases/filters_status_bar.html

https://www.odoo.com/documentation/14.0/applications/finance/documents.html#advanced-condition-type-domain

https://www.odoo.com/documentation/14.0/developer/reference/addons/actions.html (technical, but useful to know how this works, even if you don't do all of this customization in a module).



0
Avatar
Discard
Hugo
Author

Sorry for not being more especific. I need to show the last 5 created sales, regardless of the state.

To be even more especific, I'm trying to alter the sale.act_res_partner_2_sale_order action to show only the last 5 created sales (instead of every sale to that customer)

My code:
<record id="sale.act_res_partner_2_sale_order" model="ir.actions.act_window">
<field name="name">Quotations and Sales TEST</field>
<field name="res_model">sale.order</field>
<field name="view_mode">kanban,form</field>
<field name="context">{}</field>
<field name="domain">
[
'|',('partner_id.parent_id','=', active_id),('partner_id','=', active_id)
]
</field>
</record>

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
Set domain to allow everything when no value in controlling field Solved
domain v14
Avatar
1
Jun 21
3797
Nginx Rate Limits Preventing Odoo pages to load completely
nginx limit v14
Avatar
0
Mar 23
2641
DOMAIN Solved
domain helpme v14
Avatar
Avatar
1
Feb 21
2919
filter many2many field
filter domain many2many v14
Avatar
Avatar
1
Sep 23
2990
ver 14: how to search parent_id and its all child in model product.category in Many2one field
domain parent child v14
Avatar
Avatar
1
Jul 23
6292
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