Skip to Content
Menu
This question has been flagged
3 Replies
3829 Views

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
Discard
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
Discard
Author

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 Replies Views Activity
4
Sep 15
4639
1
Apr 15
2934
10
May 18
55366
1
Mar 18
4351
1
Aug 23
12549