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
Do you have any run-time errors?
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 ?
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).