orden_pago.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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(string=u'Referencia', readonly=True, copy=False, default='/')
  34. partner_id = fields.Many2one(
  35. 'res.partner',
  36. string='Proveedor',
  37. required=True
  38. )
  39. date = fields.Date(
  40. string='Fecha elab.',
  41. default=fields.Date.context_today
  42. )
  43. user_id = fields.Many2one(
  44. comodel_name='res.users',
  45. string='Preparado por:',
  46. default=_get_user
  47. )
  48. company_id = fields.Many2one(
  49. 'res.company',
  50. string='Compañía',
  51. required=True,
  52. default=lambda self: self.env.user.company_id
  53. )
  54. invoice_ids = fields.One2many(
  55. comodel_name='account.invoice',
  56. inverse_name='ordenpago_invoice_id',
  57. string='Facturas'
  58. )
  59. responsable = fields.Char(
  60. string='Aprobado Gerencia General:'
  61. )
  62. celular_partner = fields.Char(
  63. related='partner_id.mobile',
  64. string='Móvil',
  65. store=True
  66. )
  67. telefono_partner = fields.Char(
  68. related='partner_id.phone',
  69. string='Teléfono',
  70. store=True
  71. )
  72. ruc_partner = fields.Char(
  73. related='partner_id.ruc',
  74. string='RUC:',
  75. readonly=True
  76. )
  77. contacto = fields.Char(
  78. string='Contacto'
  79. )
  80. solicitado_por = fields.Char(
  81. string='Solicitado por'
  82. )
  83. metodo_ids = fields.One2many(
  84. 'orden.pago.metodo',
  85. 'orden_id',
  86. string='Líneas de Métodos de Pagos'
  87. )
  88. total = fields.Float(
  89. string='Total',
  90. compute='_compute_total',
  91. store=True
  92. )
  93. @api.model
  94. def create(self, vals):
  95. if vals.get('name', '/') == '/':
  96. vals['name'] = self.env['ir.sequence'].next_by_code('orden.pago') or '/'
  97. return super(OrdenPago, self).create(vals)
  98. @api.depends('invoice_ids.amount_total')
  99. def _compute_total(self):
  100. for rec in self:
  101. rec.total = sum(line.amount_total for line in rec.invoice_ids)
  102. @api.onchange('partner_id')
  103. def _onchange_partner_id(self):
  104. # Filtro dinámico para facturas abiertas del cliente seleccionado
  105. if self.partner_id:
  106. return {
  107. 'domain': {
  108. 'invoice_ids': [
  109. ('partner_id', '=', self.partner_id.id),
  110. ('state', '=', 'open'),
  111. ('type', '=', 'in_invoice')
  112. ]
  113. }
  114. }
  115. class OrdenPagoMetodo(models.Model):
  116. _name = 'orden.pago.metodo'
  117. _description = 'Línea de Método de Orden de Pago'
  118. orden_id = fields.Many2one(
  119. 'orden.pago',
  120. string='Orden de Pago'
  121. )
  122. forma_pago = fields.Char(
  123. string='Forma de Pago'
  124. )
  125. cheque_nro = fields.Char(
  126. string='Cheque N°'
  127. )
  128. comprobante_fecha = fields.Date(
  129. string='Fecha Comprobante'
  130. )
  131. comprobante_monto = fields.Float(
  132. string='Importe Comprobante'
  133. )
  134. class AccountInvoice(models.Model):
  135. _inherit = 'account.invoice'
  136. ordenpago_invoice_id = fields.Many2one(
  137. comodel_name='orden.pago',
  138. string='Orden de Pago'
  139. )