stock_inventory_adjustment_name.py 1015 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models, _
  4. class StockInventoryAdjustmentName(models.TransientModel):
  5. _name = 'stock.inventory.adjustment.name'
  6. _description = 'Inventory Adjustment Reference / Reason'
  7. def default_get(self, fields_list):
  8. res = super().default_get(fields_list)
  9. if self.env.context.get('default_quant_ids'):
  10. quants = self.env['stock.quant'].browse(self.env.context['default_quant_ids'])
  11. res['show_info'] = any(not quant.inventory_quantity_set for quant in quants)
  12. return res
  13. quant_ids = fields.Many2many('stock.quant')
  14. inventory_adjustment_name = fields.Char(default="Quantity Updated")
  15. show_info = fields.Boolean('Show warning')
  16. def action_apply(self):
  17. quants = self.quant_ids.filtered('inventory_quantity_set')
  18. return quants.with_context(inventory_name=self.inventory_adjustment_name).action_apply_inventory()