Suppose I have a field called isbn
on stock_move
, this field is of Boolean
type, I can create a method, with domain filter, which will bring all the stock_move
objects, with ('isbn', '=', 'True'),
, and reflect that calculation on another field, like this:
@api.multi
@api.depends('stock_move')
def _compute_amount_total(self):
draft_orders = self.env['stock.move'].search([('isbn', '=', True)])
product_uom_qty = sum(draft_orders.mapped('product_uom_qty'))
for record in self:
record.total_isbn = product_uom_qty
So, by far, this is a nice approach, but now, suppose I want to do this, but not for ALL the stock_moves
in which the isbn
field is checked, but just for the stock_moves
I'm calling from let's say 4 Many2one
fields in a model, ie:
stock_move1 = fields.Many2one('stock.move', string="My Stock Move 1")
stock_move2 = fields.Many2one('stock.move', string="My Stock Move 2")
stock_move3 = fields.Many2one('stock.move', string="My Stock Move 3")
stock_move4 = fields.Many2one('stock.move', string="My Stock Move 4")
I can call the isbn
field on my model like this though:
stock_move1 = fields.Many2one('stock.move', string="My Stock Move 1")
isbn1 = fields.Boolean(string="ISBN 1", related="stock_move1.isbn")
stock_move2 = fields.Many2one('stock.move', string="My Stock Move 2")
isbn2 = fields.Boolean(string="ISBN 2", related="stock_move2.isbn")
stock_move3 = fields.Many2one('stock.move', string="My Stock Move 3")
isbn3 = fields.Boolean(string="ISBN 3", related="stock_move3.isbn")
stock_move4 = fields.Many2one('stock.move', string="My Stock Move 4")
isbn4 = fields.Boolean(string="ISBN 4", related="stock_move4.isbn")
This should bring them, but actually I don't want to show them or anything on my view, just read those 4 stock_moves
look for isbn = True
and sum product_uom_qty
on them.
I hope I've explained myself.
Any ideas on how this could be accomplished?