Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

How to alert if user sell product bellow cost?

形象
odoo
形象
丢弃
3 答案
0
形象
odoo
最佳答案

Hi Lima:

You can display the Sales Order Lines in red color if the unit price is less than the cost by adding a custom boolean field to the Sales Order Line model and using it to change the color of the text in that row. The boolean field will compare the value of the unit price and the cost and return a True or a False as it's value which can then be used in the QWeb view.

a. Add a computed boolean field to the Sales Order Line model like so.

 

b. Inherit and extend the sale.view_order_form to use the value of the custom field to change the color of the rows where the unit price is less than the cost like so.


Code in Architecture field:

<data>
    <xpath expr="//page[@name='order_lines']//tree[1]">
        <field name="x_price_below_cost" invisible="1"/>
    </xpath>
    <xpath expr="//page[@name='order_lines']//tree[1]" position="attributes">
        <attribute name="decoration-danger">(x_price_below_cost)</attribute>
    </xpath>
</data>

The result in the Sales Order form. The cost of the first line item is $190. The entered unit price is $150 so the row is displayed in red. The cost of the second line item is $85 so it is displayed in the normal color.


1 备注
形象
丢弃
形象
odoo
-

Thank you very much :)

This is perfect the answer, I'll think about the POS for now.

0
形象
odoo
最佳答案

thank you so much

but this code not working in v 18

how update this

形象
丢弃
0
形象
odoo
最佳答案

Any Idea how to prevent the sale if the value is lower than cost? in the given answer it just alerts.

3 注释
形象
丢弃
形象
odoo
-

Hi Moustafa: You can extend the model, perform a similar check in the "create" method and raise a ValidationError to prevent the user from saving the order.

形象
odoo
-

If writing a custom module is not an option, you can implement something similar using an automated action/automation rule.

形象
odoo
-

Thanks Paresh, this really helps