123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- # -*- encoding: utf-8 -*-
- ##############################################################################
- #
- # OpenERP, Open Source Management Solution
- # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- ##############################################################################
- from openerp import models, fields, api
- from openerp.exceptions import ValidationError, except_orm, Warning, RedirectWarning
- from openerp.tools import DEFAULT_SERVER_TIME_FORMAT
- from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
- from datetime import datetime
- class OrdenPago(models.Model):
- _name = 'orden.pago'
- _description = 'Orden de Pago'
- def _get_user(self):
- return self.env.uid
- def _get_number(self):
- return self.env['ir.sequence'].next_by_code('orden.pago') or '*'
- name = fields.Char(
- string=u'Referencia',
- readonly=True,
- default=_get_number,
- )
- partner_id = fields.Many2one(
- 'res.partner',
- string='Proveedor',
- required=True
- )
- date = fields.Date(
- string='Fecha elab.',
- default=fields.Date.context_today
- )
- user_id = fields.Many2one(
- comodel_name='res.users',
- string='Preparado por:',
- default=_get_user
- )
- company_id = fields.Many2one(
- 'res.company',
- string='Compañía',
- required=True,
- default=lambda self: self.env.user.company_id
- )
- invoice_ids = fields.One2many(
- comodel_name='account.invoice',
- inverse_name='ordenpago_invoice_id',
- string='Facturas'
- )
- responsable = fields.Char(
- string='Aprobado Gerencia General:'
- )
- celular_partner = fields.Char(
- related='partner_id.mobile',
- string='Móvil',
- store=True
- )
- telefono_partner = fields.Char(
- related='partner_id.phone',
- string='Teléfono',
- store=True
- )
- ruc_partner = fields.Char(
- related='partner_id.ruc',
- string='RUC:',
- readonly=True
- )
- contacto = fields.Char(
- string='Contacto'
- )
- solicitado_por = fields.Char(
- string='Solicitado por'
- )
- metodo_ids = fields.One2many(
- 'orden.pago.metodo',
- 'orden_id',
- string='Líneas de Métodos de Pagos'
- )
- total = fields.Float(
- string='Total',
- compute='_compute_total',
- store=True
- )
- @api.depends('invoice_ids.amount_total')
- def _compute_total(self):
- for rec in self:
- rec.total = sum(line.amount_total for line in rec.invoice_ids)
- @api.onchange('partner_id')
- def _onchange_partner_id(self):
- # Filtro dinámico para facturas abiertas del cliente seleccionado
- if self.partner_id:
- return {
- 'domain': {
- 'invoice_ids': [
- ('partner_id', '=', self.partner_id.id),
- ('state', '=', 'open'),
- ('type', '=', 'in_invoice')
- ]
- }
- }
- class OrdenPagoMetodo(models.Model):
- _name = 'orden.pago.metodo'
- _description = 'Línea de Método de Orden de Pago'
- orden_id = fields.Many2one(
- 'orden.pago',
- string='Orden de Pago'
- )
- forma_pago = fields.Char(
- string='Forma de Pago'
- )
- cheque_nro = fields.Char(
- string='Cheque N°'
- )
- comprobante_fecha = fields.Date(
- string='Fecha Comprobante'
- )
- comprobante_monto = fields.Float(
- string='Importe Comprobante'
- )
- class AccountInvoice(models.Model):
- _inherit = 'account.invoice'
- ordenpago_invoice_id = fields.Many2one(
- comodel_name='orden.pago',
- string='Orden de Pago'
- )
|