This question has been flagged

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

Avatar
Discard

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

Author

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

Best Answer

Check this link, works great

 

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

Avatar
Discard