跳至内容
菜单
此问题已终结
1 回复
14670 查看

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. 

形象
丢弃

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"

编写者

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.

最佳答案

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. 

形象
丢弃
相关帖文 回复 查看 活动
0
7月 24
1291
0
12月 21
2423
2
10月 16
6160
1
1月 16
4876
0
3月 15
4105