Skip to Content
Menu
This question has been flagged
2 Replies
2485 Views

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!    

Avatar
Discard
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
    

Avatar
Discard
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).



Avatar
Discard
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>

Related Posts Replies Views Activity
1
Jun 21
1799
0
Mar 23
1051
DOMAIN Solved
1
Feb 21
1652
1
Sep 23
1078
1
Jul 23
4367