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

How to copy default value from other field?

By
David
on 1/2/15, 2:12 PM 1,639 views

I want a datetime value to be inherited by default from other datetime value in the same view, but from other model.

Sale order lines will have a datetime field that, by default, take their value from a datetime field at sale_order model.

Anybody helping me?

I try adding _defaults when adding extra field as in:

class new_sale_order_line(osv.Model):

  
    _inherit = 'sale.order.line'
    _columns = {
        'date_finish': fields.datetime('Fecha fin'),
    }
    _defaults = {
        'date_finish' : 'inherited value????'

   }

1
Nishant Jogi
On 1/2/15, 2:47 PM

Hello David,

You can do it with help of XML by assigning parent model field value to child as default value with the help of context.

Example:

<record id="view_order_form" model="ir.ui.view">
    <field name="name">sale.order.form</field>
    <field name="model">sale.order</field>
    <field name="arch" type="xml">
        <form string="Sales Order" version="7.0">
            <field name="name" />
            <field name="date_finish" />
            <field name="order_line" context="{'default_date_finish' : date_finish}">
                <form string="Sales Order Lines">
                    <field name="product_id" />
                    <field name="date_finish" />
                </form>
            </field>
        </form>
    </field>
</record>

Thanks.

 

0
David
On 1/2/15, 3:22 PM

Thanks Nishant, It works!!! Thank you very much!

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

1 follower(s)

Stats

Asked: 1/2/15, 2:12 PM
Seen: 1639 times
Last updated: 4/3/15, 9:08 AM