Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged

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
Opusti
Avtor Best Answer

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
Opusti
Related Posts Odgovori Prikazi Aktivnost
0
jun. 25
587
3
feb. 25
3046
1
nov. 24
2855
1
dec. 23
2687
1
apr. 21
7834