Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i call my method after create new object in odoo 10?

I'm using odoo 10 i inherited from module stock.quant i add a new attribute and a new method. i want my method execute after each creating a new object in stock.quant. This is my code Thanks for help

class stock_quant(models.Model):
    _inherit = 'stock.quant'
    inventory_value_charge = fields.Float('Total Value',store=True,compute='update_stock_value')

    @api.one
    @api.depends('qty')
    def update_stock_value(self):
        stock_price_obj = self.env['stock.price.partition'].search([('id', '!=', False)])
        val_obj = stock_price_obj.search([('reception.pack_operation_product_ids.pack_lot_ids.lot_id.id', '=', self.lot_id.id)])
        if val_obj!= False:
            val_obj.calccule_price()
        else:
            self.inventory_value_charge=self.inventory_value
        #stock_price_obj = self.env['stock.price.partition'].search([('reception.pack_operation_product_ids.pack_lot_ids.lot_id.id', '=', self.lot_id.id)])
        return True

    @api.model
    def create(self, vals):
        res = super(stock_quant, self).create(vals)
        self.update_stock_value()
        return res
like image 425
MOHAMED Avatar asked Oct 20 '25 07:10

MOHAMED


1 Answers

First of all the field is computed you don't have to call the method because it's allready called in the process of create call. and in write call too but only if you change the qty field.

So remove the create method you are just calling it for the second time.

Now make sure that your method is called by adding some print calls if you don't know how to use debug in you IDE.

Make sure you import the module in your __init__ files.

like image 62
Charif DZ Avatar answered Oct 22 '25 21:10

Charif DZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!