Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
3536 Vistas

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
Descartar
Mejor respuesta


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
Descartar
Mejor respuesta

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
Descartar
Autor

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>

Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 21
3059
0
mar 23
1862
DOMAIN Resuelto
1
feb 21
2410
1
sept 23
2386
1
jul 23
5605