This question has been flagged
2 Replies
5230 Views

Hi everybody,

I would like to know how is possible to get (or to link together) in a field another field save in other table?

To be more clear:

My first field (field1) is a one2many field. Table product.product. My second field (field2) is on the table sale.order.line.

The goal of this manipulation is to have the field1 for each product of the sale.order.line Need I to declare my field2 as a one2many too? or can in make the link to say: My field 2 is my field 1?

Thank you a lot,

Selverine

Avatar
Discard
Best Answer

I would make field2 many2one.
And then use an on_change method on field2 or make field1 a function field to get the products of the sale.order.line

Or better: Make field1 a relational field!

Avatar
Discard
Author Best Answer

Hi René Schuster,

Thank your for your help.

So, I try to use a relational field. In the developer guide I saw this :

:City -> State -> Country, and you need to refer to the Country from a City, you can define a field as below in the City object: 'country_id': fields.related( 'state_id', 'country_id', type="many2one", relation="res.country", string="Country", store=False)

So I try to adapt to my projet.

I have

Sale.order.line <-> product -> BAT

It is why I try to do that:

class product_bat(osv.osv):
_name = 'product.bat'
_description = 'Product BAT'

_columns = {
    'name': fields.char('Name', size=64, required=False, translate=True),
    'name_id': fields.many2one('product.bat', 'Template'),
    'product_link_BAT': fields.many2one('product.template', 'Template Id'),
    'product_BAT' : fields.related('product_link_BAT', 'product_link_sale', string=" Product BAT", relation='sale.order.line', type='char', size=128, store=True, select=True),

}

product_bat()

class product_template(osv.osv): _name = "product.template" _description = "Product Template"

_columns = {
    'name': fields.char('Name', size=128, required=True, translate=True, select=True),
    'product_BAT': fields.one2many('product.bat', 'product_link_BAT', 'product BAT'),
    'product_link_sale': fields.many2one('sale.order.line', 'Product link sale'),

class sale_order_line(osv.osv):

_name = 'sale.order.line'
_description = 'Sales Order Line'
_columns = {
    'order_id': fields.many2one('sale.order', 'Order Reference', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
    'name': fields.text('Description', required=True, readonly=True, states={'draft': [('readonly', False)]}),
    'product_link' : fields.one2many('product.product', 'product_link_sale', 'test_aurel'),

But it don't works. Have you an idea please? Is it a problem of link object together?

My error:

AttributeError: 'NoneType' object has no attribute '_table'

Thanks

Aurelien

Avatar
Discard