123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- # -*- coding: utf-8 -*-
- from openerp import models, fields, tools, api
- import openerp.addons.decimal_precision as dp
- class constructionOrder(models.Model):
- _name = 'construction.order'
- name = fields.Char('name')
- date = fields.Date()
- active = fields.Boolean('Active', default=True)
- work_id = fields.Many2one('construction.work', string='obra', required=True)
- partner_id = fields.Many2one('res.partner', string='owner', help='owner of the work', required=True)
- order_street = fields.Char('street')
- order_city = fields.Char('city')
- total_area = fields.Float('Superficie', required=True)
- ref = fields.Char('Ref')
- comment = fields.Text('Comment', help='information')
- type = fields.Selection([('budget', 'Presupuesto'),('order', 'orden')])
- line_ids = fields.One2many('construction.order.line', 'order_ids', string='lines')
- state = fields.Selection([('draft', 'Borrador'),('done', 'Hecho')], default='draft')
- currency_id = fields.Many2one('res.currency', string="Currency", help="Moneda de la operación", required=True)
- ''' order & budget'''
- budget_id = fields.Many2one('construction.order', string='Budget', ondelete='restrict', index=True)
- order_id = fields.Many2one('construction.order', string='Orden', ondelete='restrict', index=True)
- amount_total = fields.Float('Amount Total', digits_compute=dp.get_precision('Account'), default=0.0)
- @api.model
- def create(self, vals):
- vals['type'] = self._context.get('type')
- if (self._context.get('type') == 'budget'):
- vals['name'] = self.env['ir.sequence'].get('construction.order.budget') or '/'
- else:
- vals['name'] = self.env['ir.sequence'].get('construction.order.order') or '/'
- return super(constructionOrder, self).create(vals)
- @api.model
- def get_currency_order(self, id):
- order = self.env['construction.order'].browse(id)
- company = self.env.user.company_id
- currencyID = order.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,
- }
- @api.model
- def eiru_add_task(self, id,tasks):
- line = self.env['construction.order.line'].search([('order_ids', '=', id )])
- lineTask = []
- if ( line ):
- for i in line:
- i.unlink()
- for task in tasks:
- lineTask= {
- 'code':task['code'],
- 'task_name': task['taskName'],
- 'uom_id': task['uomId'],
- 'task_id': task['taskId'],
- 'task_line_id': task['taskLineId'],
- 'qty': task['qty'],
- 'amount': task['amount'],
- 'amount_total': task['amountTotal'],
- 'type': task['type'],
- 'order_ids': id
- }
- line.create(lineTask)
- order = self.env['construction.order'].browse(id)
- if (not order):
- return {'state': False }
- ammount = 0
- for line in order.line_ids:
- if (line.type =='activity'):
- ammount +=line.amount_total
- order.write({'amount_total': ammount})
- return {'state': True }
- @api.model
- def action_confirm_budget(self, idBudget):
- orderBudget = self.env['construction.order'].browse(idBudget)
- if (not orderBudget):
- return
- order = orderBudget.copy()
- if (not order):
- return
- order.write({
- 'name': self.env['ir.sequence'].get('construction.order.order') or '/',
- 'type': 'order',
- 'budget_id': orderBudget.id
- })
- lines = orderBudget.line_ids.copy()
- for line in lines:
- line.write({'order_ids': order.id})
- ''' Actualizar el numero de orden en elregistro de Subcontratista'''
- for contractor in orderBudget.contractor_budget_ids:
- contractor.write({'order_id': order.id})
- ''' Actualizar en numero de orden en el presupuesto '''
- orderBudget.write({'state': 'done', 'order_id': order.id})
- return True
- @api.model
- def action_confirm_order(self, idOrder):
- move = []
- moveLines = []
- order = self.env['construction.order'].browse(idOrder)
- if (not order):
- return False
- for line in order.line_ids:
- moveLines.append([0, False,{
- 'code': line.code,
- 'task_name': line.task_name,
- 'uom_id': line.uom_id.id,
- 'task_id': line.task_id.id,
- 'task_line_id': line.task_line_id.id,
- 'type': line.type,
- 'amount_total': line.amount_total,
- 'amount_paid': 0,
- 'residual': line.amount_total,
- }])
- move = {
- 'partner_id': order.partner_id.id,
- 'order_id': order.id,
- 'work_id': order.work_id.id,
- 'amount_total': order.amount_total,
- 'amount_paid': 0,
- 'residual': order.amount_total,
- 'type': 'order',
- 'move_lines_ids': moveLines,
- 'currency_id': order.currency_id.id
- }
- # create
- moveOrder = self.env['construction.move'].create(move)
- if (not moveOrder):
- return False
- moveOrder.createInvoiceMove()
- ''' Contratista '''
- move = []
- for contractor in order.contractor_order_ids:
- moveLines = []
- for line in contractor.line_ids:
- moveLines.append([0, False,{
- 'code': line.code,
- 'task_name': line.task_name,
- 'uom_id': line.uom_id.id,
- 'task_id': line.task_id.id,
- 'task_line_id': line.task_line_id.id,
- 'type': line.type,
- 'amount_total': line.amount_total,
- 'amount_paid': 0,
- 'residual': line.amount_total,
- }])
- move = {
- 'partner_id': contractor.partner_id.id,
- 'order_id': order.id,
- 'work_id': order.work_id.id,
- 'amount_total': contractor.amount_total,
- 'amount_paid': 0,
- 'residual': contractor.amount_total,
- 'type': 'contractor',
- 'move_lines_ids': moveLines,
- 'currency_id': order.currency_id.id
- }
- moveOrder = self.env['construction.move'].create(move)
- if (not moveOrder):
- return False
- order.write({'state': 'done'})
- ''' RES PARTNER '''
- class ResPartnerOrder(models.Model):
- _inherit = 'res.partner'
- construction_budget = fields.One2many('construction.order', 'partner_id', string='Budget', domain=[('type', '=', 'budget')])
- construction_order = fields.One2many('construction.order', 'partner_id', string='Order', domain=[('type', '=', 'order')])
- class constructionOrderLine(models.Model):
- _name = 'construction.order.line'
- code = fields.Char('Code', size=32, required=True, select=True)
- 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')
- qty = fields.Float('Cantidad', default=0)
- amount = fields.Float('Amount Unit', digits_compute=dp.get_precision('Account'), default=0.0)
- amount_total = fields.Float('Amount Total', digits_compute=dp.get_precision('Account'), default=0.0)
- type = fields.Selection([('task', 'Tarea'),('activity', 'Actividad')])
- order_ids = fields.Many2one('construction.order', string='Orden', ondelete='cascade', index=True, required=True)
- ''' Get Line in order '''
- def get_construction_order_line(self, orderID):
- return [{
- 'id': line.id,
- 'code': line.code,
- 'taskName': line.task_name,
- 'uomId': line.uom_id.id if(line.uom_id) else "",
- 'uomName': line.uom_id.name if(line.uom_id) else "" ,
- 'taskId': line.task_id.id,
- 'taskLineId': line.task_line_id.id if(line.task_line_id) else "",
- 'qty': line.qty,
- 'amount': line.amount,
- 'amountTotal': line.amount_total,
- 'type': line.type,
- } for line in self.env['construction.order.line'].search([('order_ids', '=', orderID)])]
|