This question has been flagged
1 Reply
130 Views

Hello, I am asking for your help again and I would appreciate it:

I am developing a module of my own, where I have a model that stores the price per pound, date and type of cattle. 


I have another model that is the main one, in which are all the attributes of the cattle. In this one I calculate the amount of each cattle according to the most recent weight and price per pound, here I condition this calculation to be according to the type of cattle that is registered and that it is equal to the type of cattle of the associated price per pound. 

When entering a new price per pound for each cattle, the amount is not calculated automatically in all the records.

But if I enter a new weight record for each carcass, the amount is calculated correctly taking the most recent price per pounds record and making the correct calculation.


Another detail, the type of cattle I inherit it in the price per pound model of my main model with a realated, like this: type_cow = fields.Selection(related='cow_id.type_cow', string=“Type of cattle”, readonly=False, store=True, required=True), so it would be. 


and in my main model the condition to search the price per pound according to the type of cattle is: price_actually_record = self.env['price.pound'].search([('type_cow', '=', record.type_cow)], order='date_pound desc', limit=1). here then i do u if and if there is any record with such condition it does the multiplication, otherwise price_total is zero.

Avatar
Discard
Best Answer

Hi,
In the write or create method of the pricing model, you have to forcefully re trigger the computation of the existing records.

Thanks

Avatar
Discard