res_partner.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. class res_partner(models.Model):
  4. _inherit= 'res.partner'
  5. total_debt_paid = fields.Float('Cobros Realizados:', compute='_compute_total_debt_paid', store=False)
  6. total_payment = fields.Float('Pagos Realizados:',compute='_compute_total_payment', store=False)
  7. debt_paid_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '!=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')])
  8. debt_pending_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')])
  9. payment_done_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '!=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'payable'), ('state', '!=', 'draft')])
  10. payment_pending_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'payable'), ('state', '!=', 'draft')])
  11. def _compute_total_debt_paid(self):
  12. res = {}
  13. for partner in self:
  14. suma = 0
  15. account = self.env['account.voucher'].search([('partner_id','=',partner.id),('type','=','receipt'),('state','=','posted')])
  16. for each in account:
  17. suma = suma + each.amount
  18. partner.total_debt_paid = suma
  19. res = partner.total_debt_paid
  20. return {'value': res}
  21. def _compute_total_payment(self):
  22. res = {}
  23. for partner in self:
  24. suma = 0
  25. account = self.env['account.voucher'].search([('partner_id','=',partner.id),('type','=','payment'),('state','=','posted')])
  26. for each in account:
  27. suma = suma + each.amount
  28. partner.total_payment = suma
  29. res = partner.total_payment
  30. return {'value': res}
  31. @api.model
  32. def get_debt_paid_ids(self, domain):
  33. data = []
  34. partner = self.env['res.partner'].search(domain)
  35. for each in partner.debt_paid_ids:
  36. print each
  37. data.append({
  38. 'journal_id': each.journal_id.name,
  39. 'ref' : each.ref,
  40. 'move_id': each.move_id.name,
  41. 'date_created': each.date_created,
  42. 'amount': each.credit,
  43. })
  44. return data
  45. @api.model
  46. def get_debt_pending_ids(self, domain):
  47. data = []
  48. partner = self.env['res.partner'].search(domain)
  49. for each in partner.debt_pending_ids:
  50. print each
  51. data.append({
  52. 'journal_id': each.journal_id.name,
  53. 'ref' : each.ref,
  54. 'move_id': each.move_id.name,
  55. 'date_maturity': each.date_maturity,
  56. 'amount': each.debit,
  57. })
  58. return data
  59. @api.model
  60. def get_payment_done_ids(self, domain):
  61. data = []
  62. partner = self.env['res.partner'].search(domain)
  63. for each in partner.payment_done_ids:
  64. print each
  65. data.append({
  66. 'journal_id': each.journal_id.name,
  67. 'ref' : each.ref,
  68. 'move_id': each.move_id.name,
  69. 'date_created': each.date_created,
  70. 'amount': each.credit,
  71. })
  72. return data
  73. @api.model
  74. def get_payment_pending_ids(self, domain):
  75. data = []
  76. partner = self.env['res.partner'].search(domain)
  77. for each in partner.payment_pending_ids:
  78. print each
  79. data.append({
  80. 'journal_id': each.journal_id.name,
  81. 'ref' : each.ref,
  82. 'move_id': each.move_id.name,
  83. 'date_maturity': each.date_maturity,
  84. 'amount': each.credit,
  85. })
  86. return data