Skip to Content
Menú
This question has been flagged
3 Respostes
4706 Vistes

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
Descartar
Best Answer

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
Descartar
Autor

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!

Related Posts Respostes Vistes Activitat
4
de set. 15
5667
1
d’abr. 15
3730
10
de maig 18
56580
1
de març 18
5259
0
de març 25
1264