Em 27/02/2014 08:50, Cédric Krier escreveu:
On 27 Feb 08:43, Iasmini - Gmail wrote:
Hi,
I need to do something just before saving. I did this:
class Invoice:
__name__ = 'account.invoice'
...
def save(self):
if self.rps_number == '':
if not self.create_rps_number():
self.raise_user_error(u'xxxx!')
super(Invoice, self).save()
But this function is not called. Why?
Because save is a recent method added for syntactic sugar and so it is
not always (almost never) called.
I think what you are looking for is the validate method:
http://doc.tryton.org/3.0/trytond/doc/ref/models/models.html?highlight=validate#trytond.model.ModelStorage.validate
I did on validate(). I'm setting the value of the field numero_rps with
the created numero_rps by method gera_numero_rps() called on validate().
But on invoice this field is getting null after saving. Why? Save method
is called after validate(), right?
I tried with self and with invoice (putting @staticmethod before function).
Here is the code:
class Invoice:
...
@classmethod
def validate(cls, invoices):
super(Invoice, cls).validate(invoices)
# gera número do rps antes de salvar
for invoice in invoices:
if invoice.numero_rps == '' or invoice.numero_rps == None:
if not invoice.gera_numero_rps():
invoice.raise_user_error(u'xxx!')
def gera_numero_rps(self):
go_on = True
try:
NumeracaoRPS = Pool().get('nfse_br.numeracao_rps')
numeracao_rps = NumeracaoRPS.search([
('tipo_rps', '=', self.tipo_rps),
('serie_rps', '=', self.serie),
('company', '=', self.company)])
if numeracao_rps:
numeracao_rps[0].ultimo_numero_rps +=
numeracao_rps[0].ultimo_numero_rps
NumeracaoRPS.write(numeracao_rps, {
'ultimo_numero_rps':
numeracao_rps[0].ultimo_numero_rps})
else:
go_on = False
self.raise_user_error(u'Deve ser criada a numeração do
RPS de acordo com o tipo do RPS, série e'
u' emitente da NFS-e antes de
processar!')
return
self.numero_rps = str(numeracao_rps[0].ultimo_numero_rps)
except:
go_on = False
raise
return go_on
Here
self.numero_rps = str(numeracao_rps[0].ultimo_numero_rps)
I'm setting invoice.numero_rps, but in database is null. I traced and
it's > 0.
--
Iasmini Gomes
Sílex Sistemas
www.silexsistemas.com.br
---
Este email está limpo de vírus e malwares porque a proteção do avast! Antivírus
está ativa.
http://www.avast.com