Odoo Help


How to use a global variable

abdelwahed chiheb
on 10/20/13, 4:52 AM 3,471 views


I want to display a warning message when the user add an existing sale order line,

exp: i have a sale order line with an item x, when i add an other sale order line with the item x i want to display the warning message.

global list_product list_product = []

class sale_order_line(osv.osv): _inherit = 'sale.order.line'

def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
        uom=False, qty_uos=0, uos=False, name='', partner_id=False,
        lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
    context = context or {}
    lang = lang or context.get('lang',False)

................... if product in list_product: WRNNING MESSAGE HERE


    if warning_msgs:
        warning = {
                   'title': _('Configuration Error!'),
                   'message' : warning_msgs
    return {'value': result, 'domain': domain, 'warning': warning}


with this code i can not initialize the variable list_product[]

Any ideas?




| 5 4 7
On 10/20/13, 3:51 PM
if product: line_ids = self.pool.get('sale.order.line').search(cr, uid, [('product_id), '=', product])

Hello nazarii, i tried your code but i have the list of items of all order line in my database. i would like to get just the items of my current order (the order can be not yet saved). Thanks

abdelwahed chiheb
on 10/21/13, 6:59 AM

You'r order items are passed as arguments to product_id_change method (E.g. product will be id of product even if the order is not saved yet)

on 10/21/13, 7:29 AM

if i have 3 lines with 3 different items, how can i get those items at the time when i'm adding the 4 th line ( 3 lines not yet saved and i want to do this in product_id_change ). thanks for your response

abdelwahed chiheb
on 10/21/13, 11:20 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/20/13, 4:52 AM
Seen: 3471 times
Last updated: 3/16/15, 8:10 AM