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.

0

sale quotation: check if unit_price lower than purchase price

By
Kris Coenen
on 10/15/13, 12:25 PM 766 views

Hi

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:
            pass
        elif unit_price < purchase_price:
            raise osv.except_osv(('fout'),('Verkoopprijs moet lager zijn dan aankoopprijs'))
        elif unit_price > purchase_price:
            pass

.xml

    <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>
        <xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="replace">
            <field name="price_unit" on_change="check_margin('product_id')"/>
        </xpath>
    </field>
</record>

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

with regards

Kris Coenen

Hi Kris Conenen . did you solve this? Me also facing this please help..

manuthalasseril
on 5/8/14, 12:43 PM

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: 10/15/13, 12:25 PM
Seen: 766 times
Last updated: 3/16/15, 8:10 AM