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

How to use a global variable

By
abdelwahed chiheb
on 10/20/13, 4:52 AM 2,339 views

Hello,

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

    list_product.append(product)

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

sale_order_line()

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

Any ideas?

0
nazarii
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)

nazarii
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

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

1 follower(s)

Stats

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