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.

1

How to develop a function that returns move_line.product_id.name?

By
Mr Rhys Park
on 3/21/13, 3:58 PM 1,884 views

I am having some difficulty with this, i am trying to get the description from the sales order per product line on the delivery note:

The delivery note calls the following function:

def get_product_desc(self,move_line):
    desc = move_line.product_id.name
    if move_line.product_id.default_code:
        desc = '[' + move_line.product_id.default_code + ']' + ' ' + desc
    return desc

I would have thought that just adding + move_line.product_id.XXX and creating a field in the move line names xxx would have done it? But I cannot for the life of me figure out how to add the field to the move_line ?

Your help would be appreciated

Do you want to put the information onto a report? Which report? Do you mean the name or the description of the product? which version do you use?

Andreas Brueckl
on 3/21/13, 4:02 PM

Using version 7, I want to get the info into the delivery note created from rhe sales order through create deliveries. I need to get the Description from the sales order line in there. i.e we have some products where the code is meaningless and on the order we add text in the sales line.

Mr Rhys Park
on 3/21/13, 4:29 PM
0

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/22/13, 4:36 AM

I do not know where do you use the function but if you want to return the description of the sale.order.line then you can use:

def get_product_desc(self,move_line):
    if move_line.sale_line_id:
        return move_line.sale_line_id.name
    return False

I assume that move_line is not only the id, but a whole object.

0
Mr Rhys Park
On 3/21/13, 5:19 PM

I tried

def get_product_desc(self,move_line):
    product_product = self.pool.get('product.product')
    product = product_product.browse(cr, uid, move_line.product_id, context=context_partner)
    # desc = move_line.product_id.name 
    desc = product.name
    if product.default_code:
        desc = '[' + product.default_code + ']' + ' ' + desc
    return desc

again the move_line is passed from the picking.py and called in the report, i still think I would need to add the description into the move_line

Still stuck but thanks

if product.default_code: desc = '[' + product.default_code + ']' + ' ' + desc return desc

AJ Schrafel Paper Corp
on 3/21/13, 5:21 PM

def get_product_desc(self,move_line): product_product = self.pool.get('product.product') product = product_product.browse(cr, uid, move_line.product_id, context=context_partner) desc = product.name if product.default_code: desc = '[' + product.default_code + ']' + ' ' + desc return desc

Mr Rhys Park
on 3/21/13, 5:28 PM
0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2050
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 3/21/13, 4:29 PM

product_id just holds the identifier for the product, no more details.

you have to do something more like this:

def get_product_desc(self,product_id):
    product_product = self.pool.get('product.product')
    product = product_product.browse(cr, uid, product_id, context=context_partner)
    desc = product.name
    if product.default_code:
        desc = '[' + product.default_code + ']' + ' ' + desc
    return desc

I see where your coming from with that but I still cant get it working,

Mr Rhys Park
on 3/21/13, 5:11 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: 3/21/13, 3:58 PM
Seen: 1884 times
Last updated: 3/16/15, 8:10 AM