Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
3688 Visualizações

from odoo import api, fields, models
from odoo.exceptions import ValidationError


class InvoiceInh(models.Model):
_inherit = 'account.move.line'

@api.constrains('analytic_account_id')
def check_account(self):
for line in self:
if not line.analytic_account_id:
raise ValidationError('Analytic Account field in the products tab is missing.'
' Please enter it to be able to continue.')
When the required field (analytic account) field filled out, it still raises the validation error. anyone know why? what are the alternatives?

Note: does not give proper message if made from front end with required>1<


Regards,

Adel

Avatar
Cancelar
Autor Melhor resposta

from odoo import api, fields, models
from odoo.exceptions import ValidationError


class InvoiceInh(models.Model):
_inherit = 'account.move'

def action_post(self):

for line in self.invoice_line_ids:
if not line.analytic_account_id:
raise ValidationError('Analytic Account field in the products tab is missing.'
' Please enter it to be able to continue.')
A work-around solution is to add validation code on the 'post' button. Achieved through inheriting that function.

from odoo import models
from odoo.exceptions import ValidationError


class ValidateAccountMove(models.TransientModel):
_inherit = 'validate.account.move'

def validate_move(self):
res = super(ValidateAccountMove, self).validate_move()

active_ids = self._context.get('active_ids')
moves = self.env['account.move'].browse(active_ids)
for line in moves.invoice_line_ids:
if not line.analytic_account_id:
raise ValidationError('Analytic Account field in the products tab is missing.'
' Please enter it to be able to continue.')
return res
Also this should be added to prevent posting from accounting dashboard using action->post entries
Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
0
jun. 25
586
3
fev. 25
3045
1
nov. 24
2855
1
dez. 23
2686
1
abr. 21
7833