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

hi. i have a one2many field on which there is a python constraint that a sum of one of its fields must match a certain value. on record creation it works fine. but when editing the record and deleting a row of the one2omany field the deleted row is still taken in the constraint. please help

Version is updated v14.0 Community

الصورة الرمزية
إهمال

We cannot help you until you share your code, specially constraint.

الكاتب

the code has grown quite large but ill try to compress:

class Order(models.Model):

order_line = fields.One2Many('order.line', ...

cost_center_line = fields.One2Many('cost_center_line', ...

amount_total = fields.Monetary(store=True, compute='_compute_amount')

amount_cost_center = fields.Monetary(store=True, compute='_compute_cost_center_amount')

@api.depends('order_line.price_total')

def _compute_amount(self):

for rec in self:

amount = 0.0

for line in rec.order_line:

amount += line.price_total

rec.amount_total = amount

@api.depends('cost_center_line.amount')

def _compute_cost_center_amount(self):

for rec in self:

amount = 0.0

for line in rec.cost_center_line:

amount += line.amount

rec.amount_cost_center = amount

@api.constrains('amount_total','amount_cost_center')

def _constrains_amount(self):

for rec in self:

if rec.amount_total != rec.amount.cost_center:

raise ValidationError('...')

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مارس 24
5357
1
نوفمبر 17
12372
1
يونيو 15
4945
0
يونيو 15
4919
3
مارس 15
5411