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.

44 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 openerp import models, fields, api
  4. class AccountMove(models.Model):
  5. _inherit = 'account.move'
  6. move_type = fields.Selection(
  7. string="Move type", selection=[
  8. ('other', 'Other'),
  9. ('liquidity', 'Liquidity'),
  10. ('receivable', 'Receivable'),
  11. ('receivable_refund', 'Receivable refund'),
  12. ('payable', 'Payable'),
  13. ('payable_refund', 'Payable refund'),
  14. ], compute='_compute_move_type', store=True, readonly=True)
  15. @api.multi
  16. @api.depends(
  17. 'line_ids.account_id.internal_type', 'line_ids.balance',
  18. 'line_ids.account_id.user_type_id.type'
  19. )
  20. def _compute_move_type(self):
  21. def _balance_get(line_ids, internal_type):
  22. return sum(line_ids.filtered(
  23. lambda x: x.account_id.internal_type == internal_type).mapped(
  24. 'balance'))
  25. for move in self:
  26. internal_types = move.line_ids.mapped('account_id.internal_type')
  27. if 'liquidity' in internal_types:
  28. move.move_type = 'liquidity'
  29. elif 'payable' in internal_types:
  30. balance = _balance_get(move.line_ids, 'payable')
  31. move.move_type = (
  32. 'payable' if balance < 0 else 'payable_refund')
  33. elif 'receivable' in internal_types:
  34. balance = _balance_get(move.line_ids, 'receivable')
  35. move.move_type = (
  36. 'receivable' if balance > 0 else 'receivable_refund')
  37. else:
  38. move.move_type = 'other'