Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | None | 0 0
  1. # inherited Object https://github.com/odoo/odoo/blob/9.0/openerp/models.py
  2.  
  3. class PlustronProjectTask(models.Model):
  4.     _name = 'default.project.task'
  5.     _order = 'sequence'
  6.  
  7.     name = fields.Char('Name')
  8.     description = fields.Text('Description', required=True)
  9.     sequence = fields.Integer('Sequence', select=True, help="Gives the sequence order when displaying a list of tasks.",
  10.                               default=10, required=True)
  11.  
  12.     tag_ids = fields.Many2many('project.tags', string='Tags', oldname='categ_ids')
  13.     notes = fields.Text('Notes')
  14.  
  15.     @api.constrains('planned_hours')
  16.     def constrain_planned_hours(self):
  17.         if self.planned_hours <= 0.00:
  18.             raise ValidationError(_('You have not planned time for that task!'))
  19.  
  20.     planned_hours = fields.Float('Initially Planned Hours',
  21.                                  help='Estimated time to do the task, usually set by the project manager '
  22.                                       'when the task is in draft state.', required=True)
  23.     user_id = fields.Many2one('res.users', 'Assigned to', select=True, required=True)
  24.     child_ids = fields.Many2many('default.project.task', 'default_project_task_parent_rel', 'parent_id', 'task_id',
  25.                                  'Delegated Tasks', domain=lambda self: [('id', '!=', self.id)])
  26.     parent_id = fields.Many2one('default.project.task', 'Parent Tasks', domain=lambda self: [('id', '!=', self.id)])
  27.     color = fields.Integer('Color Index', default=1)
  28.     attachment_ids = fields.One2many('ir.attachment', 'res_id', domain=lambda self: [('res_model', '=', self._name)],
  29.                                      auto_join=True, string='Attachments')
  30.     displayed_image_id = fields.Many2one('ir.attachment',
  31.                                          domain="[('mimetype', 'ilike', 'image')]", string='Displayed Image')
  32.     product_id = fields.Many2one('product.product', 'Product for Sale',
  33.                                  help="If account generated invoices from tasks this is the product")
  34.     company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.user.company_id, required=True)
  35.     type = fields.Selection(
  36.         [('recruiting', 'Recruiting'), ('office', 'Office')],
  37.         'Type',
  38.         help="Task type",
  39.         default="office"
  40.     )
  41.  
  42.    
  43. #   def create(https://github.com/odoo/odoo/blob/9.0/openerp/models.py#L4114)
  44.  
  45.  
  46.  
  47. # for explaination: I have a default.project.task model, which stores templates for creating objects of model project.task.
  48. # Iam now in the method, which should create tasks(project.task) from default.tasks(default.project.task)
  49. # this method is called from an other model, which has a reference default_task_ids to model default.project.task
  50.  
  51.  
  52.     def create_tasks_from_default_tasks(self)
  53.         default_tasks = self.default_task_ids
  54.         task_model = self.env['project.task']
  55.         for default_task in in default_tasks:
  56.             vals = default_task.read()
  57.  
  58.             task_model.create(vals if not default_task.child_ids else vals.update({'child_ids': ##call this line recursive## for child in default_task.child_ids}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement