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.

72 lines
2.8 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2013 Therp BV (<http://therp.nl>).
  5. #
  6. # All Rights Reserved
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.osv import orm
  23. class ResPartner(orm.Model):
  24. _inherit = 'res.partner'
  25. def def_journal_account_bank(
  26. self, cr, uid, ids, get_property_account, context=None):
  27. """
  28. Returns the property journal account for the given partners ids.
  29. :param get_property_account: method of this object that takes
  30. a partner browse record and returns a field name of type many2one.
  31. """
  32. if not ids:
  33. return {}
  34. res = dict([(res_id, False) for res_id in ids])
  35. for partner in self.browse(cr, uid, ids, context=context):
  36. property_account = get_property_account(partner)
  37. if partner[property_account]:
  38. res[partner.id] = partner[property_account].id
  39. return res
  40. def get_property_account_decrease(self, partner):
  41. if partner.customer and not partner.supplier:
  42. return 'property_account_receivable'
  43. return 'property_account_payable'
  44. def get_property_account_increase(self, partner):
  45. if partner.supplier and not partner.customer:
  46. return 'property_account_payable'
  47. return 'property_account_receivable'
  48. def def_journal_account_bank_decr(
  49. self, cr, uid, ids, context=None):
  50. """
  51. Return the default journal account to be used for this partner
  52. in the case of bank transactions that decrease the balance.
  53. """
  54. return self.def_journal_account_bank(
  55. cr, uid, ids, self.get_property_account_decrease, context=context)
  56. def def_journal_account_bank_incr(
  57. self, cr, uid, ids, context=None):
  58. """
  59. Return the default journal account to be used for this partner
  60. in the case of bank transactions that increase the balance.
  61. """
  62. return self.def_journal_account_bank(
  63. cr, uid, ids, self.get_property_account_increase, context=context)