models.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. class AccountInvoice(models.Model):
  4. _inherit = 'account.invoice'
  5. @api.model
  6. def getAccountInvoicePagare(self,domain):
  7. AccountInvoice = self.env['account.invoice'].search(domain)
  8. values = []
  9. for invoice in AccountInvoice:
  10. values.append({
  11. # ID
  12. 'id': invoice.id,
  13. 'number': invoice.number,
  14. 'origin': invoice.origin,
  15. 'date_invoice': invoice.date_invoice,
  16. 'user_name': invoice.user_id.name,
  17. 'amount_untaxed': invoice.amount_untaxed,
  18. 'amount_tax': invoice.amount_untaxed,
  19. 'amount_total': invoice.amount_untaxed,
  20. # PARTNER INFO
  21. 'partner_id':[{
  22. 'id': invoice.partner_id.id,
  23. 'name': invoice.partner_id.name,
  24. 'ruc': invoice.partner_id.ruc,
  25. 'address': invoice.partner_id.street,
  26. 'phone': invoice.partner_id.phone,
  27. 'mobile': invoice.partner_id.mobile,
  28. }],
  29. # COMPANY INFO
  30. 'company_id': [{
  31. 'id':invoice.user_id.company_id.id,
  32. 'name': invoice.user_id.company_id.name,
  33. 'logo': invoice.user_id.company_id.logo,
  34. 'phone': invoice.user_id.company_id.phone,
  35. }],
  36. # CURRENCY INFO
  37. 'currency_id':[{
  38. 'id': invoice.currency_id.id,
  39. 'name': invoice.currency_id.name,
  40. 'symbol': invoice.currency_id.symbol,
  41. 'thousands_separator': invoice.currency_id.thousands_separator,
  42. 'decimal_separator': invoice.currency_id.decimal_separator,
  43. 'decimal_places': invoice.currency_id.decimal_places,
  44. 'symbol_position': invoice.currency_id.symbol,
  45. }],
  46. })
  47. return values
  48. @api.model
  49. def getAccountInvoicePagareQuota(self,domain):
  50. AccountInvoice = self.env['account.invoice'].search(domain)
  51. AccountMoveLine = self.env['account.move.line'].search([('move_id','=',AccountInvoice.number),('debit','>',0)],order='date_maturity')
  52. i = 1
  53. x = len(AccountMoveLine)
  54. values = []
  55. for line in AccountMoveLine:
  56. amount = 0
  57. value = 0
  58. state = 'No pagado'
  59. if(line.reconcile_ref != False):
  60. if(line.amount_residual == 0):
  61. state = 'Pagado'
  62. if(line.amount_residual > 0):
  63. value = line.debit - line.amount_residual
  64. state = 'Amortizado'
  65. values.append({
  66. 'date': line.date_maturity,
  67. 'name': 'Cuota ' + str(i) + ' / ' + str(x),
  68. 'state': state,
  69. 'value': value,
  70. 'amount': line.debit,
  71. 'residual': line.amount_residual,
  72. })
  73. i = i + 1
  74. return values
  75. class AccountInvoiceLine(models.Model):
  76. _inherit = 'account.invoice.line'
  77. @api.model
  78. def getAccountInvoiceLinePagare(self,domain):
  79. AccountInvoiceLine = self.env['account.invoice.line'].search(domain)
  80. values = []
  81. for line in AccountInvoiceLine:
  82. values.append({
  83. 'id': line.id,
  84. 'name': line.name,
  85. 'quantity': line.quantity,
  86. 'price_unit': line.price_unit,
  87. 'price_subtotal': line.price_subtotal,
  88. })
  89. return values