res_partner.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from openerp import api, fields, models
  2. from datetime import datetime, date, time, timedelta
  3. class ResPartner(models.Model):
  4. _inherit = 'res.partner'
  5. @api.model
  6. def get_partners(self):
  7. domain = [('customer', '=', True), ('active', '=', True), ('credit', '>', 0)]
  8. partners = []
  9. for customer in self.env['res.partner'].search(domain):
  10. categories = []
  11. invoices = []
  12. for category in customer.category_id:
  13. categories.append({
  14. 'id': category.id,
  15. 'name': category.name,
  16. 'display_name': category.display_name
  17. })
  18. for invoice in customer.invoice_ids:
  19. movelines = []
  20. for move in invoice.move_id:
  21. for moveline in move.line_id:
  22. if moveline.amount_residual > 0 and moveline.state != "draft":
  23. movelines.append({
  24. 'id': moveline.id,
  25. 'amount_residual': moveline.amount_residual,
  26. 'credit': moveline.credit,
  27. 'debit': moveline.debit,
  28. 'date_maturity': moveline.date_maturity
  29. })
  30. # domain=['&', ('reconcile_id', '=', False), '&', ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')])
  31. if invoice.state == 'open':
  32. invoices.append({
  33. 'id': invoice.id,
  34. 'number': invoice.number,
  35. 'date_invoice': invoice.date_invoice,
  36. 'amount_total': invoice.amount_total,
  37. 'residual': invoice.residual,
  38. 'moveLines': movelines
  39. })
  40. partners.append({
  41. 'id': customer.id,
  42. 'name': customer.name,
  43. 'display_name': customer.display_name,
  44. 'ruc': customer.ruc,
  45. 'image_medium': customer.image_medium,
  46. 'phone': customer.phone,
  47. 'mobile': customer.mobile,
  48. 'email': customer.email,
  49. 'credit': customer.credit,
  50. 'credit_limit': customer.credit_limit,
  51. 'categories': categories,
  52. 'invoices': invoices,
  53. 'date_server': str(datetime.now().date())
  54. })
  55. return partners