Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

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
Buang
Penulis Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
0
Jun 25
586
3
Feb 25
3040
1
Nov 24
2847
1
Des 23
2683
1
Apr 21
7827