123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- from openerp import api, fields, models
- class ResPartner(models.Model):
- _inherit = 'res.partner'
- @api.model
- def get_customers(self):
- domain = [('customer', '=', True), ('active', '=', True), ('credit', '>', 0)]
- customers = []
- for customer in self.env['res.partner'].search(domain):
- categories = []
- invoices = []
- for category in customer.category_id:
- categories.append({
- 'id': category.id,
- 'name': category.name,
- 'display_name': category.display_name
- })
- for invoice in customer.invoice_ids:
- movelines = []
- for move in invoice.move_id:
- for moveline in move.line_id:
- if moveline.amount_residual > 0 and moveline.state != "draft":
- movelines.append({
- 'id': moveline.id,
- 'amount_residual': moveline.amount_residual,
- 'credit': moveline.credit,
- 'debit': moveline.debit,
- 'date_maturity': moveline.date_maturity
- })
- # domain=['&', ('reconcile_id', '=', False), '&', ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')])
- if invoice.state == 'open':
- invoices.append({
- 'id': invoice.id,
- 'number': invoice.number,
- 'date_invoice': invoice.date_invoice,
- 'amount_total': invoice.amount_total,
- 'residual': invoice.residual,
- 'movelines': movelines
- })
- customers.append({
- 'id': customer.id,
- 'name': customer.name,
- 'display_name': customer.display_name,
- 'ruc': customer.ruc,
- 'image_medium': customer.image_medium,
- 'phone': customer.phone,
- 'mobile': customer.mobile,
- 'email': customer.email,
- 'credit': customer.credit,
- 'credit_limit': customer.credit_limit,
- 'categories': categories,
- 'invoices': invoices
- })
- return customers
|