orden_pago.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. metodo_ids = fields.One2many(
  85. 'orden.pago.metodo',
  86. 'orden_id',
  87. string='Líneas de Métodos de Pagos'
  88. )
  89. total = fields.Float(
  90. string='Total',
  91. compute='_compute_total',
  92. store=True
  93. )
  94. @api.depends('invoice_ids.amount_total')
  95. def _compute_total(self):
  96. for rec in self:
  97. rec.total = sum(line.amount_total for line in rec.invoice_ids)
  98. @api.onchange('partner_id')
  99. def _onchange_partner_id(self):
  100. # Filtro dinámico para facturas abiertas del cliente seleccionado
  101. if self.partner_id:
  102. return {
  103. 'domain': {
  104. 'invoice_ids': [
  105. ('partner_id', '=', self.partner_id.id),
  106. ('state', '=', 'open'),
  107. ('type', '=', 'in_invoice')
  108. ]
  109. }
  110. }
  111. class OrdenPagoMetodo(models.Model):
  112. _name = 'orden.pago.metodo'
  113. _description = 'Línea de Método de Orden de Pago'
  114. orden_id = fields.Many2one(
  115. 'orden.pago',
  116. string='Orden de Pago'
  117. )
  118. forma_pago = fields.Char(
  119. string='Forma de Pago'
  120. )
  121. cheque_nro = fields.Char(
  122. string='Cheque N°'
  123. )
  124. comprobante_fecha = fields.Date(
  125. string='Fecha Comprobante'
  126. )
  127. comprobante_monto = fields.Float(
  128. string='Importe Comprobante'
  129. )
  130. class AccountInvoice(models.Model):
  131. _inherit = 'account.invoice'
  132. ordenpago_invoice_id = fields.Many2one(
  133. comodel_name='orden.pago',
  134. string='Orden de Pago'
  135. )