Пример #1
0
    def write(self, vals):
        """
        Extends Odoo `write` method to manage the ``related_stage_id``
        changes.

        Non `queue` stages are not allowed to have a related stage.
        related_stage_id cannot be of `backlog` or `queue` type.
        """
        if vals.get('related_stage_id'):
            if self.browse(vals.get('related_stage_id')).stage_type in \
                    ['backlog', 'queue']:
                raise models.except_orm(
                    'Stage Type Error',
                    'related_stage_id cannot be of backlog or queue type')
            for stage in self:
                if stage.stage_type != 'queue':
                    raise models.except_orm(
                        'Stage Type Error',
                        'Only queue stages can have related_stage_id')
        stage_type = vals.get('stage_type')
        if stage_type:
            if stage_type != 'queue':
                vals['related_stage_id'] = False
            if stage_type in ['backlog', 'queue', 'done']:
                    vals['wip_limit'] = False
        if vals.get('wip_limit'):
            for stage in self:
                if stage.stage_type in ['backlog', 'queue', 'done']:
                    raise models.except_orm(
                        'Stage WIP Limit Error',
                        '{0} stages cannot have a WIP limit'.format(
                            stage.stage_type))
        return super(ProjectTaskTypeExtension, self).write(vals)
Пример #2
0
    def get_working_hours(self, date_start, date_end):
        """
        Computes the working hours between two given dates using the
        calendar information from the related project.

        Does not check if the dates are consistent with the task start
        and end dates.

        :param date_start: Start time
        :type date_start: datetime
        :param date_end: End time
        :type date_end: datetime
        :raises: `models.except_orm`
        :returns: working hours
        :rtype: int
        """
        if not isinstance(date_start, dt):
            raise models.except_orm(
                'Attribute Error',
                'expected datetime, received %s' % type(date_start))
        if not isinstance(date_end, dt):
            raise models.except_orm(
                'Attribute Error',
                'expected datetime, received %s' % type(date_end))
        if self.project_id and self.project_id.resource_calendar_id:
            return int(self.project_id.resource_calendar_id.get_working_hours(
                date_start, date_end)[0])
        else:
            return int((date_end - date_start).total_seconds() / 3600)
Пример #3
0
    def write(self, vals):
        """
        Extends Odoo `write` method to manage the ``related_stage_id``
        changes.

        Non `queue` stages are not allowed to have a related stage.
        related_stage_id cannot be of `backlog` or `queue` type.
        """
        if vals.get('related_stage_id'):
            if self.browse(vals.get('related_stage_id')).stage_type in \
                    ['backlog', 'queue']:
                raise models.except_orm(
                    'Stage Type Error',
                    'related_stage_id cannot be of backlog or queue type')
            for stage in self:
                if stage.stage_type != 'queue':
                    raise models.except_orm(
                        'Stage Type Error',
                        'Only queue stages can have related_stage_id')
        stage_type = vals.get('stage_type')
        if stage_type:
            if stage_type != 'queue':
                vals['related_stage_id'] = False
            if stage_type in ['backlog', 'queue', 'done']:
                vals['wip_limit'] = False
        if vals.get('wip_limit'):
            for stage in self:
                if stage.stage_type in ['backlog', 'queue', 'done']:
                    raise models.except_orm(
                        'Stage WIP Limit Error',
                        '{0} stages cannot have a WIP limit'.format(
                            stage.stage_type))
        return super(ProjectTaskTypeExtension, self).write(vals)
Пример #4
0
    def get_working_hours(self, date_start, date_end):
        """
        Computes the working hours between two given dates using the
        calendar information from the related project.

        Does not check if the dates are consistent with the task start
        and end dates.

        :param date_start: Start time
        :type date_start: datetime
        :param date_end: End time
        :type date_end: datetime
        :raises: `models.except_orm`
        :returns: working hours
        :rtype: int
        """
        if not isinstance(date_start, dt):
            raise models.except_orm(
                'Attribute Error',
                'expected datetime, received %s' % type(date_start))
        if not isinstance(date_end, dt):
            raise models.except_orm(
                'Attribute Error',
                'expected datetime, received %s' % type(date_end))
        if self.project_id and self.project_id.resource_calendar_id:
            return int(
                self.project_id.resource_calendar_id.get_working_hours(
                    date_start, date_end)[0])
        else:
            return int((date_end - date_start).total_seconds() / 3600)
