Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
4 Відповіді
52921 Переглядів

Add the Ship field as a drop down list field of the Ship object to the order lines next to quantity. and Create a button under ship field 'Update to Order Lines', update the same Ship information to the order lines. When creating a new order line, in the Ship field in order line by default show the Ship information of the SO..!!?

<xpath 
expr="//field[@name='order_line']" position="attributes">

     <attribute name="context">{'default_shipimo':ship}    </attribute>

</xpath>

Аватар
Відмінити
Автор

i need the Python code too..

Автор

.

Найкраща відповідь

There are mostly 2 ways of setting a default value for the fields in Odoo(there are more, but this are the most used ones).

1- Setting the default value in the Python model that contains the field

#old api
    _defaults = {
        'ship': 'ship_value1',
    }

#new api

    ship = fields.Selection([('ship_value1', 'Value1'),('ship_value2', 'Value2')], default='ship_value1')


2- Setting the value in xml view field or action of the form that contains the field, using context ('default_ship') like:

#the content of the field lines is not necessary, i put it for the sake of the example

<field name='lines' context="{'default_ship': 'ship_value1'}">
    <form string="Line">
        <field name="ship"/>
    </form>
    <tree>
        <field name="ship"/>
    </tree>
</field>


Аватар
Відмінити

I tried this syntax to modify an existing view but it doesn't work :

<field name='group_by_name' position="attributes">

<attribute name="string" eval="'dummy_title'"/>

<attribute name="context" eval="{default_group_by_name': 1}"/>

</field>

The syntax is globally good because the "dummy_title" appears,

but the {context...} don't

I tried several other things in the eval clause ('group_by_name': 'True', 'group_by_name': True, etc...) and nothing works.

Can you help me ?

a complementary info : the field group_by_name is of type boolean

The thing is that you need to put that context where it's belong to, like in an action, many2one, one2many or many2many field where the call to default_get to get the default values for the form create of the model record could take the context into account. Summary: don't put it on the field that needs the default, set it to the superior level so it could be taken into account as a default for the form values

Найкраща відповідь

In module file

<<field name>>= fields.<<datatype>>(default=<<value>>)


in views.xml

<field name="start_date"/>

Аватар
Відмінити
Найкраща відповідь

In odoo 9 we use 

ship = fields.Selection([('ship_value1', 'Value1'),('ship_value2', 'Value2')], default=lambda self: self._context.get('ship', 'ship_value1'))


Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
жовт. 24
1534
0
груд. 22
1540
0
квіт. 20
3560
1
серп. 19
6263
1
жовт. 16
6438