Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3 Antwoorden
4793 Weergaven

I am using Odoo v8.

I have a situation in a services company where the final cost of providing a service may not be known until after the Invoice has been issued (validated) and sometimes it will have been paid.

An estimate of the cost price can be entered on the Sales Order Line. I have written a module to pass the Cost Price (price_unit) field to the Invoice Line on creation of the Invoice. Cost Price is editable whilst the Invoice is in “Draft” state. Once the Invoice is validated, none of the Invoice Line is editable. I need to make a change which will allow just my new Cost Price field to remain editable.

I can see in account_invoice.py that the invoice line is treated as one field which is only editable in the draft status :-

invoice_line = fields.One2many('account.invoice.line', 'invoice_id', string='Invoice Lines',

    readonly=True, states={'draft': [('readonly', False)]}, copy=True)

So my question is how can I allow editing of an individual field on the invoice line with any status?

 

Avatar
Annuleer
Beste antwoord

Gill,

In order to make separate fields editable under a one2many fields, u need to make changes at xml part as:

<field name='invoice_line'>

<tree>

<field name='cost_price_field' attrs="{'readonly': [('parent.[STATE_FIELD IN ACCOUNT.INVOICE]', '=', 'draft')]}"/>

<field name='abc' attrs="{'readonly': [('parent.[STATE_FIELD IN ACCOUNT.INVOICE]', '=', '[STATE]')]}"/>

<field name='def' attrs="{'readonly': [('parent.[STATE_FIELD IN ACCOUNT.INVOICE]', '=', '[STATE]')]}"/>

</tree>

</field>

this will make the individual field in invoice_line field(one2many to account.invoice.line) to be readonly on the basis of state of current invoice object.

Hope it Helps!

Avatar
Annuleer
Auteur

Thank you for your suggestion. I am struggling to apply it as I need to add it to my xpath expression and I want to be able to EDIT the field rather than not edit it. So readonly needs to be set to false for parent.state of open and paid. My xml is here <xpath expr="//field[@name='invoice_line']/tree/field[@name='price_unit']" position="after">

Gill,
Please keep it like this
< xpath expr="//field[@name='invoice_line']/tree/field[@name='price_unit']" position="attribute">
<attribute name="attrs">{'readonly': [('state', 'not in ', ['open', 'paid'])]}</attribute>
</xpath>
Hope i got u right!

Gerelateerde posts Antwoorden Weergaven Activiteit
4
sep. 15
5785
1
apr. 15
3826
10
mei 18
56702
1
mrt. 18
5325
0
mrt. 25
1363