Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4503 Lượt xem

I am trying to get the purchase form to show my product manufacturer. I did managed to get the manufacturer code to show with :

'manufacturer_pref': fields.related('product_id', 'manufacturer_pref', type="char", relation="product.product", string="Manufacturer Code", store=True),

I am also trying to get the manufacturer related to this manufacturer_pref.

both fields are in the product.product table, (manufacturer and manufacturer_pref). Only thing that looks to be tricky, is that manufacturer is a mny2one field taken from res.partner :

'manufacturer' : fields.many2one('res.partner', 'Manufacturer'),

I have tried many ways but still, I cannot get the "Name" of the partner to show up. I do have the integer(id) related to the partner table in the product.product table under manufacturer field. But, I cannot get it to show and or being added in the purchase.order.line tableor form/report.

Can anyone help me dig it?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

just modify your comment typed code type='char' into type='many2one' Example, 'manufacturer':fields.related('product_id', 'manufacturer', type='many2one', relation='product.product', string='manufacturer', store=True); same as sudhir arya but change relation res.partner into product.product.

Ảnh đại diện
Huỷ bỏ

hi, the problem u had is caused by "relation", the field u created on product_product is many2one and the object is res.partner. So on field related in purchase.order.line, u need to link it to res.partner instead of product.product

please try this code : 'manufacturer_pref': fields.related('product_id', 'manufacturer', type="many2one", relation="res.partner", string="Manufacturer Code", store=True),

Tác giả

Yes. finaly, Maybe we had tried this earlier but I had a typos in, fields.related('product_id', 'manufacturer', type="many2one", relation="res.partner", string="Manufacturier", store=True),

Câu trả lời hay nhất

Hello Christian Parent,

You just have to add another related field to get manufacturer.

Here it is:

fields.related('product_id', 'manufacturer', relation='res.partner', type='many2one', string='Manufacturer')

You can get more information about related and other fields: OpenERP Fields

Hope this will help you.

Ảnh đại diện
Huỷ bỏ
Tác giả

I am receiving File "/opt/openerp/server/openerp/osv/fields.py", line 1285, in _fnct_read value = value[field] or False File "/opt/openerp/server/openerp/osv/orm.py", line 387, in __getitem__ raise KeyError(error_msg) KeyError: "Field 'manufacturer' does not exist in object 'browse_record(purchase.order, 8)'"

When creating a new record. I will try to use existing records and add manufacturer to my view see if it at least links.

Tác giả

I have modified the line a couple time... I am at 'manufacturer': fields.related('product_id', 'manufacturer', type="char", relation="product.product", string="Manufacturier", store=True), this at least gives me something in the DB : browse_record(res.partner, 1654) 1654 is the right manufacturer, so getting close but just not there yet !!!

Tác giả Câu trả lời hay nhất

I dont know if it is the way we are doing it but, it does not seem to work. The manufacturer of the product already exist in the product.product table, it is his id number from res.partner. The things tried so far does not work, see my comment above.

Remember, I want to add the field manufacturer to purchase.order.line table. The line in this table consist of each individual product ordered in an invoice.

I have managed to add the manufacturer reference code thru :

'manufacturer_pref': fields.related('product_id', 'manufacturer_pref', type="char", relation="product.product", string="Manufacturer Code", store=True),

So, I use the product_id from purchase_order_line which is the primary key (ID) in the table product.product. with that, I can get the manufacturer_pref which is already in the product.product table.

When I try to do similar to this for manufacturer name (manufacturer) It gives me errors.

I have all the logic :

Product_id in purchase_order_line is related to id in product.product. Each product in product.product has a field manufacturer which contains the id (Primary Key) of the res.partner table.

What I need to get in purchase_order_line is the field "name" from res.partner .... Is this more clear ?

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 24
8222
1
thg 3 18
3373
2
thg 12 15
3206
0
thg 3 15
3089
2
thg 11 16
7374