Пример #5
0
    def create(self, vals):
        """
        Extends Odoo `create` method to do class of service checks.

        :param vals: values dictionary
        :type vals: dict
        :returns: ``project.task`` id
        :rtype: int
        """
        res = super(ProjectTaskExtension, self).create(vals)
        if vals.get('categ_ids'):
            tag_model = self.env['project.category']
            tags = tag_model.browse(vals.get('categ_ids')[0][2]) \
                if isinstance(vals.get('categ_ids')[0], (list, tuple)) \
                else tag_model.browse(vals.get('categ_ids'))
            if tags.cos_limit_overflow():
                raise models.except_orm(
                    'Class of Service Error!',
                    'Cannot create a new task with that class of service, the '
                    'maximum allowed amount has already been reached.')
            color = tags.get_cos_colour()
            if color:
                res.color = color
            tags.check_deadline_required(vals.get('date_deadline'))
        return res
Пример #6
0
 def create(self, vals):
     if vals.get('track_stage') and not vals.get('can_be_parent'):
         raise models.except_orm(
             'Class of Service Error!',
             'In order to track child tasks stages the Class of Service '
             'needs to be flagged as parent.')
     return super(ClassOfService, self).create(vals)
Пример #7
0
    def stage_working_hours(self, stage_id, date):
        """
        Computes the working hours spent in a given stage until a given
        date.

        :param stage_id: `project.task.type` id
        :type stage_id: int
        :param date: end date
        :type date: datetime
        :raises: `models.except_orm`
        :returns: working hours
        :rtype: int
        """
        if not isinstance(date, dt):
            raise models.except_orm(
                'Attribute Error',
                'expected datetime, received %s' % type(date))
        history_records = self.env['project.task.history'].search([
            ['task_id', '=', self.id], ['date', '<=', date.strftime(dtf)],
            ['type_id', '=', stage_id]],
            order='date asc')
        result = 0
        if history_records:
            result += sum([hr.working_hours for hr in history_records])
        if self.stage_id.id == stage_id:
            date_start = dt.strptime(history_records[-1].date, dtf) \
                if history_records \
                else dt.strptime(self.date_last_stage_update, dtf)
            return result + self.get_working_hours(date_start, date)[0]
        return result
Пример #8
0
 def create(self, vals):
     if vals.get('track_stage') and not vals.get('can_be_parent'):
         raise models.except_orm(
             'Class of Service Error!',
             'In order to track child tasks stages the Class of Service '
             'needs to be flagged as parent.')
     return super(ClassOfService, self).create(vals)
Пример #9
0
    def stage_working_hours(self, stage_id, date):
        """
        Computes the working hours spent in a given stage until a given
        date.

        :param stage_id: `project.task.type` id
        :type stage_id: int
        :param date: end date
        :type date: datetime
        :raises: `models.except_orm`
        :returns: working hours
        :rtype: int
        """
        if not isinstance(date, dt):
            raise models.except_orm(
                'Attribute Error',
                'expected datetime, received %s' % type(date))
        history_records = self.env['project.task.history'].search(
            [['task_id', '=', self.id],
             ['date', '<=', date.strftime(dtf)], ['type_id', '=', stage_id]],
            order='date asc')
        result = 0
        if history_records:
            result += sum([hr.working_hours for hr in history_records])
        if self.stage_id.id == stage_id:
            date_start = dt.strptime(history_records[-1].date, dtf) \
                if history_records \
                else dt.strptime(self.date_last_stage_update, dtf)
            return result + self.get_working_hours(date_start, date)[0]
        return result
