Skip to Content
Menu
This question has been flagged
5 Replies
42018 Views

I am getting this following error

The operation cannot be completed: another model requires the record being deleted. If possible, archive it instead. Model: product.enquiry (product.enquiry), Constraint: product_enquiry_product_id_fkey

# Product Enquiry Model
class ProductEnquiryModel(models.Model):
    _name = "product.enquiry"

    def name_get(self):
        result = []
        for enquiry in self:
            result.append((enquiry.user_id.id, enquiry.user_id.farmer_name))
            
        return result

    product_id = fields.Many2one("retailer.products"string = "Product ID")
    member_id = fields.Char(string = "Member ID"required=True)
    enquired_at = fields.Datetime('Enquired At'readonly=True)
    retailer_id = fields.Many2one("res.partner.retailer"string = "Retailer")


# Retailer Products Model
class RetailerProductsModel(models.Model):
    _name = "retailer.products"
    
    def name_get(self):
        result = []
        for product in self:
            result.append((product.product_id.id, product.product_id.name))
            
        return result

    @api.onchange('product_id')
    def getProductInfo(self):
        if self.product_id:
            self.category_id = self.product_id.categ_id
            self.sub_category_id = self.product_id.sub_category_id
            self.selling_price = self.product_id.list_price
            self.name = self.product_id.name
    
    @api.model
    def create(selfvals):
        if 'is_offer' in vals and vals['is_offer'] == True:
            offers = self.env['product.offers'].create({
                'name': vals['offer_type'],
                'value': vals['value'],
                'offer_type': vals['offer_type'],
            })
            vals['offer_id'] = offers.id
            
        result = super(RetailerProductsModel, self).create(vals)
        return result

    name = fields.Char("Product Name")
    retailer_id = fields.Many2one("res.partner.retailer"string = "Retailer")
    product_id = fields.Many2one("product.template"string = "Product"ondelete='cascade', )
    is_offer = fields.Boolean(string = "Offer")
    offer_id = fields.Many2one("product.offers"string = "Offer")
    selling_price = fields.Float("Price")
    min_qty = fields.Integer("Minimum Quantity")
    max_qty = fields.Integer("MaximumQuantity")
    category_id = fields.Many2one("product.category"string = "Product Category"required=True)
    sub_category_id = fields.Many2one("product.sub.category"string="Product Sub Category")
    offer_type = fields.Selection([
        ('flat_discount''Flat Discount'),
        ('percentage''Percentage'),
        ],
        'Offer Type')
    value = fields.Float(string="Value")
    retailer_product_multilingual_ids = fields.One2many('product.master.multilingual''retailer_product_multilingual_id'string='Data for Multilingual')

    

Avatar
Discard
Best Answer

here is the example :



Avatar
Discard
Best Answer

Not Related to This Question but l had same problem too

In my case it was caused by calling a Many2one field and passing a value id which is not available in the Many2one table on create function, ie

self.env['claims_payments.model'].create({
'product_id':6,
'claim_pay_qoute':repaires_qoutes,
})

Therefore look around if you not passing a value which is not in a database you are referring to.

Avatar
Discard
Best Answer

Hi Selva KD ,

Have you solved this issue?

The problem that I had was because I didn't update the module before using the fields.


Avatar
Discard
Best Answer

Hi,

You are creating the model "product.offers" in your create function,

I hope the error is because , data for  some mandatory field or fileds in model product.offers  is not being passed in def create function

Check  for the required=True fields in model product.offers  and check whether you have passed the data in your create function.

Hope it helps

Thanks

Avatar
Discard
Best Answer

The error already told the cause: There are some records which has fields linked to the record you are trying to delete. Just find them and unlink, or as Odoo suggest, you archive it instead of delete the record.

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 23
1182
2
Jan 25
2289
1
Dec 24
6002
1
Nov 24
2424
1
Nov 24
1820