orden_pago.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import models, fields, api
  22. from openerp.exceptions import ValidationError, except_orm, Warning, RedirectWarning
  23. from openerp.tools import DEFAULT_SERVER_TIME_FORMAT
  24. from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
  25. from datetime import datetime
  26. class OrdenPago(models.Model):
  27. _name = 'orden.pago'
  28. _description = 'Orden de Pago'
  29. def _get_user(self):
  30. return self.env.uid
  31. def _get_number(self):
  32. return self.env['ir.sequence'].next_by_code('orden.pago') or '*'
  33. name = fields.Char(
  34. string=u'Referencia',
  35. readonly=True,
  36. default=_get_number,
  37. )
  38. partner_id = fields.Many2one(
  39. 'res.partner',
  40. string='Proveedor',
  41. required=True
  42. )
  43. date = fields.Date(
  44. string='Fecha elab.',
  45. default=fields.Date.context_today
  46. )
  47. user_id = fields.Many2one(
  48. comodel_name='res.users',
  49. string='Preparado por:',
  50. default=_get_user
  51. )
  52. company_id = fields.Many2one(
  53. 'res.company',
  54. string='Compañía',
  55. required=True,
  56. default=lambda self: self.env.user.company_id
  57. )
  58. invoice_ids = fields.One2many(
  59. comodel_name='account.invoice',
  60. inverse_name='ordenpago_invoice_id',
  61. string='Facturas'
  62. )
  63. responsable = fields.Char(
  64. string='Aprobado Gerencia General:'
  65. )
  66. celular_partner = fields.Char(
  67. related='partner_id.mobile',
  68. string='Móvil',
  69. store=True
  70. )
  71. telefono_partner = fields.Char(
  72. related='partner_id.phone',
  73. string='Teléfono',
  74. store=True
  75. )
  76. ruc_partner = fields.Char(
  77. related='partner_id.ruc',
  78. string='RUC:',
  79. readonly=True
  80. )
  81. contacto = fields.Char(
  82. string='Contacto'
  83. )
  84. solicitado_por = fields.Char(
  85. string='Solicitado por'
  86. )
  87. metodo_ids = fields.One2many(
  88. 'orden.pago.metodo',
  89. 'orden_id',
  90. string='Líneas de Métodos de Pagos'
  91. )
  92. total = fields.Float(
  93. string='Total',
  94. compute='_compute_total',
  95. store=True
  96. )
  97. @api.depends('invoice_ids.amount_total')
  98. def _compute_total(self):
  99. for rec in self:
  100. rec.total = sum(line.amount_total for line in rec.invoice_ids)
  101. @api.onchange('partner_id')
  102. def _onchange_partner_id(self):
  103. # Filtro dinámico para facturas abiertas del cliente seleccionado
  104. if self.partner_id:
  105. return {
  106. 'domain': {
  107. 'invoice_ids': [
  108. ('partner_id', '=', self.partner_id.id),
  109. ('state', '=', 'open'),
  110. ('type', '=', 'in_invoice')
  111. ]
  112. }
  113. }
  114. class OrdenPagoMetodo(models.Model):
  115. _name = 'orden.pago.metodo'
  116. _description = 'Línea de Método de Orden de Pago'
  117. orden_id = fields.Many2one(
  118. 'orden.pago',
  119. string='Orden de Pago'
  120. )
  121. forma_pago = fields.Char(
  122. string='Forma de Pago'
  123. )
  124. cheque_nro = fields.Char(
  125. string='Cheque N°'
  126. )
  127. comprobante_fecha = fields.Date(
  128. string='Fecha Comprobante'
  129. )
  130. comprobante_monto = fields.Float(
  131. string='Importe Comprobante'
  132. )
  133. class AccountInvoice(models.Model):
  134. _inherit = 'account.invoice'
  135. ordenpago_invoice_id = fields.Many2one(
  136. comodel_name='orden.pago',
  137. string='Orden de Pago'
  138. )