Пример #10
0
    def write(self, vals):
        """
        Extends Odoo `write` method to do class of service checks.

        :param vals: values dictionary
        :type vals: dict
        :returns: True
        :rtype: bool
        """
        if 'can_be_parent' in vals and not vals.get('can_be_parent'):
            vals['track_stage'] = False
        elif vals.get('track_stage'):
            if not self.can_be_parent:
                raise models.except_orm(
                    'Class of Service Error!',
                    'In order to track child tasks stages the Class of '
                    'Service needs to be flagged as parent.')
        res = super(ClassOfService, self).write(vals)
        if vals.get('colour') or vals.get('priority'):
            tag_model = self.env['project.category']
            tags = tag_model.search([['cos_id', 'in', [c.id for c in self]]])
            task_model = self.env['project.task']
            tasks = task_model.search(
                [['categ_ids', 'in', [t.id for t in tags]]])
            color = tags.get_cos_colour()
            if color:
                tasks.write({'color': color})
        return res
Пример #11
0
    def write(self, vals):
        """
        Extends Odoo `write` method to do class of service checks.

        :param vals: values dictionary
        :type vals: dict
        :returns: True
        :rtype: bool
        """
        if 'can_be_parent' in vals and not vals.get('can_be_parent'):
            vals['track_stage'] = False
        elif vals.get('track_stage'):
            if not self.can_be_parent:
                raise models.except_orm(
                    'Class of Service Error!',
                    'In order to track child tasks stages the Class of '
                    'Service needs to be flagged as parent.')
        res = super(ClassOfService, self).write(vals)
        if vals.get('colour') or vals.get('priority'):
            tag_model = self.env['project.category']
            tags = tag_model.search([['cos_id', 'in', [c.id for c in self]]])
            task_model = self.env['project.task']
            tasks = task_model.search(
                [['categ_ids', 'in', [t.id for t in tags]]])
            color = tags.get_cos_colour()
            if color:
                tasks.write({'color': color})
        return res
Пример #12
0
    def create(self, vals):
        """
        Extends Odoo `create` method to do class of service checks.

        :param vals: values dictionary
        :type vals: dict
        :returns: ``project.task`` id
        :rtype: int
        """
        res = super(ProjectTaskExtension, self).create(vals)
        if vals.get('categ_ids'):
            tag_model = self.env['project.category']
            tags = tag_model.browse(vals.get('categ_ids')[0][2]) \
                if isinstance(vals.get('categ_ids')[0], (list, tuple)) \
                else tag_model.browse(vals.get('categ_ids'))
            if tags.cos_limit_overflow():
                raise models.except_orm(
                    'Class of Service Error!',
                    'Cannot create a new task with that class of service, the '
                    'maximum allowed amount has already been reached.')
            color = tags.get_cos_colour()
            if color:
                res.color = color
            tags.check_deadline_required(vals.get('date_deadline'))
        return res
Пример #13
0
    def write(self, vals):
        """
        Extends Odoo `write` method to log the Work In Progress per user
        when a task changes stage.

        It also records automatically the ``date_out`` of a task if
        the new stage is of type `done` and the ``date_in`` if a
        task is not type ``backlog`` and it doesn't have it already.

        :param vals: values dictionary
        :type vals: dict
        :returns: True
        :rtype: bool
        """
        if vals.get('stage_id'):
            self.filtered(
                lambda t:
                t.stage_id.stage_type == 'dev' and t.user_id
            ).user_id.add_finished_item()
            self.filtered(
                lambda t:
                t.stage_id.stage_type == 'analysis' and t.analyst_id
            ).analyst_id.add_finished_item()
            self.filtered(
                lambda t:
                t.stage_id.stage_type == 'review' and t.reviewer_id
            ).reviewer_id.add_finished_item()
            stage = self.env['project.task.type'].browse(vals.get('stage_id'))
            if stage.stage_type != 'backlog' and not self.date_in:
                vals['date_in'] = dt.now().strftime(dtf)
            if stage.stage_type == 'done' and not self.date_out:
                vals['date_out'] = dt.now().strftime(dtf)
        if vals.get('feature_id'):
            self.check_feature_id(vals.get('feature_id'))
        res = super(ProjectTaskExtension, self).write(vals)
        if vals.get('categ_ids'):
            tag_model = self.env['project.category']
            tags = tag_model.browse(vals.get('categ_ids')[0][2]) \
                if isinstance(vals.get('categ_ids')[0], (list, tuple)) \
                else tag_model.browse(vals.get('categ_ids'))
            if tags.cos_limit_overflow():
                raise models.except_orm(
                    'Class of Service Error!',
                    'Cannot link another task with that class of service, the '
                    'maximum allowed amount has already been reached.')
            color = tags.get_cos_colour()
            if color:
                self.color = color
            for task in self:
                tags.check_deadline_required(task.date_deadline)
        elif 'date_deadline' in vals:
            self.categ_ids.check_deadline_required(vals.get('date_deadline'))
        if vals.get('stage_id'):
            self.update_feature_stage_tracking()
        return res
