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

Hi, i am a newbie in odoo programming. I got this warning when creating  a One2many field relation, where I took the data from the Many2one field in the same model. 

Here is my custom code:

class ReferInherit(models.Model):
_inherit = 'qc.inspection'

reference_line = fields.One2many('qc.inspection', 'picking', readonly=False, store=True)

and I took the data from here:

class QcInspection(models.Model):
_inherit = 'qc.inspection'

@api.multi
@api.depends('object_id')
def _compute_picking(self):
for inspection in self:
inspection.picking = False
if inspection.object_id:
if inspection.object_id._name == 'stock.move':
inspection.picking = inspection.object_id.picking_id
elif inspection.object_id._name == 'stock.picking':
inspection.picking = inspection.object_id
elif inspection.object_id._name == 'stock.pack.operation':
inspection.picking = inspection.object_id.picking_id
    picking = fields.Many2one(comodel_name="stock.picking", compute="_compute_picking", store=True)

When I run it, I got this Warning:

The operation cannot be completed: another model requires the record being deleted. If possible, archive it instead.
Model: Quality control inspection (qc.inspection), Constraint: qc_inspection_picking_fkey

what's wrong with my code? and how to solve it? Sorry for my bad english and Thanks before.


الصورة الرمزية
إهمال
الكاتب

Hi, Kanakinfosystems

Thanks for your answer.

This is very helpful. Your answer is so inspiring for me. Thanks a lot:)

أفضل إجابة

Hi Ahmad,

Please see below code example for correct implementation of One2many relational field.

class QcInspection(models.Model):
    _name = 'qc.inspection'

    line_ids = fields.One2many(comodel_name='qc.inspection.line', inverse_name='inspection_id', string='Lines')

class QcInspectionLine(models.Model):
   _name = 'qc.inspection.line'

   inspection_id = fields.Many2one('comodel_name='qc.inspection', string="Inspection", ondelet="cascade")

Note:  Inverse field should not be computed, as per your code you are trying to compute value of picking fields.

Thanks.


الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
ديسمبر 17
3774
1
يوليو 19
13324
0
أبريل 17
6462
1
مارس 23
1804
0
ديسمبر 22
2480