Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
6175 Vizualizări

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!

Imagine profil
Abandonează

Do you have any run-time errors?

Autor

No error appear unfortunately...

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 ?

Autor

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.

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

Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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

Imagine profil
Abandonează

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

Autor

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

Perfect ! Can you mark this question as close ?

Autor

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

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

Cel mai bun răspuns

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()

Imagine profil
Abandonează