Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
29544 มุมมอง

Odoo V9. In fields.date, is it possible to display month and year only?

ex. 11-2016

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Giezel,

Module swr_datepicker can be used for  v10.  but you are using v9.

See the alternative solution

Py

# Outside the model
def get_years():
    year_list = []
for i in range(2016, 2036):
        year_list.append((i, str(i)))
    return year_list


# Inside the model
month = fields.Selection([(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'),
(5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'),
                          (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December'), ],
  string='Month',
year = fields.Selection(get_years(), string='Year',)

xml

<group> 
    <div>
        <label for="month" string="Month"
               style="font-weight: bold !important;margin-right:107px;margin-left: 0px;"/>
        <field name="month" style="width:110px"/>
        <field name="year" style="width:110px;margin-left: 34px;"/>
</div>
</group>

All the best !



อวตาร
ละทิ้ง

I installed your module and i don't know how it work? I realized that in Languages, we have two more field is Year format and Month format, but how can i use that format for my own module to display like this '07/2019' in my field?

คำตอบที่ดีที่สุด

No it is not possible

But you can achieve the same using computational field of type Char, so in the method, parse the date and extract in whichever format you want.


 

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ค. 22
16459
1
ม.ค. 20
7499
1
ม.ค. 18
4406
0
ม.ค. 18
3277
odoo9 yesterday filter แก้ไขแล้ว
1
ก.พ. 23
6000