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

I am trying to access the field manufacturer_pref from the product.product table from the purchase order report.

This is the module that created the field :

class product_product(osv.osv):
_inherit = 'product.product'
_columns = {
    'manufacturer' : fields.many2one('res.partner', 'Manufacturer'),
    'manufacturer_pname' : fields.char('Manufacturer Product Name', size=64),
    'manufacturer_pref' : fields.char('Manufacturer Product Code', size=64),
    'attribute_ids': fields.one2many('product.manufacturer.attribute', 'product_id', 'Attributes'),
}

I went in the purchase module, edited purchase.py and added this under _columns = {

'manufacturer_pref': fields.related('order_line','manufacturer_pref', type='char', relation='product.product', string='Manufacturer'),

saved, did a

./openerp-server -db My_DB -u=all

and when I get back in pgAdminIII, when I look in purchase_order_line table, the column is not showing up.

Where I am wrong ?

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

Did you add it in the class purchase_order or purchase_order_line ?

For the update command try: ./openerp-server -d My_DB -u all

What if adding purchase to order_line:

    'manufacturer_pref': fields.related('purchase_order_line','manufacturer_pref', type='char', relation='product.product',   string='Manufacturer'),
Ảnh đại diện
Huỷ bỏ
Tác giả

it was in the wrong class indeed, still it aint showing up after moving it down to the right class. It was not in the purchase_order table. I have looked before I made the changes !

Tác giả

Used -u all, it was a typo on my side tho as I use --update=all or --update=purchase. Still, after doing so, the new column not showing up in the purchase_order_line table. Is it something in my line that is not set properly ? The column manufacturer_ref is in product_product table. as does the product_id (which already existed) product_id is in the table but still cant get manufacturer_ref !

Try adding the path to your openerp-server.conf -c ./openerp-server.conf and --addons=path to your addons folder

column manufacturer_ref or manufacturer_pref ?

Tác giả

Pref indeed. Typo. Will try it later on and let you know

Tác giả

The problem realy is with my line :

'manufacturer_pref': fields.related('order_line','product_id','manufacturer_pref', type='char', relation='product.product', string='Manufacturer'),

as I have added a 'test': fields.text('Test'), and it was added to the table.

Tác giả

Lets see it that way.

In my table purchase order line, I would like to add a column for both, the manufacturer name (manufacturer_pname) and manufacturer code(manufacturer_pref). those 2 are fields of product wich are located in product.product table.

in the table purchase.order.line, I have the field product_id which is related to my product id in product.product table

'product_id': fields.many2one('product.product', 'Product', domain=[('purchase_ok','=',True)], change_default=True),

so, I would I get those 2 fields from that product.product table into purchase.order.line table ?

Tác giả

That line did not work, in fact, my column manufacturer_pref that I had in the purchase_order_line is gone.

Tác giả

when related, the column gets deleted from table.

changed it to 'manufacturer_pref': fields.many2one('order_line','manufacturer_pref', type='char', relation='product.product'), removing string='Manufacturer' has it gives an error, brings the column back in the table but, there is no data in it even tho I do have order lines with product that do hve manufacturer code (manufacturer_pref)

store = True

Tác giả

still nothing

Could you post the new code ?

Tác giả

removed the extra stuff:

columns = {

    'name': fields.text('Description', required=True),

'product_id': fields.many2one('product.product', 'Product', domain=[('purchase_ok','=',True)], change_default=True),

'manufacturer_pref': fields.many2one('purchase.order.line','manufacturer_pref', type='char', relation='product.product', store=True),
   'manufacturer_pref': fields.many2one('product.product','manufacturer_pref', type='char', string='Manufacturer'),
Tác giả

Will try this tomorrow

Tác giả

Tried your line, no go, went back the related field type path, got the column to create itself but, still no value in the column:

'manufacturer_pref': fields.related('manufacturer_pref', type="char", relation="product.product", string="Manufacturer", store=True),
Tác giả

Got it, was missing the first reference order_id:

'manufacturer_pref': fields.related('product_id', 'manufacturer_pref', type="char", relation="product.product", string="Manufacturer", store=True),
Tác giả Câu trả lời hay nhất

solved it: the line needed was :

'manufacturer_pref': fields.related('product_id', 'manufacturer_pref', type="char", relation="product.product", string="Manufacturer", store=True),
Ảnh đại diện
Huỷ bỏ