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

I would like to add new column to the table account_invoice

I tried using:

from openerp import fields  as fieldss

    product_id= fieldss.related('order_line', 'product_id', type='many2one', relation='product.product', string='Product'),

the purpose:  add product in the view account invoice view search  <record id="view_account_invoice_filter" model="ir.ui.view">

 

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

There could be more than one product in the invoice line which product you want to store in the account.invoice. If you just want to search the product in accout.invoice then look in to sale.order model for reference, which includes product_id as a related field.

Tác giả

Yes I want to search product on account.invoice but the the account module is writen in differnet APÏ

May I know, what you exactly want to get as value in that column "name_product"

Tác giả

I updated my question

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

Try this

from openerp import models,fields,api

class account_invoice_ext(models.Model):
        _inherit = 'account.invoice'

product_id=fields.Many2one("product.product",related="invoice_line.product_id",string="Product")
    
 

Your xml file

 

        <record id="view_account_invoice_filter_inherit" model="ir.ui.view">
            <field name="name">account.invoice.inherit.select</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.view_account_invoice_filter"/>
            <field name="arch" type="xml">
                <field name="period_id" position="after">
                    <field name="product_id"/>
                </field>
             </field>
         </record>

Hope this helps !!.

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

I got : File "/opt/odoo/odoo/openerp/models.py", line 1276, in _validate_fields raise ValidationError('\n'.join(errors)) ParseError: "ValidateError Field(s) `arch` failed against a constraint: Invalid view definition Error details: Field `product_id` does not exist

Tác giả

I tried it in different DB same result

Did you updated the module? I have tried this, it working perfectly. Did you restarted the server and updated the module?

Tác giả

your code apair perfect, I update & unistalled & installed the module I get that error. The field doesn't create a column in the DataBase !!!!!

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 11 23
3371
1
thg 10 22
4039
2
thg 3 21
2572
1
thg 3 15
6104
1
thg 3 15
7015