123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- # -*- coding: utf-8 -*-
- from openerp import models, fields, tools, api
- import openerp.addons.decimal_precision as dp
- ''' Account Invoice'''
- class AccountInvoiceConstruction(models.Model):
- _inherit = 'account.invoice'
- construction_order_id = fields.Many2one('construction.order', string='Orden', ondelete='cascade', index=True, domain="[('type','=','order')]")
- # @api.model
- # def save_payments_invoice(self, values):
- # paymentsInvoice = super(AccountInvoiceConstruction, self).save_payments_invoice(values)
- # invoice = self.env['account.invoice'].browse(values['invoiceId'])
- # if (not invoice):
- # return {
- # 'process': False,
- # 'removeModal': True,
- # 'message': 'No fue posible localizar la factura.'
- # }
- #
- # if ((paymentsInvoice['process']) and (invoice.construction_move_id)):
- # move = self.env['construction.move'].browse(invoice.construction_move_id.id)
- # if (not move):
- # return paymentsInvoice
- #
- # move.recalculate_paid_invoice(values['amountPayments'])
- #
- # return paymentsInvoice
- @api.model
- def _compute_residual(self):
- if ((self.construction_move_id) and (self.type =='out_invoice')):
- super(AccountInvoiceConstruction, self)._compute_residual()
- move = self.env['construction.move'].browse(self.construction_move_id.id)
- if (move):
- amountTotal = self.amount_total or 0.0
- residual = self.residual or 0.0
- amountPaidTotal = (self.amount_total - self.residual) or 0.0
- move.recalculate_paid_invoice(amountTotal, amountPaidTotal,residual)
- super(AccountInvoiceConstruction, self)._compute_residual()
- ''' Get Task invoices Expenses '''
- @api.model
- def getAccountInvoiceOrder(self, id):
- invoice = self.env['account.invoice'].browse(id)
- taskOrdeLine = []
- if (not invoice):
- return False
- accountOrden = self.env['construction.move'].search([('order_id.id', '=', invoice.construction_order_id.id)])
- if (not accountOrden):
- return False
- for line in accountOrden.move_lines_ids:
- expense = self.env['construction.expenses.move.line'].search([('invoice_id.id','=',invoice.id),('move_line_id.id','=',line.id)])
- if ((expense) or (line.type == 'task')):
- continue
- taskOrdeLine.append({
- # 'selected': False,
- # 'code': line.code,
- # 'taskName': line.task_name,
- # 'quantity': expense.quantity if (expense) else 0,
- # 'priceUnit': expense.price_unit if (expense) else 0,
- # 'amountTotal': expense.amount_total if (expense) else 0,
- 'code': line.code,
- 'taskName': line.task_name,
- 'amountTotal': line.amount_total,
- 'amountExpenses': line.amount_expenses,
- 'residual': line.residual,
- 'moveLineId': line.id
- })
- '''
- move_id = fields.Many2one('construction.move', string='move', ondelete='cascade', index=True)
- uom_id = fields.Many2one('construction.uom', string='Unidad de medida')
- task_id = fields.Many2one('construction.task', string='Tarea')
- task_line_id = fields.Many2one('construction.task.line', string='Actividad')
- type = fields.Selection([('task', 'Tarea'),('activity', 'Actividad')])
- # Importe Pagado, Total , Residual
- expenses_ids = fields.One2many('construction.expenses.move.line', 'move_line_id', string='Expenses')
- '''
- return taskOrdeLine
- '''
- construction.expenses.move.line
- 'name':
- 'code':
- 'move_line_id' :
- 'invoice_line_id' :
- 'quantity' :
- 'price_unit' :
- 'amount_total' :
- 'invoice_id' :
- construction.move.line
- move_id = fields.Many2one('construction.move', string='move', ondelete='cascade', index=True)
- code = fields.Char('Code', size=32)
- task_name = fields.Char('name')
- uom_id = fields.Many2one('construction.uom', string='Unidad de medida')
- task_id = fields.Many2one('construction.task', string='Tarea')
- task_line_id = fields.Many2one('construction.task.line', string='Actividad')
- type = fields.Selection([('task', 'Tarea'),('activity', 'Actividad')])
- # Importe Pagado, Total , Residual
- amount_total = fields.Float('Amount Total', digits_compute=dp.get_precision('Account'), default=0.0)
- amount_expenses = fields.Float('Amount Expenses', digits_compute=dp.get_precision('Account'), default=0.0)
- residual = fields.Float('Amount Residual', digits_compute=dp.get_precision('Account'), default=0.0)
- expenses_ids = fields.One2many('construction.expenses.move.line', 'move_line_id', string='Expenses')
- '''
- ''' GET currency Invoice'''
- @api.model
- def getCurrencyInvoceExpenses(self, idInvoice):
- invoice = self.env['account.invoice'].browse(idInvoice)
- company = self.env.user.company_id
- currencyID = invoice.currency_id.id or company.currency_id.id
- currency = self.env['res.currency'].search([('id', '=', currencyID)])
- if (not currency):
- return False
- return {
- 'thousandsSeparator': currency.thousands_separator,
- 'decimalPlaces': currency.decimal_places,
- 'decimalSeparator': currency.decimal_separator,
- 'name': currency.local_name,
- 'symbol ':currency.symbol,
- }
- ''' ADD Task exepnse Move '''
- @api.model
- def addTaskExpensesMove(self, invoiceId, tasks):
- invoice = self.env['account.invoice'].browse(invoiceId)
- if (not invoice):
- return {
- 'state': False,
- 'message': 'No Fue posible localizar la factura'
- }
- for task in tasks:
- moveline = self.env['construction.move.line'].browse(task['moveLineId'])
- exepnseMove = {
- 'invoice_id': invoice.id,
- 'code': task['code'],
- 'move_line_id': task['moveLineId'],
- 'name': moveline.task_name if (moveline) else ''
- }
- moveExpense = self.env['construction.expenses.move.line'].create(exepnseMove)
- return {'state': True}
|