콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
11109 화면

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
아바타
취소
작성자

Thanks a lot

베스트 답변

hello

make the super call your create method and then after call your method.

@api.model

def create(self, vals):

    res = super(classname, self).create(vals)

    res.update_stock_value() # call your method

    return res

아바타
취소
베스트 답변
Hello Mohamed,
use @api.multi instead of @api.one
you are using @api.depends('qty'), it means this method will call whenever the qty change on stock quant
아바타
취소
관련 게시물 답글 화면 활동
2
5월 21
7930
2
3월 24
11234
5
9월 20
5752
1
12월 19
9066
1
2월 24
6093