Oumar Diarra
Oumar Diarra

Reputation: 365

Display list of values in sale order form

I'm able to extend the sale order view and add 2 static fields. My code is like this:

class MysaleOrder(models.Model):
_inherit = 'sale.order'

rule_name=fields.Char('Règle')
rule_total = fields.Float('Montant de règle')
rule_exist=fields.Boolean(default=False)

And for the view:

<record id="remise1_view_order_form" model="ir.ui.view">
        <field name="name">sale.order.remse1.form</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <field name="amount_untaxed" position="before">
                <field name='rule_exist' invisible="1" />
                <field name="rule_name" nolabel="1" attrs="{'invisible':[('rule_exist', '!=', True)]}" readonly="1" />
               <field name="rule_total"  nolabel="1" widget='monetary' attrs="{'invisible':[('rule_exist', '!=', True)]}" readonly="1" options="{'currency_field': 'currency_id'}"></field>

            </field>

        </field>
    </record>

And the result:

enter image description here

Now I have a list [("solde1",1000),("solde2",2000)...]. Since that list is dynamic, I don't know the number of fields to generate.

How do I display that list in the form so that above HT price I'll have

solde1: 1000
solde2: 2000
....
Montant HT: value

Upvotes: 2

Views: 64

Answers (2)

simahawk
simahawk

Reputation: 2431

AFAIK the only way to achieve dynamically generated views is to override "fields_view_get" method and manipulate xml on the fly.

Upvotes: 0

Phillip Stack
Phillip Stack

Reputation: 3378

The form view really does not allow for dynamic elements of this nature easily. If you knew for sure you would have a maximum of x items you could use attrs="{'invisible': [('condition','=', True)]}" on each of your elements (field1,field2,field2) which would allow you to only display for field-n under the approprate condition, but the only element which is set up for truly dynamic n-elements is the one2many or many2many fields.

Qweb has the foreach templating function however this is not available in a normal form view.

Upvotes: 2

Related Questions