跳至内容
菜单
此问题已终结
5 回复
42467 查看

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

    

形象
丢弃
最佳答案

here is the example :



形象
丢弃
最佳答案

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.

形象
丢弃
最佳答案

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.


形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
1
7月 23
1218
0
5月 25
11
2
1月 25
2415
1
12月 24
6116
1
11月 24
2556