2016-10-10 2 views
0

나는 다음과 같은 OpenERP 7 방법이 : 나는 V8 구문을 Odoo 그것을 다시 작성해야OpenERP 7 방법을 Odoo 8 구문으로 다시 작성 하시겠습니까?

# Function to get the vat number (CIF/NIF) and then show it on invoice form view 
def _get_vat_num(self, cr, uid, ids, field_name, args=None, context=None): 
    partner_pool = self.pool.get('res.partner') 
    invoice_pool = self.pool.get('account.invoice') 
    res = {} 
    for inv in self.browse(cr, uid, ids, context=context): 
     invoice = invoice_pool.browse(cr,uid, inv.id, context=None) 
     partner = partner_pool.browse(cr, uid, invoice.partner_id.id, context=None) 
     res[inv.id] = partner.vat 

    return res 

inv_vat = fields.Char(compute='_get_vat_num', string="CIF/NIF") 

합니다. 시도했지만 작동하지 않습니다.

def _get_vat_num(self): 
    partner_pool = self.env['res.partner'] 
    invoice_pool = self.env['account.invoice'] 

    res = {} 
    for inv in self.browse(self.id): 
     invoice = invoice_pool.browse(inv.id) 
     partner = partner_pool.browse(invoice.partner_id.id) 
     res[inv.id] = partner.vat 

    return res 

올바른 코드는 무엇입니까?

+0

는 F 무엇입니까 에 대한 유감? 어떤 오류가 발생하고 있습니까? – alexbclay

+0

파이 사이드에서 해당 함수를 호출하는 방법은 무엇입니까? 우리는 odoo v8에 다른 데코레이터를 추가해야한다고 부름에 달려있다. –

답변

1

기능 필드를 설정하는 것처럼 보입니다.

inv_vat = fields.Char(string="VAT", related="partner_id.vat") 

당신이 정말로 기능 필드로 원하는 경우, 이것은 당신이 그것을 레코드를

inv_vat = fields.Char(string="VAT", compute="_get_vat_num") 

def _get_vat_num(self): 
    # self is a recordset of account.invoice records 
    for invoice in self: 
     # to set a functional field, you just assign it 
     invoice.inv_vat = invoice.partner_id.vat 

체크 아웃 할 것이다 방법이다 : 당신은 대신 related field 그래서 등과 같은 필드를 정의 할 수 있어야한다 문서 : https://www.odoo.com/documentation/8.0/reference/orm.html#recordsets

그리고 계산 된 필드 문서 : https://www.odoo.com/documentation/8.0/reference/orm.html#computed-fields

+0

Thanks @alexbclay. 이 필드는 일부 사람들을위한 추가 참조 용이기 때문에이 필드를 저장하려고하지 않습니다. 이런 이유로 계산 된 필드'inv_vat = fields.Char (compute = '_ get_vat_num', string = "CIF/NIF")'를 생성했습니다. 내 문제는 함수를 다시 작성하는 것입니다. 나는 너의 해결책을 시험해 보러 간다. –

+1

관련 항목을'store = False'로 시도해 보았습니다! 예제 기능을 이용해 주셔서 감사합니다. –

+0

문제 없습니다. 도움이 되니 기쁩니다! – alexbclay