콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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

아바타
취소
작성자 베스트 답변

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
아바타
취소
관련 게시물 답글 화면 활동
0
6월 25
587
3
2월 25
3046
1
11월 24
2855
1
12월 23
2687
1
4월 21
7834