Пример #14
0
    def write(self, vals):
        """
        Extends Odoo `write` method to log the Work In Progress per user
        when a task changes stage.

        It also records automatically the ``date_out`` of a task if
        the new stage is of type `done` and the ``date_in`` if a
        task is not type ``backlog`` and it doesn't have it already.

        :param vals: values dictionary
        :type vals: dict
        :returns: True
        :rtype: bool
        """
        if vals.get('stage_id'):
            self.filtered(lambda t: t.stage_id.stage_type == 'dev' and t.
                          user_id).user_id.add_finished_item()
            self.filtered(lambda t: t.stage_id.stage_type == 'analysis' and t.
                          analyst_id).analyst_id.add_finished_item()
            self.filtered(lambda t: t.stage_id.stage_type == 'review' and t.
                          reviewer_id).reviewer_id.add_finished_item()
            stage = self.env['project.task.type'].browse(vals.get('stage_id'))
            if stage.stage_type != 'backlog' and not self.date_in:
                vals['date_in'] = dt.now().strftime(dtf)
            if stage.stage_type == 'done' and not self.date_out:
                vals['date_out'] = dt.now().strftime(dtf)
        if vals.get('feature_id'):
            self.check_feature_id(vals.get('feature_id'))
        res = super(ProjectTaskExtension, self).write(vals)
        if vals.get('categ_ids'):
            tag_model = self.env['project.category']
            tags = tag_model.browse(vals.get('categ_ids')[0][2]) \
                if isinstance(vals.get('categ_ids')[0], (list, tuple)) \
                else tag_model.browse(vals.get('categ_ids'))
            if tags.cos_limit_overflow():
                raise models.except_orm(
                    'Class of Service Error!',
                    'Cannot link another task with that class of service, the '
                    'maximum allowed amount has already been reached.')
            color = tags.get_cos_colour()
            if color:
                self.color = color
            for task in self:
                tags.check_deadline_required(task.date_deadline)
        elif 'date_deadline' in vals:
            self.categ_ids.check_deadline_required(vals.get('date_deadline'))
        if vals.get('stage_id'):
            self.update_feature_stage_tracking()
        return res
Пример #15
0
    def check_deadline_required(self, deadline):
        """
        Raises exception if deadline is required but not provided or
        if deadline must be empty and is provided.

        :param deadline: is deadline provided or not.
        :type deadline: bool
        :returns: True
        :rtype: bool
        """
        if self.filtered(
                lambda c: c.cos_id and c.cos_id.deadline == 'required'):
            if not deadline:
                raise models.except_orm(
                    'Deadline required!',
                    'This class of service requires deadline to be '
                    'provided.')
        if self.filtered(lambda c: c.cos_id and c.cos_id.deadline == 'nodate'):
            if deadline:
                raise models.except_orm(
                    'Deadline must NOT exist!',
                    'This class of service requires deadline to be '
                    'empty.')
        return True
