Beispiel #1
0
    def _check_quantity(self, active_model):
        '''Check for groups_id of uid and if it are not merger manager check limit
        quantity of objects to merge.

        '''
        if len(self._context.get('active_ids', [])) < 2:
            raise UserError(_('At less two items are necessary for merge.'))
        model = IrModel.sudo().search([('model', '=', active_model)], limit=1)
        if model and 0 < model.merge_limit < len(
                self._context.get('active_ids', [])):
            raise UserError(_('You can`t merge so much objects at one time.'))
        return True
Beispiel #2
0
 def action_merge(self):
     active_model = self._context.get('active_model')
     if not active_model:
         raise UserError(_('The is no active model defined!'))
     Model = self.env[active_model]
     sources = Model.browse(self._context.get('active_ids', []))
     attr = self._context.get('field_to_read')
     val = getattr(self, attr, None) if attr else None
     if not val:
         raise UserError(_('Please select one value to keep'))
     target = val[0]
     self.merge(sources, target)
     try:
         Model.read([])
         return target.get_formview_action()
     except AccessError:
         return CLOSE_WINDOW
    def merge(self):
        """Merge several `partners` into a single destination partner.

        Original `partners` will be removed from the DB afterwards.  Only
        target will remain.  All references to the original partners
        will be re-establish to the target partner.

        If `partners` constains less that 2 partners, do nothing.  All
        partners must have the same email.

        If sources `partner` is none, the target partner defaults to the last
        created record in `partners`.

        :param sources: The source partners.
        :type sources: A recordset of 'res.partners'.

        :param target: The target partner.
        :type target: A singleton recordset of 'res.partners' or None.

        """
        sources = self.partner_ids
        target = self.dest_partner_id
        if sources.sudo().exists() and len(sources) < 2:
            raise UserError(_("Constains less that 2 partners, do nothing"))
        partner_different_emails = {
            p.email
            for p in sources
            if p.email and p.email.strip()
        }
        if len(partner_different_emails) > 1:
            user = self.env.user
            if user.has_group('xopgi_partner_merge.base_parter_merger'):
                object_merger = self.env['object.merger']
                object_merger.merge(sources, target)
            else:
                raise UserError(
                    _("All contacts must have the same email. Only the "
                      "users with Partner Merge rights can merge contacts "
                      "with different emails.")
                )
        object_merger = self.env['object.merger']
        object_merger.merge(sources, target)
        self.unlink()
Beispiel #4
0
 def validate_type_alias(self, vals, use_lead, use_opportunity):
     alias = eval(vals['alias_defaults'])
     type_valias = alias.get('type', False)
     if not type_valias:
         return vals
     if use_lead is None:
         use_lead = self.use_leads
     if use_opportunity is None:
         use_opportunity = self.use_opportunities
     if not use_lead and type_valias == 'lead':
         raise UserError(
             _("This sale team not use 'Leads' then cant alias with "
               "'Lead'.  Please select the 'Leads' option from "
               "'Sales team'"))
     if not use_opportunity and type_valias == 'opportunity':
         raise UserError(
             _("This sale team not use 'Opportunities' then cant alias with "
               "'Opportunity' please select the Opportunities' option from "
               "'Sales team'."))
     return vals
Beispiel #5
0
    def _create_statement(self):
        '''Create a Bank Statement from payments.

        Each line in the statement will correspond to each payment (self).
        All lines will be conciliated with the corresponding payments.

        The statement is not completed to have starting/ending balances.

        '''
        payments = self.filtered(lambda p: p.should_reconcile_with_statement)
        if not payments:
            raise UserError(
                _("You must select at least a payment that needs reconciliation"
                  ))
        journal = payments.mapped('journal_id')
        if len(journal) > 1:
            raise UserError(
                _('You cannot create an statement from payments in different '
                  'journals.'))
        Statement = self.env['account.bank.statement']
        lines = payments._new_related_statement_lines()
        statement = Statement.create({
            'date':
            fields.Date.context_today(self),
            'state':
            'open',
            'name':
            _('New bank statement'),
            'journal_id':
            journal.id,
            'user_id':
            self.env.user.id,
            'line_ids':
            lines,
            'balance_start':
            Statement.with_context(
                default_journal_id=journal.id)._default_opening_balance()
        })
        statement.line_ids._reconcile_from_payments()
        statement.balance_end_real = statement.balance_end
        return statement
Beispiel #6
0
 def install_fuzzy_extension(self):
     try:
         # TODO: This is bound to fail if the user is not a
         # super-user... Check with the PostgreSQL documentation for
         # details.
         self._cr.execute('CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;')
     except Exception as error:
         _logger.error("%s", error)
         raise UserError(
             _('A required DB extension was not found. '
               'Ask your administrator to install '
               '"postgresql-contrib" package.'))
Beispiel #7
0
 def validate_model_project(self, vals, use_issue, use_task):
     """Validate that when creating a mail_alias within a project is not
        created or modified with a model (Task, Issues) without being
        defined for that project that can use Task and Issues.
     """
     model_id = vals.get('alias_model_id', False)
     if not model_id:
         return vals
     if use_issue is None:
         use_issue = self.use_issues
     if use_task is None:
         use_task = self.use_tasks
     if not use_issue and model_id == _get_model_ids(
             self, ['project.issue']).id:
         raise UserError(
             _("This project not use 'Issues' then cant alias with 'project.issue'"
               " please select the 'Isuues option' from the project form."))
     if not use_task and model_id == _get_model_ids(self,
                                                    ['project.task']).id:
         raise UserError(
             _("This project not use 'Tasks' then cant alias with 'project.task'"
               " please select the 'Tasks option' from the project form."))
     return vals