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

[Closed] how to pass product default_code to the report file "quotation"?

By
Mitik974
on 8/1/13, 10:35 AM 1,842 views

Hi all,

I'm trying to show the default_code of a product to my final PDF file. But i'm facing to a new language and software, i'm coming from PHP/Mysql. I just want to populate the sale_order_line.reference, then use my field in my report like line.reference.

And my database field is still empty...

Here is my code "sale_order_line_rdp.py" :

from openerp.osv import osv, fields

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

    _columns = {
            'reference':fields.char('Reference', required=False, readonly=False)
    }

    def sale_order_line_reference(self, cr, uid, line, account_id=False, context=None):
        res = super('sale_order_line', self)._prepare_order_line_invoice_line(cr, uid, line, account_id=account_id, context=context)
        product_obj = self.pool.get('product.product')
        product = product_obj.search(cr, uid, line, context=context)
        res.update({'reference': product.default_code})
        return res

sale_order_line_rdp()

If anyone can help me please!

Do you have any run-time errors?

Xsias
on 8/1/13, 11:39 AM

No error appear unfortunately...

Mitik974
on 8/1/13, 12:08 PM

Because i don't write my .search() like you. I will post an answer you could try. If she is'nt good, i will delete her. But before, can you say to me : What is the line variable ? A list ? Just an id ? The id of what ?

Xsias
on 8/1/13, 12:21 PM

Thanks for your answer, i just want to retreive the default internal Reference of a product. Default it's a char field. The field "default_code" in table product.product basic table in database.

Mitik974
on 8/1/13, 1:33 PM

I'm ok with the field "default_code", my question was about the line variable here : product_obj.search(cr, uid, line, context=context).

Xsias
on 8/1/13, 2:19 PM
0
Chyn Wey Lee
On 10/31/13, 1:05 PM

I am having trouble with this.

I want to add another column to the quotation report that get the value from internal reference. i tried using [[ format(default_code) ]]

but can't seem to get it to work. can someone help me please

0
Mitik974
On 8/2/13, 12:34 PM

The line for me was the same thing what in sale.py. I feel i'm not understanding completely the OpenERP framework...

Not working with your code...

But you point me to the line variable. I changed my code now is:

    id_product = res['product_id']
    product_obj = self.pool.get('product.product')
    product = product_obj.search(cr, uid, [('id','=', id_product)])
    res.update({'reference': product.default_code})

The same thing... Nothing...

EDIT I finally find a solution!

Here my new code (not very clean but it work...)

*sale.py*    
from openerp.osv import osv, fields

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

    _columns = {
            'reference':fields.char('Reference', required=False, readonly=False)
    }

    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, reference='', context=None):
        if not product:
            return {'value': {'th_weight': 0,
                'product_uos_qty': qty}, 'domain': {'product_uom': [],
                   'product_uos': []}}
        context = {'lang': lang, 'partner_id': partner_id}
        context_partner = {'lang': lang, 'partner_id': partner_id}
        product_obj = self.pool.get('product.product').browse(cr, uid, product, context=context_partner)

        res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
                                                             uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
                                                             lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)

        res['value'].update({'reference': product_obj.default_code or False})
        return res

sale_order_line()

class sale_order(osv.Model):
    _name = 'sale.order'
    _inherit = 'sale.order'

    def _prepare_invoice(self, cr, uid, order, line, context=None):
        res = super(sale_order, self)._prepare_invoice(cr, uid, order=order, line=line, context=context)
        res['reference'] = line.reference
        return res

sale_order()

*sale_view.xml*
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record id="view_order_reference_form_change" model="ir.ui.view">
            <field name="name">sale.order.form.sale.reference</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='product_id']" position="replace">
                    <field name="reference"
                    context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                    groups="base.group_user"
                    on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False,reference, context)"/>
                </xpath>

            </field>
        </record>
        <record id="view_order_image_form_inherit" model="ir.ui.view">
            <field name="name">sale.order.form.sale.image</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='product_id']" position="before">
                    <field name="reference"/>
                </xpath> 

                <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='price_subtotal']" position="before">
                    <field name="reference"/>
                </xpath>


            </field>
         </record>
    </data>
</openerp>

thanks for your patience

id_product return something ? (Try with "print id_product" to know that)

Xsias
on 8/2/13, 1:12 PM

Tonight i going to install a debug environment in a VM with eclipse or aptana, because all my tests are in a Windows environment. I return after to explain more

Mitik974
on 8/3/13, 11:59 AM

Perfect ! Can you mark this question as close ?

Xsias
on 8/5/13, 5:44 AM

I can't mark this question as close...

Mitik974
on 8/5/13, 11:38 AM

Me too, i don't have enought karma. By default, you can edit your question and add [Closed].

Xsias
on 8/5/13, 12:41 PM
0
Xsias
On 8/2/13, 8:00 AM

Could you try this :

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

    _columns = {
            'reference':fields.char('Reference', required=False, readonly=False)
    }

    def sale_order_line_reference(self, cr, uid, line, account_id=False, context=None):
        res = super('sale_order_line', self)._prepare_order_line_invoice_line(cr, uid, line, account_id=account_id, context=context)
        product_obj = self.pool.get('product.product')
        product = product_obj.search(cr, uid, [('TheFieldCorrespondingInProduct_product','=',line)])
        res.update({'reference': product.default_code})
        return res

sale_order_line_rdp()

The edit is in the .search()

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: 8/1/13, 10:35 AM
Seen: 1842 times
Last updated: 3/16/15, 8:10 AM