Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # inherited Object https://github.com/odoo/odoo/blob/9.0/openerp/models.py
- class PlustronProjectTask(models.Model):
- _name = 'default.project.task'
- _order = 'sequence'
- name = fields.Char('Name')
- description = fields.Text('Description', required=True)
- sequence = fields.Integer('Sequence', select=True, help="Gives the sequence order when displaying a list of tasks.",
- default=10, required=True)
- tag_ids = fields.Many2many('project.tags', string='Tags', oldname='categ_ids')
- notes = fields.Text('Notes')
- @api.constrains('planned_hours')
- def constrain_planned_hours(self):
- if self.planned_hours <= 0.00:
- raise ValidationError(_('You have not planned time for that task!'))
- planned_hours = fields.Float('Initially Planned Hours',
- help='Estimated time to do the task, usually set by the project manager '
- 'when the task is in draft state.', required=True)
- user_id = fields.Many2one('res.users', 'Assigned to', select=True, required=True)
- child_ids = fields.Many2many('default.project.task', 'default_project_task_parent_rel', 'parent_id', 'task_id',
- 'Delegated Tasks', domain=lambda self: [('id', '!=', self.id)])
- parent_id = fields.Many2one('default.project.task', 'Parent Tasks', domain=lambda self: [('id', '!=', self.id)])
- color = fields.Integer('Color Index', default=1)
- attachment_ids = fields.One2many('ir.attachment', 'res_id', domain=lambda self: [('res_model', '=', self._name)],
- auto_join=True, string='Attachments')
- displayed_image_id = fields.Many2one('ir.attachment',
- domain="[('mimetype', 'ilike', 'image')]", string='Displayed Image')
- product_id = fields.Many2one('product.product', 'Product for Sale',
- help="If account generated invoices from tasks this is the product")
- company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.user.company_id, required=True)
- type = fields.Selection(
- [('recruiting', 'Recruiting'), ('office', 'Office')],
- 'Type',
- help="Task type",
- default="office"
- )
- # def create(https://github.com/odoo/odoo/blob/9.0/openerp/models.py#L4114)
- # for explaination: I have a default.project.task model, which stores templates for creating objects of model project.task.
- # Iam now in the method, which should create tasks(project.task) from default.tasks(default.project.task)
- # this method is called from an other model, which has a reference default_task_ids to model default.project.task
- def create_tasks_from_default_tasks(self)
- default_tasks = self.default_task_ids
- task_model = self.env['project.task']
- for default_task in in default_tasks:
- vals = default_task.read()
- 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