# -*- coding: utf-8 -*- from openerp import models, fields, tools, api import openerp.addons.decimal_precision as dp class ConstructionConfig(models.Model): _name = 'construction.config' name = fields.Char('Name', required=True, readonly=True) active = fields.Boolean('active',default=True) comment = fields.Text('Comment', help="Información adicional") ''' Invoice ''' invoice_journal_id = fields.Many2one('account.journal', string='Journal', required=True, domain="[('type','=','sale')]", help="Diario que utilizara para la facturación") invoice_account_id = fields.Many2one('account.account', string='Account', required=True, domain="[('type','=','receivable')]") ''' Line ''' line_account_id = fields.Many2one('account.account', string='Account', required=True, domain=[('type','=','other')]) line_tax_id = fields.Many2one('account.tax', string='Tax', domain=[('type_tax_use','=','sale')]) @api.model def create_default_construction_config(self): config = { 'name': 'Facturación de cliente', 'invoice_journal_id': self.get_account_journal_construction({'code':'VENTA', 'type': 'sale'}), 'invoice_account_id': self.get_account_account_construction({'code':'121000', 'type':'receivable'}), 'line_account_id': self.get_account_account_construction({'code':'411.01', 'type':'other'}), 'comment': 'Creación de factura de cliente desde la orden de servicio', } constructionConfig = self.env['construction.config'].search([('name', '=', config['name'])]) if (not constructionConfig): constructionConfig.create(config) def get_account_account_construction(self, vals): account = self.env['account.account'].search([('code','=', vals['code']),('type','=',vals['type'])]) if (not account): return '' if (len(account) > 1): account = account[len(account) -1] return account.id or '' def get_account_journal_construction(self, vals): journal = self.env['account.journal'].search([('code','=',vals['code']),('type','=',vals['type'])]) if (not journal): return '' if (len(journal) > 1): journal = journal[len(journal)-1] return journal.id or ''