You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.7 KiB

  1. # Copyright (C) 2018 - TODAY, Open Source Integrators
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class Agreement(models.Model):
  5. _inherit = "agreement"
  6. picking_count = fields.Integer('# Pickings',
  7. compute='_compute_picking_count')
  8. move_count = fields.Integer('# Moves', compute='_compute_move_count')
  9. lot_count = fields.Integer('# Lots/Serials', compute='_compute_lot_count')
  10. @api.multi
  11. def _compute_picking_count(self):
  12. data = self.env['stock.picking'].read_group(
  13. [('agreement_id', 'in', self.ids)],
  14. ['agreement_id'], ['agreement_id'])
  15. count_data = dict((item['agreement_id'][0],
  16. item['agreement_id_count']) for item in data)
  17. for agreement in self:
  18. agreement.picking_count = count_data.get(agreement.id, 0)
  19. @api.multi
  20. def _compute_move_count(self):
  21. data = self.env['stock.move'].read_group(
  22. [('agreement_id', 'in', self.ids)],
  23. ['agreement_id'], ['agreement_id'])
  24. count_data = dict((item['agreement_id'][0],
  25. item['agreement_id_count']) for item in data)
  26. for agreement in self:
  27. agreement.move_count = count_data.get(agreement.id, 0)
  28. @api.multi
  29. def _compute_lot_count(self):
  30. data = self.env['stock.production.lot'].read_group(
  31. [('agreement_id', 'in', self.ids)],
  32. ['agreement_id'], ['agreement_id'])
  33. count_data = dict((item['agreement_id'][0],
  34. item['agreement_id_count']) for item in data)
  35. for agreement in self:
  36. agreement.lot_count = count_data.get(agreement.id, 0)