Пример #16
0
 def open_related_action(self, cr, uid, ids, context=None):
     """ Open the related action associated to the job """
     if hasattr(ids, '__iter__'):
         assert len(ids) == 1, "1 ID expected, got %s" % ids
         ids = ids[0]
     session = ConnectorSession(cr, uid, context=context)
     storage = OdooJobStorage(session)
     job = self.browse(cr, uid, ids, context=context)
     job = storage.load(job.uuid)
     action = job.related_action(session)
     if action is None:
         raise models.except_orm(
             _('Error'),
             _('No action available for this job'))
     return action
Пример #17
0
 def _get_journals(self):
     if self.env.context.get("active_model", False):
         active_model = self.pool.get("account.bank.statement").browse(self.env.cr, self.env.uid,
                                                                       self.env.context["active_id"])
         informal_journal = active_model.journal_id.informal_journal_id
         gastos_journal_id = active_model.journal_id.gastos_journal_id
         purchase_journal_id = active_model.journal_id.purchase_journal_id
         res = []
         res.append((informal_journal.id, informal_journal.name))
         res.append((gastos_journal_id.id, gastos_journal_id.name))
         res.append((purchase_journal_id.id, purchase_journal_id.name))
         if len(res) != 3:
             raise models.except_orm('Configuracion pendiente!',
                                     "Se deben configurar los diarios para este tipo de docuemnto.")
         return tuple(res)
Пример #18
0
    def check_feature_id(self, feature_id):
        """
        Checks if the feature_id can be linked to the tasks

        :param feature_id: ``project.task`` id
        :type feature_id: int
        :returns: True
        :rtype: bool
        """
        feature_tags = self.env['project.category'].search(
            [['cos_id.can_be_parent', '=', True]])
        feature_tasks = self.search(
            [['categ_ids', 'in', [tag.id for tag in feature_tags]]])
        feature_ids = [ft.id for ft in feature_tasks]
        if feature_id not in feature_ids:
            raise models.except_orm(
                'Class of Service Error!',
                'The task feature must be linked to a Feature Class of '
                'Service.')
        if any([t.id in feature_ids for t in self]):
            raise models.except_orm(
                'Class of Service Error!',
                'A feature tagged task cannot have a feature attached to it.')
        return True
Пример #19
0
    def check_deadline_required(self, deadline):
        """
        Raises exception if deadline is required but not provided or
        if deadline must be empty and is provided.

        :param deadline: is deadline provided or not.
        :type deadline: bool
        :returns: True
        :rtype: bool
        """
        if self.filtered(
                lambda c: c.cos_id and c.cos_id.deadline == 'required'):
            if not deadline:
                raise models.except_orm(
                    'Deadline required!',
                    'This class of service requires deadline to be '
                    'provided.')
        if self.filtered(lambda c: c.cos_id and c.cos_id.deadline == 'nodate'):
            if deadline:
                raise models.except_orm(
                    'Deadline must NOT exist!',
                    'This class of service requires deadline to be '
                    'empty.')
        return True
Пример #20
0
    def check_feature_id(self, feature_id):
        """
        Checks if the feature_id can be linked to the tasks

        :param feature_id: ``project.task`` id
        :type feature_id: int
        :returns: True
        :rtype: bool
        """
        feature_tags = self.env['project.category'].search(
            [['cos_id.can_be_parent', '=', True]])
        feature_tasks = self.search(
            [['categ_ids', 'in', [tag.id for tag in feature_tags]]])
        feature_ids = [ft.id for ft in feature_tasks]
        if feature_id not in feature_ids:
            raise models.except_orm(
                'Class of Service Error!',
                'The task feature must be linked to a Feature Class of '
                'Service.')
        if any([t.id in feature_ids for t in self]):
            raise models.except_orm(
                'Class of Service Error!',
                'A feature tagged task cannot have a feature attached to it.')
        return True
