stock_inventory.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 Mikel Arregi Etxaniz - AvanzOSC
  3. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  4. from openerp import api, fields, models
  5. class StockInventory(models.Model):
  6. _inherit = "stock.inventory"
  7. inventory_lines_count = fields.Integer(
  8. string="Lines count", compute="_compute_inventory_lines_count")
  9. @api.multi
  10. def _compute_inventory_lines_count(self):
  11. lines_obj = self.env['stock.inventory.line']
  12. for inventory in self:
  13. inventory.inventory_lines_count = lines_obj.search_count([
  14. ('inventory_id', '=', inventory.id)])
  15. @api.multi
  16. def action_open_inventory_lines(self):
  17. template_obj = self.env['product.template']
  18. result = template_obj._get_act_window_dict(
  19. 'stock_inventory_line_menu.action_inventory_line')
  20. result['domain'] = "[('inventory_id', '=', %d)]" % self.id
  21. result['context'] = {'search_default_internal_loc': 1}
  22. return result
  23. class StockInventoryLine(models.Model):
  24. _inherit = "stock.inventory.line"
  25. date = fields.Datetime(string="Date", related="inventory_id.date",
  26. store=True)
  27. adjust_qty = fields.Float(string="Diferencia", compute="_compute_adjust_qty", store=True)
  28. @api.depends("product_qty", "theoretical_qty")
  29. def _compute_adjust_qty(self):
  30. for record in self:
  31. record.update({
  32. 'adjust_qty' : record.product_qty - record.theoretical_qty,
  33. # record.adjust_qty = adjust_qty
  34. })