# -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # # 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 . # ############################################################################## 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 OrdenCobro(models.Model): _name = 'orden.cobro' _description = 'Orden de cobro' def _get_user(self): return self.env.uid def _get_number(self): return self.env['ir.sequence'].next_by_code('orden.cobro') or '*' name = fields.Char( string=u'Referencia', readonly=True, default=_get_number, ) partner_id = fields.Many2one( 'res.partner', string='Cliente', 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='ordencobro_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 ) forma_cobro = fields.Char( string='Forma de Cobro' ) presupuesto_nro = fields.Char( string='Presupuesto N°' ) cheque_nro = fields.Char( string='Cheque N°' ) transf_nro = fields.Char( string='Transferencia N°' ) cheque_banco = fields.Char( string='Banco Cheque' ) transf_banco = fields.Char( string='Banco Transferencia' ) concepto = fields.Char( string='Concepto' ) currency_id = fields.Many2one( 'res.currency', string='Moneda', related='company_id.currency_id', store=True, readonly=True ) is_efec = fields.Boolean(string="Efectivo", default=False) is_cheq = fields.Boolean(string="Cheque", default=False) is_transf = fields.Boolean(string="Transferencia", default=False) comprobante_monto = fields.Float( string='Importe Comprobante' ) obra = fields.Char( string='Obra' ) solicitado_por = fields.Char( string='Solicitado por' ) 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', '=', 'out_invoice') ] } } class AccountInvoice(models.Model): _inherit = 'account.invoice' ordencobro_invoice_id = fields.Many2one( comodel_name='orden.cobro', string='Orden de cobro' )