Пример #21
0
def set_gitlab_ci_conf(token, gitlab_url, runbot_domain, repo_id):
    if not token:
        raise models.except_orm(
            _('Error!'),
            _('Gitlab repo requires an API token from a user with '
              'admin access to repo.'))
    domain, name = get_gitlab_params(gitlab_url.replace(':', '/'))
    url = GITLAB_CI_SETTINGS_URL % (domain, quote_plus(name))
    project_url = "http://%s/gitlab-ci/%s" % (runbot_domain, repo_id)
    data = {
        "token": token,
        "project_url": project_url,
    }
    headers = {
        "PRIVATE-TOKEN": token,
    }
    requests.put(url, data=data, headers=headers)
Пример #22
0
def set_gitlab_ci_conf(token, gitlab_url, runbot_domain, repo_id):
    if not token:
        raise models.except_orm(
            _('Error!'),
            _('Gitlab repo requires an API token from a user with '
              'admin access to repo.')
        )
    domain, name = get_gitlab_params(gitlab_url.replace(':', '/'))
    url = GITLAB_CI_SETTINGS_URL % (domain, quote_plus(name))
    project_url = "http://%s/gitlab-ci/%s" % (runbot_domain, repo_id)
    data = {
        "token": token,
        "project_url": project_url,
    }
    headers = {
        "PRIVATE-TOKEN": token,
    }
    requests.put(url, data=data, headers=headers)
Пример #23
0
def _m2m_raise_or_create_relation(self, cr, f):
    """ Create the table for the relation if necessary.
    Return ``True`` if the relation had to be created.

    To support ordering, we create ``id`` column as SERIAL PRIMARY KEY.
    Thus, to return items in the order they were added we just ordered by id.
    SERIAL saves us from having to manually handle the sequence, while
    PRIMARY KEY is indexed, thus allows quick search, especially with LIMIT n.
    """
    m2m_tbl, col1, col2 = f._sql_names(self)
    col_id, pkey = ('id SERIAL NOT NULL, ', ' PRIMARY KEY(id),') if f._args.get('ordered') else ('', '')
    # do not create relations for custom fields as they do not belong to a module
    # they will be automatically removed when dropping the corresponding ir.model.field
    # table name for custom relation all starts with x_, see __init__
    if not m2m_tbl.startswith('x_'):
        self._save_relation_table(cr, m2m_tbl)
    cr.execute("SELECT relname FROM pg_class WHERE relkind IN ('r','v') AND relname=%s", (m2m_tbl,))
    if not cr.dictfetchall():
        if f._obj not in self.pool:
            raise except_orm('Programming Error', 'Many2Many destination model does not exist: `%s`' % (f._obj,))
        dest_model = self.pool[f._obj]
        ref = dest_model._table
        cr.execute('CREATE TABLE "%s" (%s"%s" INTEGER NOT NULL, "%s" INTEGER NOT NULL,%s UNIQUE("%s","%s"))' %
                   (m2m_tbl, col_id, col1, col2, pkey, col1, col2))
        # create foreign key references with ondelete=cascade, unless the targets are SQL views
        cr.execute("SELECT relkind FROM pg_class WHERE relkind IN ('v') AND relname=%s", (ref,))
        if not cr.fetchall():
            self._m2o_add_foreign_key_unchecked(m2m_tbl, col2, dest_model, 'cascade')
        cr.execute("SELECT relkind FROM pg_class WHERE relkind IN ('v') AND relname=%s", (self._table,))
        if not cr.fetchall():
            self._m2o_add_foreign_key_unchecked(m2m_tbl, col1, self, 'cascade')

        cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (m2m_tbl, col1, m2m_tbl, col1))
        cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (m2m_tbl, col2, m2m_tbl, col2))
        cr.execute("COMMENT ON TABLE \"%s\" IS 'RELATION BETWEEN %s AND %s'" % (m2m_tbl, self._table, ref))
        cr.commit()
        _schema.debug("Create table '%s': m2m relation between '%s' and '%s'", m2m_tbl, self._table, ref)
        return True
    if f._args.get('ordered'):
        cr.execute("SELECT 1 FROM information_schema.columns WHERE table_name='%s' AND column_name='id'" % (m2m_tbl,))
        if not cr.fetchall():
            cr.execute('ALTER TABLE "%s" ADD COLUMN id SERIAL PRIMARY KEY' % (m2m_tbl,))
