stock_package_destination.py 1.3 KB

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models
  4. class ChooseDestinationLocation(models.TransientModel):
  5. _name = 'stock.package.destination'
  6. _description = 'Stock Package Destination'
  7. picking_id = fields.Many2one('stock.picking', required=True)
  8. move_line_ids = fields.Many2many('stock.move.line', 'Products', compute='_compute_move_line_ids', required=True)
  9. location_dest_id = fields.Many2one('stock.location', 'Destination location', required=True)
  10. filtered_location = fields.One2many(comodel_name='stock.location', compute='_filter_location')
  11. @api.depends('picking_id')
  12. def _compute_move_line_ids(self):
  13. for destination in self:
  14. destination.move_line_ids = destination.picking_id.move_line_ids.filtered(lambda l: l.qty_done > 0 and not l.result_package_id)
  15. @api.depends('move_line_ids')
  16. def _filter_location(self):
  17. for destination in self:
  18. destination.filtered_location = destination.move_line_ids.mapped('location_dest_id')
  19. def action_done(self):
  20. # set the same location on each move line and pass again in action_put_in_pack
  21. self.move_line_ids.location_dest_id = self.location_dest_id
  22. return self.picking_id.action_put_in_pack()