res_partner.py 2.4 KB

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