Skip to Content
Menu
This question has been flagged
1 Reply
13164 Views

Hi 

I am trying to get a related field value from database, but it showing column 'column_name' does not exist

When i try to find out the value of product_id or using join to find the common data between sale.order and product.product Model . but it showing column 'column_name' does not exist.

In sale.order model the field defination is like 

product_id = fields.Many2one('product.product', related='order_line.product_id', string='Product')

But when i try to join two table like below code to fetch all data as per product, like below code.

select coalesce(p.name,'Unassigned Product'), count(*) from sale_order o left join product_product p on o.product_id = p.id where o.state = 'sale' group by p.name;

It showing below error, 

column o.product_id does not exist
LINE 1: ... from sale_order o left join product_product p on o.product_...

When i try to get data from sale_order  table like below code.

select product_id from sale_order; 

It showing below error. 

column "product_id" does not exist

Can any one help me to get that value. 

Avatar
Discard

without adding store=True in python code the related fields will not store into the Database by default

or

in xml you have give an attribute force_save="True"

Author

I know that attribute, but this field is sale.order base field and no. of data also there. So i don't want to update that field. If i update that field it will not affect the past data. So any other option is there? Please tell me.

Best Answer

Try:

product_id = fields.Many2one(
'product.product',
related='order_line.product_id',
string='Product',
store=True,
)

The attribute store would add a column to Postgres. Otherwise, it is just a Python method which apply to a comodel table (in that case product.product) on a fly. 

Avatar
Discard
Related Posts Replies Views Activity
0
Jul 24
327
0
Dec 21
1323
2
Oct 16
5195
1
Jan 16
4109
0
Mar 15
3470