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

inherit sale.order.line, get bill of materials for product

By
Wolfgang Steuer
on 6/27/13, 12:16 PM 2,274 views

I just started to develop for openerp and I'm stuck already for hours on this one:

I want to display all bill of materials with all products in the sale order for each product.

This is my class which inherits from "sale.order.line" which resides in my own module.

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

    def _get_bom(self, cr, uid, ids, field_name, arg, context=None):
         result = {}
         result[ids] = self.pool.get('product.bom_ids').browse(cr, uid, ids, context=context)
         result[boms] = self.pool.get('mrp.bom').browse(cr, uid, ids, context=context)
         return result 

    _columns = {
        'bom': fields.function(_get_bom, method=True, string='Bill of Materials', type='text', store=False)
    }

sale_order_line()

But when I use now [[ line.bom ]] in sale_order.rml I get the error message: Cannot eval 'line.bom' AttributeError: 'str' object has no attribute 'get'

What am I doing wrong? I guess it is just a simple programming mistake :(

0

patrick

--patrick--
1958
| 5 4 7
Baarn, Netherlands
--patrick--
patrick
On 6/28/13, 4:27 AM

The line with self.pool.get('product.bom_ids') doesn't look good.

it should be like self.pool.get(model.name), so self.pool.get('product.bom'), if product.bom is the name of the class/object for the Bill of Material.

Further, on which line does the error happen? It might be noted in the log-file.

0
Wolfgang Steuer
On 7/8/13, 10:58 AM

I managed to solve it myself :)

It was actually very easy without doing any code. Since a order.line contains the actual product, and a product has a reference to its boms, it looks like this: (show_bom and show_discounts are custom fields I added by inheriting "sale.order")

<section>
  <para style="terp_default_1">[[repeatIn(o.order_line,'line')]]</para>
  <blockTable colWidths="250.0,80.0,70.0,50.0,85.0" style="Table5">
    <tr>
      <td>
        <para style="terp_default_9"><b>[[ format(line.name) ]]</b></para>
        <para style="terp_default_9">[[ format(line.product_id.description) or removeParentNode('para') ]]</para>
        <section>
            <para style="terp_default_9">[[ o.show_bom and repeatIn(line.product_id.bom_ids,'bom') ]]</para>
            <para style="terp_default_9"> </para>
            <para style="terp_default_9">Stückliste: [[ format(bom.name) ]]</para>
            <section>
                <para style="terp_default_9">[[ repeatIn(bom.bom_lines,'bomline') ]]</para>
                <blockTable style="Table3" colWidths="220.0,60.0,60.0">
                    <tr>
                        <td>[[ format(bomline.product_id.name) ]]</td>
                        <td>[[ bomline.product_qty ]]</td>
                        <td>[[ o.show_bom and formatLang(bomline.product_id.list_price, digits=get_digits(dp='Product Price')) ]]</td>
                    </tr>
                </blockTable>
            </section>
        </section>
      </td>
      <td>
        <para style="terp_default_Right_9">[[ formatLang(line.product_uos and line.product_uos_qty or line.product_uom_qty) ]] [[ line.product_uos and line.product_uos.name or line.product_uom.name ]]</para>
      </td>
      <td>
        <para style="terp_default_Right_9">[[ not o.show_discounts and formatLang(line.price_unit * (1 - line.discount / 100) , digits=get_digits(dp='Product Price')) or formatLang(line.price_unit , digits=get_digits(dp='Product Price'))]]</para>
      </td>
      <td>
        <para style="terp_default_Centre_9">[[ o.show_discounts and formatLang(line.discount, digits=get_digits(dp='Discount')) or '']]</para>
      </td>
      <td>
        <para style="terp_default_Right_9">[[ formatLang(line.price_subtotal, digits=get_digits(dp='Account'), currency_obj=o.pricelist_id.currency_id) ]] </para>
      </td>
    </tr>
  </blockTable>
</section>

hi this looks nice, but where did you place this code ?

a
on 12/21/13, 1:57 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

2 follower(s)

Stats

Asked: 6/27/13, 12:16 PM
Seen: 2274 times
Last updated: 3/16/15, 8:10 AM