Пример #24
0
    def _get_picking_in(self):
        obj_data = self.env['ir.model.data']
        type_obj = self.env['stock.picking.type']
        user_obj = self.env['res.users']
        company_id = user_obj.browse(self._uid).company_id.id

        # Fixed, @moreinfo, Tejas Tank
        pick_type = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)])
        pick_type = pick_type[0] if pick_type != [] else False

        if not pick_type:
            pick_type = type_obj.search([('code', '=', 'incoming')])
            pick_type = pick_type[0] if pick_type != [] else False

        if not pick_type:
            raise models.except_orm(_('Error!'), _("Make sure you have at least an incoming picking type defined"))

        # _logger.warning("elvenstudio_v8 _get_picking_in " + str(pick_type))

        return pick_type
Пример #25
0
    def write(self, vals):
        """
        Extends Odoo `write` method to do class of service checks.

        :param vals: values dictionary
        :type vals: dict
        :returns: True
        :rtype: bool
        """
        res = super(ProjectCategoryExtension, self).write(vals)
        if vals.get('cos_id'):
            if self.cos_limit_overflow():
                raise models.except_orm(
                    'Class of Service Error!',
                    'Cannot link another tag with that class of service, as '
                    'it would break the maximum task amount limit.')
            task_model = self.env['project.task']
            tasks = task_model.search(
                [['categ_ids', 'in', [c.id for c in self]]])
            color = self.get_cos_colour()
            if color:
                tasks.write({'color': color})
        return res
Пример #26
0
    def write(self, vals):
        """
        Extends Odoo `write` method to do class of service checks.

        :param vals: values dictionary
        :type vals: dict
        :returns: True
        :rtype: bool
        """
        res = super(ProjectCategoryExtension, self).write(vals)
        if vals.get('cos_id'):
            if self.cos_limit_overflow():
                raise models.except_orm(
                    'Class of Service Error!',
                    'Cannot link another tag with that class of service, as '
                    'it would break the maximum task amount limit.')
            task_model = self.env['project.task']
            tasks = task_model.search(
                [['categ_ids', 'in', [c.id for c in self]]])
            color = self.get_cos_colour()
            if color:
                tasks.write({'color': color})
        return res
Пример #27
0
    def _parse_vals(self, current_model):
        vals = {}
        for inv in self:
            journal_obj = self.env["account.journal"].browse(int(inv.journal_id))

            if not journal_obj.default_credit_account_id.id:
                raise models.except_orm('Configuracion pendiente!', "Se deben configurar las cuentas para este diario.")
            elif not inv.line_ids:
                raise models.except_orm('Registro sin productos!', "Debe de registrar por lo menos un producto.")

            ncf_required = True
            if journal_obj.ncf_special in ['gasto', 'informal']:
                ncf_required = False
            if ncf_required and not is_ncf(inv.ncf.encode("ascii")):
                raise models.except_orm(u"NCF Invalido!", u"El NCF del proveedor no es válido!")

            vals.update({
                u'account_id': self.partner_id.property_account_payable.id or self.journal_id.special_partner.property_account_payable.id,
                u'check_total': 0,
                u'child_ids': [[6, False, []]],
                u'comment': "Factura de caja chica",
                u'company_id': inv.company_id.id,
                u'currency_id': journal_obj.company_id.currency_id.id,
                u'date_due': False,
                u'date_invoice': self.date,
                u'fiscal_position': self.partner_id.property_account_position.id,
                u'internal_number': self.ncf,
                u'journal_id': int(self.journal_id.id),
                u'message_follower_ids': False,
                u'message_ids': False,
                u'name': False,
                u'ncf_required': ncf_required,
                u'origin': current_model.name,
                u'parent_id': False,
                u'partner_bank_id': False,
                u'partner_id': self.partner_id.id or self.journal_id.special_partner.id,
                u'payment_term': False,
                u'period_id': current_model.period_id.id,
                u'reference': self.ncf,
                u'reference_type': self.reference_type,
                u'supplier_invoice_number': False,
                u'tax_line': [],
                u'user_id': self.env.uid,
                u'pay_to': current_model.journal_id.pay_to.id,
                u'invoice_line': []
            })

            for line in inv.line_ids:
                line_list = [0, False]
                line_dict = {}
                line_dict.update({
                    u'account_analytic_id': False,
                    u'account_id': line.concept_id.account_expense.id,
                    u'asset_category_id': False,
                    u'discount': 0,
                    u'invoice_line_tax_id': [[6, False, [t.id for t in line.concept_id.supplier_taxes_id]]],
                    u'name': line.concept_id.name,
                    u'price_unit': abs(line.amount),
                    # u'product_id': line.concept_id.product_id.id,
                    u'quantity': 1,
                    u'uos_id': 1
                })
                line_list.append(line_dict)
                vals["invoice_line"].append(line_list)

        context = {u'default_type': u'in_invoice', u'journal_type': u'purchase'}

        result = self.env["account.invoice"].with_context(context).create(vals)
        return result
