eiru_study_feature.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. # -*- coding: utf-8 -*-
  2. # License, author and contributors information in:
  3. # __openerp__.py file at the root folder of this module.
  4. from openerp import api, models, fields
  5. from openerp.exceptions import ValidationError, except_orm, Warning, RedirectWarning
  6. import logging
  7. _log = logging.getLogger(__name__)
  8. class StudyFeature(models.Model):
  9. _name = 'study.feature'
  10. _description = 'Study Feature'
  11. _inherit = ['mail.thread', 'ir.needaction_mixin']
  12. def _get_user(self):
  13. return self.env.uid
  14. def _get_number(self):
  15. return self.env['ir.sequence'].get('study.feature') or '*'
  16. name = fields.Char(
  17. string=u'Code',
  18. readonly=True,
  19. default=_get_number
  20. )
  21. user_id = fields.Many2one(
  22. comodel_name='res.users',
  23. string='Engineer',
  24. default=_get_user
  25. )
  26. partner_id = fields.Many2one(
  27. comodel_name='res.partner',
  28. string='Partner'
  29. )
  30. product_id = fields.Many2one(
  31. comodel_name='product.product',
  32. string='Partner'
  33. )
  34. # line_ids = fields.One2many(
  35. # comodel_name='repair.workorder.line',
  36. # inverse_name='workorder_id',
  37. # string='Products delivered'
  38. # )
  39. # consumed_ids = fields.One2many(
  40. # comodel_name='repair.workorder.consumed',
  41. # inverse_name='workorder_id',
  42. # string='Product & Services consumed'
  43. # )
  44. order_date = fields.Datetime(
  45. string='Order date',
  46. default=fields.Datetime.now
  47. )
  48. # planned_start_date = fields.Datetime(
  49. # string='Planned start date'
  50. # )
  51. # planned_end_date = fields.Datetime(
  52. # string='Planned end date'
  53. # )
  54. diagnostic = fields.Text(
  55. string='Diagnostic'
  56. )
  57. causes = fields.Text(
  58. string='Causes'
  59. )
  60. actions = fields.Text(
  61. string='Actions'
  62. )
  63. recommendations = fields.Text(
  64. string="recommendations"
  65. )
  66. # state = fields.Selection([
  67. # ('draft', 'Pending'),
  68. # ('in_progress', 'In progress'),
  69. # ('done', 'Done'),
  70. # ('canceled', 'Canceled'),
  71. # ('invoiced', 'Invoiced')],
  72. # string='State',
  73. # default='draft'
  74. # )
  75. # invoice_ids = fields.One2many('account.invoice', 'work_invoice_id')
  76. # invoice_count = fields.Integer(
  77. # string='Facturas',
  78. # compute='_get_invoice_count',
  79. # )
  80. # @api.multi
  81. # def button_draft(self):
  82. # if self.invoice_count > 0:
  83. # raise Warning('Este trabajo tiene una factura asociada')
  84. # if self.invoice_count == 0:
  85. # for work in self:
  86. # work.write({'state': 'draft'})
  87. # return True
  88. # @api.one
  89. # @api.depends('invoice_ids')
  90. # def _get_invoice_count(self):
  91. # self.invoice_count = len(self.invoice_ids)
  92. @api.one
  93. def onchange_partner_id(self, partner_id):
  94. _log.info('-'*100)
  95. _log.info(partner_id)
  96. # @api.one
  97. # def button_in_progress(self):
  98. # self.state = 'in_progress'
  99. # @api.one
  100. # def button_in_progress_back(self):
  101. # self.state = 'draft'
  102. # @api.one
  103. # def button_done(self):
  104. # product = self.line_ids
  105. # works = self.consumed_ids
  106. # if not product or not works:
  107. # raise Warning('El trabajo debe tener productos y trabajos asociados')
  108. # else:
  109. # self.state = 'done'
  110. # @api.one
  111. # def button_done_back(self):
  112. # self.state = 'in_progress'
  113. # @api.one
  114. # def button_cancel(self):
  115. # self.state = 'canceled'
  116. # @api.multi
  117. # def Facturado(self):
  118. # inv_obj = self.env['account.invoice']
  119. # inv_line_obj = self.env['account.invoice.line']
  120. # customer = self.partner_id
  121. # if not customer.name:
  122. # raise osv.except_osv(_('UserError!'), _('Please select a Customer.'))
  123. # company_id = self.env['res.users'].browse(1).company_id
  124. # self.ensure_one()
  125. # ir_values = self.env['ir.values']
  126. # inv_data = {
  127. # 'name': customer.name,
  128. # 'reference': customer.name,
  129. # 'account_id': customer.property_account_receivable.id,
  130. # 'partner_id': customer.id,
  131. # 'origin': self.name,
  132. # 'work_invoice_id': self.id
  133. # }
  134. # inv_id = inv_obj.create(inv_data)
  135. # for records in self.consumed_ids:
  136. # if records.product_id.id:
  137. # income_account = records.product_id.categ_id.property_account_income_categ.id
  138. # if not income_account:
  139. # raise osv.except_osv(_('UserError!'), _('There is no income account defined '
  140. # 'for this product: "%s".') % (records.product_id.name,))
  141. # inv_line_data = {
  142. # 'name': records.product_id.name,
  143. # 'account_id': income_account,
  144. # 'price_unit': records.price_unit,
  145. # 'quantity': records.quantity,
  146. # 'product_id': records.product_id.id,
  147. # 'invoice_id': inv_id.id,
  148. # 'invoice_line_tax_id': [(6, 0, [x.id for x in records.product_id.taxes_id])],
  149. # }
  150. # inv_line_obj.create(inv_line_data)
  151. # self.state = 'invoiced'
  152. # imd = self.env['ir.model.data']
  153. # action = imd.xmlid_to_object('account.action_invoice_tree1')
  154. # list_view_id = imd.xmlid_to_res_id('account.invoice_tree')
  155. # form_view_id = imd.xmlid_to_res_id('account.invoice_form')
  156. # result = {
  157. # 'name': action.name,
  158. # 'help': action.help,
  159. # 'type': 'ir.actions.act_window',
  160. # 'views': [[list_view_id, 'tree'], [form_view_id, 'form'], [False, 'graph'], [False, 'kanban'],
  161. # [False, 'calendar'], [False, 'pivot']],
  162. # 'target': action.target,
  163. # 'context': action.context,
  164. # 'res_model': 'account.invoice',
  165. # }
  166. # if len(inv_id) > 1:
  167. # result['domain'] = "[('id','in',%s)]" % inv_id.ids
  168. # elif len(inv_id) == 1:
  169. # result['views'] = [(form_view_id, 'form')]
  170. # result['res_id'] = inv_id.ids[0]
  171. # else:
  172. # result = {'type': 'ir.actions.act_window_close'}
  173. # invoiced_records = self.env['repair.workorder']
  174. # total = 0
  175. # self.stage_id = 3
  176. # for rows in invoiced_records:
  177. # invoiced_date = rows.date
  178. # invoiced_date = invoiced_date[0:10]
  179. # if invoiced_date == str(date.today()):
  180. # total = total + rows.price_subtotal
  181. # inv_id.signal_workflow('invoice_open')
  182. # return result
  183. # class WorkOrderLine(models.Model):
  184. # _name = 'repair.workorder.line'
  185. # _description = 'Product to repair'
  186. # _inherit = ['mail.thread', 'ir.needaction_mixin']
  187. # workorder_id = fields.Many2one(
  188. # comodel_name='repair.workorder',
  189. # string='Work order')
  190. # description = fields.Char(string='Description')
  191. # quantity = fields.Float(string='Quantity', default=1.0)
  192. # brand = fields.Char(string='Marca')
  193. # number = fields.Char(string="Numero de serie")
  194. # class WorkOrderConsumed(models.Model):
  195. # _name = 'repair.workorder.consumed'
  196. # _description = 'Services for repair'
  197. # _inherit = ['mail.thread', 'ir.needaction_mixin']
  198. # workorder_id = fields.Many2one(
  199. # comodel_name='repair.workorder',
  200. # string='Work order'
  201. # )
  202. # product_id = fields.Many2one(
  203. # comodel_name='product.product',
  204. # string='Product'
  205. # )
  206. # type = fields.Selection([
  207. # ('service', 'Service'),
  208. # ('product', 'Product')],
  209. # string='Type',
  210. # required=True,
  211. # default='service'
  212. # )
  213. # description = fields.Char(
  214. # string='Description',
  215. # required=True
  216. # )
  217. # quantity = fields.Float(
  218. # string='Quantity',
  219. # default=1
  220. # )
  221. # price_unit = fields.Float(
  222. # string='Price unit'
  223. # )
  224. # subtotal = fields.Float(
  225. # string='Subtotal',
  226. # compute='compute_subtotal'
  227. # )
  228. # @api.one
  229. # @api.depends('quantity', 'price_unit')
  230. # def compute_subtotal(self):
  231. # self.subtotal = self.quantity * self.price_unit
  232. # @api.onchange('product_id')
  233. # def onchange_product_id(self):
  234. # if self.product_id:
  235. # self.description = self.product_id.name
  236. # self.type = 'service' if self.product_id.type == 'service' \
  237. # else 'product'
  238. # # @ TODO impuestos??
  239. # # Obtener el precio del producto a partir de la tarifa del cliente
  240. # self.price_unit = self.product_id.list_price
  241. # class AccountInvoice(models.Model):
  242. # _inherit = 'account.invoice'
  243. # work_invoice_id = fields.Many2one('repair.workorder')