Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Openerp 7 calendar: end date for sale order calendar

By
Mathieu Stumpf
on 4/25/14, 4:22 AM 1,194 views

I'm trying to add an end date for the sale order calendar, here is the code I would expect to do the work :

<?xml version="1.0" encoding="UTF-8"?>
 <openerp>
<data>
<!-- add the expiration_date support -->
    <record id="sale.view_sale_order_calendar" model="ir.ui.view">
        <field name="name">sale.order.calendar</field>
        <field name="model">sale.order</field>
        <field name="arch" type="xml">
            <calendar string="Sales Orders" color="state" 
                date_start="date_order"
        date_stop="expiration_date"
        >
                <field name="partner_id"/>
                <field name="amount_total"/>
            </calendar>
        </field>
    </record>      

    <record model="ir.ui.view" id="partner_axima_form_view">
        <field name="name">sale.order.form</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form" />
        <field name="arch" type="xml">

            <field name="shop_id" position="after" >
                <field name="validity_duration" 
                    on_change="onchange_validity_duration(validity_duration)" />
            </field>

    </record>      

</data>
</openerp>

Where expiration_date and validity_duration is defined as follow :

class sale_order(osv.Model):
    _inherit = 'sale.order'


    def _get_validity_durations(self, cursor, user_id, context=None):


        durations = ("One week",
                     "Two weeks",
                     "Three weeks",
                     "One month",
                     "Permanent")
        return list(enumerate(durations, start=1))

    _columns = {
        'validity_duration': fields.selection(
            _get_validity_durations,
            u'Durée de validitée du devis'),

        'expiration_date' : fields.date(u"Date d’expiration",
                                            required=False, ),
    }

    def onchange_validity_duration(self, cr, uid, ids, validity_duration=False, context=None):
        import datetime
        from dateutil.relativedelta import *
        today = datetime.date.today()
        if validity_duration in [0, False] :
            expiration_date = False
        else:
            expiration_date = today+relativedelta(weeks=+validity_duration)
        self.write(cr, uid, ids, {'expiration_date': expiration_date}, context=context)

        return {}

But looking at calendar it doesn't work, in fact it looks like the events are displayed beginning at the end date (expiration_date), and end in the same day.

0
Mathieu Stumpf
On 4/25/14, 10:30 AM

Here is an xml working version :

    <record id="view_sale_order_calendar" model="ir.ui.view">
        <field name="name">order.calendar</field>
        <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_sale_order_calendar" />
        <field name="arch" type="xml">
    <xpath expr="//calendar" position="attributes" >
        <attribute name="date_stop">expiration_date</attribute>
    </xpath>
        </field>
    </record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/25/14, 4:22 AM
Seen: 1194 times
Last updated: 3/16/15, 8:10 AM