construction_account_invoice.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, tools, api
  3. import openerp.addons.decimal_precision as dp
  4. ''' Account Invoice'''
  5. class AccountInvoiceConstruction(models.Model):
  6. _inherit = 'account.invoice'
  7. construction_order_id = fields.Many2one('construction.order', string='Orden', ondelete='cascade', index=True, domain="[('type','=','order')]")
  8. # @api.model
  9. # def save_payments_invoice(self, values):
  10. # paymentsInvoice = super(AccountInvoiceConstruction, self).save_payments_invoice(values)
  11. # invoice = self.env['account.invoice'].browse(values['invoiceId'])
  12. # if (not invoice):
  13. # return {
  14. # 'process': False,
  15. # 'removeModal': True,
  16. # 'message': 'No fue posible localizar la factura.'
  17. # }
  18. #
  19. # if ((paymentsInvoice['process']) and (invoice.construction_move_id)):
  20. # move = self.env['construction.move'].browse(invoice.construction_move_id.id)
  21. # if (not move):
  22. # return paymentsInvoice
  23. #
  24. # move.recalculate_paid_invoice(values['amountPayments'])
  25. #
  26. # return paymentsInvoice
  27. @api.model
  28. def _compute_residual(self):
  29. if ((self.construction_move_id) and (self.type =='out_invoice')):
  30. super(AccountInvoiceConstruction, self)._compute_residual()
  31. move = self.env['construction.move'].browse(self.construction_move_id.id)
  32. if (move):
  33. amountTotal = self.amount_total or 0.0
  34. residual = self.residual or 0.0
  35. amountPaidTotal = (self.amount_total - self.residual) or 0.0
  36. move.recalculate_paid_invoice(amountTotal, amountPaidTotal,residual)
  37. super(AccountInvoiceConstruction, self)._compute_residual()
  38. ''' Get Task invoices Expenses '''
  39. @api.model
  40. def getAccountInvoiceOrder(self, id):
  41. invoice = self.env['account.invoice'].browse(id)
  42. taskOrdeLine = []
  43. if (not invoice):
  44. return False
  45. accountOrden = self.env['construction.move'].search([('order_id.id', '=', invoice.construction_order_id.id)])
  46. if (not accountOrden):
  47. return False
  48. for line in accountOrden.move_lines_ids:
  49. expense = self.env['construction.expenses.move.line'].search([('invoice_id.id','=',invoice.id),('move_line_id.id','=',line.id)])
  50. if ((expense) or (line.type == 'task')):
  51. continue
  52. taskOrdeLine.append({
  53. # 'selected': False,
  54. # 'code': line.code,
  55. # 'taskName': line.task_name,
  56. # 'quantity': expense.quantity if (expense) else 0,
  57. # 'priceUnit': expense.price_unit if (expense) else 0,
  58. # 'amountTotal': expense.amount_total if (expense) else 0,
  59. 'code': line.code,
  60. 'taskName': line.task_name,
  61. 'amountTotal': line.amount_total,
  62. 'amountExpenses': line.amount_expenses,
  63. 'residual': line.residual,
  64. 'moveLineId': line.id
  65. })
  66. '''
  67. move_id = fields.Many2one('construction.move', string='move', ondelete='cascade', index=True)
  68. uom_id = fields.Many2one('construction.uom', string='Unidad de medida')
  69. task_id = fields.Many2one('construction.task', string='Tarea')
  70. task_line_id = fields.Many2one('construction.task.line', string='Actividad')
  71. type = fields.Selection([('task', 'Tarea'),('activity', 'Actividad')])
  72. # Importe Pagado, Total , Residual
  73. expenses_ids = fields.One2many('construction.expenses.move.line', 'move_line_id', string='Expenses')
  74. '''
  75. return taskOrdeLine
  76. '''
  77. construction.expenses.move.line
  78. 'name':
  79. 'code':
  80. 'move_line_id' :
  81. 'invoice_line_id' :
  82. 'quantity' :
  83. 'price_unit' :
  84. 'amount_total' :
  85. 'invoice_id' :
  86. construction.move.line
  87. move_id = fields.Many2one('construction.move', string='move', ondelete='cascade', index=True)
  88. code = fields.Char('Code', size=32)
  89. task_name = fields.Char('name')
  90. uom_id = fields.Many2one('construction.uom', string='Unidad de medida')
  91. task_id = fields.Many2one('construction.task', string='Tarea')
  92. task_line_id = fields.Many2one('construction.task.line', string='Actividad')
  93. type = fields.Selection([('task', 'Tarea'),('activity', 'Actividad')])
  94. # Importe Pagado, Total , Residual
  95. amount_total = fields.Float('Amount Total', digits_compute=dp.get_precision('Account'), default=0.0)
  96. amount_expenses = fields.Float('Amount Expenses', digits_compute=dp.get_precision('Account'), default=0.0)
  97. residual = fields.Float('Amount Residual', digits_compute=dp.get_precision('Account'), default=0.0)
  98. expenses_ids = fields.One2many('construction.expenses.move.line', 'move_line_id', string='Expenses')
  99. '''
  100. ''' GET currency Invoice'''
  101. @api.model
  102. def getCurrencyInvoceExpenses(self, idInvoice):
  103. invoice = self.env['account.invoice'].browse(idInvoice)
  104. company = self.env.user.company_id
  105. currencyID = invoice.currency_id.id or company.currency_id.id
  106. currency = self.env['res.currency'].search([('id', '=', currencyID)])
  107. if (not currency):
  108. return False
  109. return {
  110. 'thousandsSeparator': currency.thousands_separator,
  111. 'decimalPlaces': currency.decimal_places,
  112. 'decimalSeparator': currency.decimal_separator,
  113. 'name': currency.local_name,
  114. 'symbol ':currency.symbol,
  115. }
  116. ''' ADD Task exepnse Move '''
  117. @api.model
  118. def addTaskExpensesMove(self, invoiceId, tasks):
  119. invoice = self.env['account.invoice'].browse(invoiceId)
  120. if (not invoice):
  121. return {
  122. 'state': False,
  123. 'message': 'No Fue posible localizar la factura'
  124. }
  125. for task in tasks:
  126. moveline = self.env['construction.move.line'].browse(task['moveLineId'])
  127. exepnseMove = {
  128. 'invoice_id': invoice.id,
  129. 'code': task['code'],
  130. 'move_line_id': task['moveLineId'],
  131. 'name': moveline.task_name if (moveline) else ''
  132. }
  133. moveExpense = self.env['construction.expenses.move.line'].create(exepnseMove)
  134. return {'state': True}