Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

how to change sales order line price_unit and invoice line Price_unit readonly.

By
Alloice Lagat
on 8/2/13, 11:14 AM 4,237 views

I want to edit the xml file to make the field Unit Price Readonly in invoice and sale order..Still i am not getting the field readonly: I have tried <field name= price_unit readonly="1"> but to no avail,, stil the field is not readonly,, and i dont want to make it readonly=True in the .py file as the data will not be saved

Use readonly=True in .py & readonly=1 in .xml file to make any field as readonly.

Hiral Patel (hip)
on 8/2/13, 11:30 AM
1

Hiral Patel (hip)

--Hiral Patel (hip)--
Tiny ERP Pvt Ltd
http://www.odoo.com
913
| 2 1 5
India
--Hiral Patel (hip)--


Hiral Patel (hip)
On 8/5/13, 4:56 AM

Hello,

You have to change line in sale.py to:

'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True),

Bcz, Currently line is :

'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True, states={'draft': [('readonly', False)]}),

first it applys the readonly=True and then the domain, So it makes the field to readonly when state!='Draft'.

Thanks.

1

Jeudy Nicolas

--Jeudy Nicolas--
1181
| 6 7 8
PELOUSEY, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 9/6/13, 6:04 AM

Hello, in fact readonly for this spécific field is manage by to params:

  1. readonly=True
  2. states="{'draft': [('readonly', False)]}"

You can see it in this line in sale.py

   'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True, states={'draft': [('readonly', False)]}),

So as Sven Boudesseul said: You can inherit the base view and edit the field like this and force states param too :

    <record id="view_order_line_form2_inherit" model="ir.ui.view">
        <field name="name">sale.order.line.form2.inherit</field>
        <field name="model">sale.order.line</field>
        <field name="inherit_id" ref="sale.view_order_line_form2"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='price_unit']" position="replace">
                <field name="price_unit" readonly="1" states="{'draft': [('readonly', True)]}"/>
            </xpath>
        </field>
    </record>

Or just edit the base code : module Sale > sale_view.xml

<field name="price_unit" readonly="1" states="{'draft': [('readonly', True)]}" />

Think it could be a good module, and we can do something better wil user right. If user as right to change the price.

Note:

Be carrful, you have 2 <field name="price_unit"/> on the sale.order. One for the tree definition and an other for the form definition. I try to reproduce and can have readonly field, but I think there is a bug after, if you setup `price_unit as readonly in the view, this field will not be saved when you click on the save button. Can you confirm ?

Screenshot:

image description

Note 2:

readonly field are not saved: handle reading and writing readonly field

Yes, you must have readonly="1" and states="{'draft': [('readonly', True)]}" in your xml

Tuxservices, Jeudy Nicolas
on 9/9/13, 9:31 AM

Thats what i have done after editing the base code,sale>sale_view.xml,,but no change in the field..can you elaborate more on,,"inheriting the base view?" and where is this base view?

Alloice Lagat
on 9/9/13, 11:02 AM

I update with notes: there is 2 price_unit field on sale.order form view

Tuxservices, Jeudy Nicolas
on 9/10/13, 10:12 AM

I think you can not do what you want :) see my note 2 on the answer

Tuxservices, Jeudy Nicolas
on 9/10/13, 10:32 AM

Error: QWeb2 - template['ListView.rows']: Runtime Error: Error: QWeb2 - template['ListView.row']: Runtime Error: Error: Unknown field state in domain [["state","not in",["{'draft': [('readonly', True)]}"]]]

Alloice Lagat
on 9/11/13, 4:41 AM

Thats the error i have now..FYI am using v 6.1

Alloice Lagat
on 9/11/13, 4:42 AM

You need to have <field name="state"/> on your form view ..you can add invisible="1" if you don't want to see it .. but this field must be on form view.

Tuxservices, Jeudy Nicolas
on 9/11/13, 7:51 AM

<field name="price_unit" readonly="1"> will make the field readonly,,but will not post the value if you save..what might be the problem? Is it a bug? and where has it been resolved?

Alloice Lagat
on 9/11/13, 8:27 AM
1

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 8/2/13, 12:39 PM

It depends, if your invoice is generated by some order or by other document you can do what they said above (readonly...). But if you are trying to generate invoices and add lines by yourself, then you have to do develop more code.

A readonly field it's not going to store the price given by the onchange_product. So it's not going to work when you save it. The easiest thing is adding a new field "price_unit2" and make it readonly, then you can add the invisible attribute to price_unit but without making it readonly. Then you have to override the onchange_product to return price_unit and price_unit2. So the user it's going to see the price_unit2 but behind there is price_unit that it's going to be stored.

Hi Grover,,Your solution seems to be the workable,,but implementing it is a problem

Alloice Lagat
on 9/11/13, 12:40 PM
1
Xsias
On 8/2/13, 11:44 AM

You can inherit the base view and edit the field like this :

    <record id="view_order_line_form2_inherit" model="ir.ui.view">
        <field name="name">sale.order.line.form2.inherit</field>
        <field name="model">sale.order.line</field>
        <field name="inherit_id" ref="sale.view_order_line_form2"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='price_unit']" position="replace">
                <field name="price_unit" readonly="1"/>
            </xpath>
        </field>
    </record>

Or just edit the base code : module Sale > sale_view.xml

<field name="price_unit" readonly="1"/>

That's what i had done to invoice line in invoice.view.xml and it worked,,but for sales order it did not..it still not readonly after changing it to <field name="price_unit" readonly="1"/>

Alloice Lagat
on 8/3/13, 1:01 PM

If you want to try to edit in the Python file, he is in module : Sale > sale.py (line 698 for me) The strange thing is that he is already readonly = True for me.

Xsias
on 8/4/13, 1:33 PM

You create a new module and don't forget to add "sale" in the dependencies (file __openerp__.py).

Create your file .xml and add the code i've written in my answer.

Xsias
on 9/5/13, 9:38 AM

This new module i will create ,,what will i name it and how will it be related to the price_unit coz i dont want to change everything,,only 1 field,

Alloice Lagat
on 9/5/13, 1:08 PM
0
Boris Ghelman
On 10/1/14, 11:24 PM

After many days investigating and googleling,  I solved using this function, very usefull, is not read only  , is a :  don't allow users to quote below the sales price of products, and you can make your particular changes.

 

http://stackoverflow.com/questions/23359684/dont-allow-to-quote-below-the-sales-price-of-a-product-in-openerp

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 8/2/13, 11:14 AM
Seen: 4237 times
Last updated: 3/16/15, 8:10 AM