تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
3696 أدوات العرض

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
يونيو 25
587
3
فبراير 25
3046
1
نوفمبر 24
2855
1
ديسمبر 23
2687
1
أبريل 21
7834