This question has been flagged
2 Replies
7228 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 :(

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author Best Answer

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>
Avatar
Discard

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