Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
14811 Vues

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
Ignorer

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"

Auteur

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.

Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
0
juil. 24
1410
0
déc. 21
2556
2
oct. 16
6324
1
janv. 16
4929
0
mars 15
4221