Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
42027 Lượt xem

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')

    

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

here is the example :



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 23
1182
2
thg 1 25
2290
1
thg 12 24
6006
1
thg 11 24
2426
1
thg 11 24
1822