Odoo Help


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.


sale order : check if unit_price lower than purchase_price

Kris Coenen
on 10/15/13, 12:30 PM 987 views


I'm currently am worken on a way to check if the unit_price on the sale order line is lower than the standard_price on the product of that line. if the unit price is lower than the standard_price than the user should get an error and can't create a new line. If the unit_price is higher equal or null nothing should happen. currently i get an error

TypeError: result is null

Here is my code .py

def check_margin(self, cr, uid, ids, product_id, context=None):

    if product_id:
        purchase_price = self.pool.get('product.product').browse(cr, uid, product_id).standard_price
        unit_price= self.browse(cr, uid, product_id).price_unit
        if unit_price is None:
        elif unit_price < purchase_price:
            raise osv.except_osv(('fout'),('Verkoopprijs moet lager zijn dan aankoopprijs'))
        elif unit_price > purchase_price:


    <record model="ir.ui.view" id="sale_margin_sale_order_line">
    <field name="name">sale.order.line.margin.view.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="after">
            <field name="purchase_price" groups="base.group_user"/>
        <xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="replace">
            <field name="price_unit" on_change="check_margin('product_id')"/>

what am i doing row i'm just new in creating functions in openerp

with regards

Kris Coenen

Did you try to create a pricelist that enforces a minimum margin? I wonder what user experience that gives you?

Bista Solutions US, Ray Carnes
on 10/15/13, 1:58 PM

i've tryed that didn't work. i've set the min margin to 0.01 en max on 0. still didn't get a warning. i'll be looking further with the module

ANALYS4IT, Kris Coenen
on 10/16/13, 4:36 AM
Boris Ghelman
On 10/1/14, 11:23 PM

Check this link, works great



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)


Asked: 10/15/13, 12:30 PM
Seen: 987 times
Last updated: 3/16/15, 8:10 AM