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

I need to make the VAT (TIN) field from res.partner available in account.invoice, so I can add it to the Invoice Tree View. How can I achieve this?



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

You have to customize one small module to make it visible to invoice, for more info contact@tidyway.in

Tác giả

I know how to create a module, I just need to know what to inherit exactly...in order to pass the field data from one model to another

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

Hi,

You can inherit account.invoice object and add a functional field.

Try like this:

in .py file:

from openerp.osv import fields, osv
class account_invoice(osv.osv):
 
    _inherit = "account.invoice"
    
    def _get_vat_num(self, cr, uid, ids,field_name, args, context=None):
        
        partner_pool = self.pool.get('res.partner')
        invoice_pool = self.pool.get('account.invoice')
        res = {}
        for inv_id in self.browse(cr, uid, ids, context=context):
            invoice = invoice_pool.browse(cr,uid, inv_id.id, context=None)
            partner = partner_pool.browse(cr, uid, invoice.partner_id.id, context=None)
            res[inv_id.id] = partner.vat
        
        return res 
    
    _columns = {
                
                'inv_vat': fields.function(_get_vat_num, string="VAT", type='char', method=True)  
                 }


in .xml file:

<openerp>
    <data>
        <record id="invoice_form_inherit" model="ir.ui.view">
    		<field name="name">invoice.form.inherit</field>
    		<field name="model">account.invoice</field>
    		<field name="inherit_id" ref="account.invoice_form"/>
    		<field name="arch" type="xml">
    		    <field name="partner_id" position="after">
    		    	
                                    <field name="inv_vat"/>
    		    </field>
    		</field>
		</record>
            
    </data>
</openerp>

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

Thanks Akhil! and sorry for my late response, I was busy and hadn't been able to try it till now. That's exactly what I was looking for, I just changed the view code to tree instead of form, and it worked. Thanks again for the detailed response.

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

Hello,

May be this will help full to you.

Inherit account.account.

Add one functional field in account.account which fetch value from res.partner because partner_id is already present in account.account.

Thanks.

Shamji.

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

Thanks Solanki.

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

Function fields are deprecated in api v10, now should be

inv_vat = fields.Char(string="VAT", compute="_get_vat_num")
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi, Im trying to port this solution to odoo 10, but the module gives this error when installing, any ideas?:

AttributeError: 'module' object has no attribute 'function'
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 22
2954
1
thg 4 19
4002
0
thg 3 15
3928
3
thg 3 15
4685
3
thg 11 24
3320