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.

45 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import models, fields, api
  5. class AccountMove(models.Model):
  6. _inherit = 'account.move'
  7. move_type = fields.Selection(
  8. string="Move type", selection=[
  9. ('other', 'Other'),
  10. ('liquidity', 'Liquidity'),
  11. ('receivable', 'Receivable'),
  12. ('receivable_refund', 'Receivable refund'),
  13. ('payable', 'Payable'),
  14. ('payable_refund', 'Payable refund'),
  15. ], compute='_compute_move_type', store=True, readonly=True)
  16. @api.multi
  17. @api.depends(
  18. 'line_ids.account_id.internal_type', 'line_ids.balance',
  19. 'line_ids.account_id.user_type_id.type'
  20. )
  21. def _compute_move_type(self):
  22. def _balance_get(line_ids, internal_type):
  23. return sum(line_ids.filtered(
  24. lambda x: x.account_id.internal_type == internal_type).mapped(
  25. 'balance'))
  26. for move in self:
  27. internal_types = move.line_ids.mapped('account_id.internal_type')
  28. if 'liquidity' in internal_types:
  29. move.move_type = 'liquidity'
  30. elif 'payable' in internal_types:
  31. balance = _balance_get(move.line_ids, 'payable')
  32. move.move_type = (
  33. 'payable' if balance < 0 else 'payable_refund')
  34. elif 'receivable' in internal_types:
  35. balance = _balance_get(move.line_ids, 'receivable')
  36. move.move_type = (
  37. 'receivable' if balance > 0 else 'receivable_refund')
  38. else:
  39. move.move_type = 'other'