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

Hii,

In one of my xml list view, want to show a date in quarters. 

<field name="create_date" string="Quarter" />

How to format the date field to show like Q3 2019 instead of the date?

Thanks,

아바타
취소
작성자 베스트 답변

I done it the following way. Added new custom field by inheriting the hr.appraisal.

appraisal_quarter = fields.Char(string='Quarter', compute='_get_appraisal_quarter')
@api.multi
    def _get_appraisal_quarter(self):
    for appraisal in self:
        appraisal_date = appraisal.date_close
        month = appraisal_date.month
        year = appraisal_date.year
        if 0 <= int(month) <= 3:
            appraisal.appraisal_quarter = 'Q1 ' + str(year)
        elif 4 <= int(month) <= 6:
            appraisal.appraisal_quarter = 'Q2 ' + str(year)
        elif 7 <= int(month) <= 9:
            appraisal.appraisal_quarter = 'Q3 ' + str(year)
        elif 10 <= int(month) <= 12:
            appraisal.appraisal_quarter = 'Q4 ' + str(year)
        else:
            appraisal.appraisal_quarter = 'NA'
# list view
<field name="appraisal_quarter" />
result: Q3 2019

아바타
취소
관련 게시물 답글 화면 활동
4
3월 16
6691
3
6월 25
1200
1
1월 25
18030
2
12월 24
2569
1
11월 22
6681