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.

49 lines
1.7 KiB

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