Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4878 มุมมอง

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 ?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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'),
อวตาร
ละทิ้ง
ผู้เขียน

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 !

ผู้เขียน

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 ?

ผู้เขียน

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

ผู้เขียน

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.

ผู้เขียน

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 ?

ผู้เขียน

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

ผู้เขียน

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

ผู้เขียน

still nothing

Could you post the new code ?

ผู้เขียน

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'),
ผู้เขียน

Will try this tomorrow

ผู้เขียน

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),
ผู้เขียน

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),
ผู้เขียน คำตอบที่ดีที่สุด

solved it: the line needed was :

'manufacturer_pref': fields.related('product_id', 'manufacturer_pref', type="char", relation="product.product", string="Manufacturer", store=True),
อวตาร
ละทิ้ง