Пример #28
0
    def _parse_vals(self, current_model):
        vals = {}
        for inv in self:
            journal_obj = self.env["account.journal"].browse(
                int(inv.journal_id))

            if not journal_obj.default_credit_account_id.id:
                raise models.except_orm(
                    'Configuracion pendiente!',
                    "Se deben configurar las cuentas para este diario.")
            elif not inv.line_ids:
                raise models.except_orm(
                    'Registro sin productos!',
                    "Debe de registrar por lo menos un producto.")

            ncf_required = True
            if journal_obj.ncf_special in ['gasto', 'informal']:
                ncf_required = False
            if ncf_required and not is_ncf(inv.ncf.encode("ascii")):
                raise models.except_orm(u"NCF Invalido!",
                                        u"El NCF del proveedor no es válido!")

            vals.update({
                u'account_id':
                current_model.journal_id.default_credit_account_id.id,
                u'check_total':
                0,
                u'child_ids': [[6, False, []]],
                u'comment':
                "Factura de caja chica",
                u'company_id':
                inv.company_id.id,
                u'currency_id':
                journal_obj.company_id.currency_id.id,
                u'date_due':
                False,
                u'date_invoice':
                self.date,
                u'fiscal_position':
                self.partner_id.property_account_position.id,
                u'internal_number':
                self.ncf,
                u'journal_id':
                int(self.journal_id.id),
                u'message_follower_ids':
                False,
                u'message_ids':
                False,
                u'name':
                False,
                u'ncf_required':
                ncf_required,
                u'origin':
                current_model.name,
                u'parent_id':
                False,
                u'partner_bank_id':
                False,
                u'partner_id':
                self.partner_id.id or self.journal_id.special_partner.id,
                u'payment_term':
                False,
                u'period_id':
                current_model.period_id.id,
                u'reference':
                self.ncf,
                u'reference_type':
                self.reference_type,
                u'supplier_invoice_number':
                False,
                u'tax_line': [],
                u'user_id':
                self.env.uid,
                u'pay_to':
                current_model.journal_id.pay_to.id,
                u'invoice_line': []
            })

            for line in inv.line_ids:
                line_list = [0, False]
                line_dict = {}
                line_dict.update({
                    u'account_analytic_id':
                    False,
                    u'account_id':
                    line.concept_id.account_expense.id,
                    u'asset_category_id':
                    False,
                    u'discount':
                    0,
                    u'invoice_line_tax_id': [[
                        6, False,
                        [t.id for t in line.concept_id.supplier_taxes_id]
                    ]],
                    u'name':
                    line.concept_id.name,
                    u'price_unit':
                    abs(line.amount),
                    # u'product_id': line.concept_id.product_id.id,
                    u'quantity':
                    1,
                    u'uos_id':
                    1
                })
                line_list.append(line_dict)
                vals["invoice_line"].append(line_list)

        context = {
            u'default_type': u'in_invoice',
            u'journal_type': u'purchase'
        }

        result = self.env["account.invoice"].with_context(context).create(vals)
        return result