콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
3673 화면

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!    

아바타
취소
베스트 답변


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
    

아바타
취소
베스트 답변

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



아바타
취소
작성자

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>

관련 게시물 답글 화면 활동
1
6월 21
3201
0
3월 23
2017
DOMAIN 해결 완료
1
2월 21
2495
1
9월 23
2506
1
7월 23
5742