stock_warn_insufficient_qty.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 StockWarnInsufficientQty(models.AbstractModel):
  5. _name = 'stock.warn.insufficient.qty'
  6. _description = 'Warn Insufficient Quantity'
  7. product_id = fields.Many2one('product.product', 'Product', required=True)
  8. location_id = fields.Many2one('stock.location', 'Location', domain="[('usage', '=', 'internal')]", required=True)
  9. quant_ids = fields.Many2many('stock.quant', compute='_compute_quant_ids')
  10. quantity = fields.Float(string="Quantity", required=True)
  11. product_uom_name = fields.Char("Unit of Measure", required=True)
  12. def _get_reference_document_company_id(self):
  13. raise NotImplementedError()
  14. @api.depends('product_id')
  15. def _compute_quant_ids(self):
  16. for quantity in self:
  17. quantity.quant_ids = self.env['stock.quant'].search([
  18. ('product_id', '=', quantity.product_id.id),
  19. ('location_id.usage', '=', 'internal'),
  20. ('company_id', '=', quantity._get_reference_document_company_id().id)
  21. ])
  22. def action_done(self):
  23. raise NotImplementedError()
  24. class StockWarnInsufficientQtyScrap(models.TransientModel):
  25. _name = 'stock.warn.insufficient.qty.scrap'
  26. _inherit = 'stock.warn.insufficient.qty'
  27. _description = 'Warn Insufficient Scrap Quantity'
  28. scrap_id = fields.Many2one('stock.scrap', 'Scrap')
  29. def _get_reference_document_company_id(self):
  30. return self.scrap_id.company_id
  31. def action_done(self):
  32. return self.scrap_id.do_scrap()
  33. def action_cancel(self):
  34. # FIXME in master: we should not have created the scrap in a first place
  35. if self.env.context.get('not_unlink_on_discard'):
  36. return True
  37. else:
  38. return self.scrap_id.sudo().unlink()