12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- from openerp import api, fields, models
- class ResPartner(models.Model):
- _inherit = 'res.partner'
- @api.model
- def get_partners(self):
- domain = [('customer', '=', True), ('active', '=', True), ('credit', '>', 0)]
- partners = []
- 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
- })
- partners.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 partners
|