2016-06-16 7 views
0

Ich möchte die alte API-Funktion von hr_attendance in der neuen API der Funktion unlink() aufrufen.wie alte API-Funktion in der neuen API-Funktion aufgerufen wird (unlink)?

Mein alter api-Code ist:

def _altern_si_so(self, cr, uid, ids, context=None): 

for att in self.browse(cr, uid, ids, context=context): 

prev_att_ids = self.search(cr, uid, [('employee_id', '=',att.employee_id.id), ('name', '<', att.name),('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name DESC') 

next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name),('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name ASC') 

prev_atts = self.browse(cr, uid, prev_att_ids, context=context) 

next_atts = self.browse(cr, uid, next_add_ids, context=context) 

if prev_atts and prev_atts[0].action == att.action: 

x = self.write(cr, uid, ids, {'text': "Previous Action Is Not Valid?"}) 

return self.write(cr, uid, ids, {'state': True}), x 

if prev_atts and prev_atts[0].action != att.action and next_atts and next_atts[0].action != att.action: 

a = self.write(cr, uid, ids, {'state': False}) 

c = self.write(cr, uid, next_add_ids, {'state': False}) 

xx = self.write(cr, uid, next_add_ids, {'text': "Everything seems OK!"}) 

d = self.write(cr, uid, ids, {'text': "Everything seems OK!"}) 

return self.write(cr, uid, prev_att_ids, {'state': False}), a, c, xx, d 

if next_atts and next_atts[0].action == att.action: # next exists and is same action 

y = self.write(cr, uid, ids, {'text': "Next Action Is Not Valid?"}) 

return self.write(cr, uid, ids, {'state': True}), y 

if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in 

z = self.write(cr, uid, ids, {'text': "First Action Should be Sign In!"}) 

return self.write(cr, uid, ids, {'state': True}), z 

else: 

zz = self.write(cr, uid, ids, {'text': "Everything seems OK!"}) 

return self.write(cr, uid, ids, {'state': False}), zz 

return True 

_constraints = [(_altern_si_so, 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])] 

Dieser Funktionsaufruf durch eine Beschränkung ist. Diese Funktion wird während der Validierung der importierten Daten aufgerufen.

Ich möchte diese Funktion in unlink() aufgerufen werden, so dass, wenn Löschaktion in ORM durchgeführt wird die oben genannte alte API-Funktion aufgerufen werden sollte.

Wie kann ich diese alte api Funktion in dieser neuen api fuction

@api.multi 
def unlink(self): 
#how to call the old api here 
return models.Model.unlink(self) 

Wie kann ich das erreichen nennen?

Dank

Antwort

0

versuchen auf diese Weise:

Pass self._cr,self._uid,self.ids,self._context wie unten

class product_attribute(models.Model): 
    _inherit = "product.attribute" 
    @api.multi 
    def unlink(self): 
     res= super(product_attribute,self).unlink()   
     #do your code 
     return res 

In Bezug auf alten api Methode aufrufen (die jetzt mit @ api.multi dekoriert).

method_name (self._cr, self._uid, self.ids, self._context)

Hoffe, dass es in Ihrem Fall helfen können.

+0

Ich habe diesen Code hinzugefügt „Klasse löschen (models.Model): _inherit = "hr.attendnace" @ api.multi def entkoppeln (Selbst-): res = Super (hr_attendance, Selbst-) .unlink() _altern_si_so (self, self._cr, self._uid, self._ids, kontext = Keine) #do dein code return res " aber es zeigt fehler im methodennamen" _altern_si_so "rufe ich die methode richtig oder ich habe ein paar Fehler gemacht. – sathish

+0

als unlink return True/False, so dass Sie keine Methode (_altern_si_so) über res aufrufen können, rufen Sie iterating self auf – prakash

Verwandte Themen