user3679086
user3679086

Reputation: 49

How to create calendar view in OpenERP?

class lich(osv.osv):
    _name = "tt_lich" 
    _columns = {
        'name': fields.char('Mã lịch trình',size=20,required=True),
       'date_start':fields.date('Ngày bắt đầu'),
       'date_stop':fields.date('Ngày kết thúc'),
    }
lich()
<record id="lichcalendar" model="ir.ui.view">
            <field name="name">Lịch sản xuất</field>
            <field name="model">tt_lich</field>
            <field name="arch" type="xml">
                    <calendar date_start="date_start" date_stop="date_stop">
                        <group col="2">
                            <field name="name"/>
                        </group>
                    </calendar>
             </field>
        </record>
        <record id="action_lich" model="ir.actions.act_window">
            <field name="name">Lịch sản xuất</field>
            <field name="res_model">tt_lich</field>
            <field name="view_mode">tree,form,calendar</field>
        </record>

I try to create some calendar view but when when i put start date and stop date in form view then I move to calendar view and it show this error:

"Uncaught TypeError: Cannot read property '0' of undefined"

Upvotes: 2

Views: 2615

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

Provide color attribute to the calendar and date_start and date_stop field to specify the datetime data-type. So change the data-type from date to datetime after than it will work fine.

Try with this code,

class lich(osv.osv):
    _name = "tt_lich" 
    _columns = {
        'name': fields.char('Mã lịch trình',size=20,required=True),
        'date_start':fields.datetime('Ngày bắt đầu'),
        'date_stop':fields.datetime('Ngày kết thúc'),
    }


<record id="lichcalendar" model="ir.ui.view">
    <field name="name">Lịch sản xuất</field>
    <field name="model">tt_lich</field>
    <field name="arch" type="xml">
        <calendar string="Lịch sản xuất" color="name" date_start="date_start" date_stop="date_stop">
            <field name="name"/>       
        </calendar>
     </field>
</record>

For more help of calendar view

Upvotes: 1

Related Questions