コード例 #1
0
ファイル: sale_order.py プロジェクト: sheetal4123/flectra
 def _search_abandoned_cart(self, operator, value):
     abandoned_delay = self.website_id and self.website_id.cart_abandoned_delay or 1.0
     abandoned_datetime = fields.Datetime.to_string(datetime.utcnow() - relativedelta(hours=abandoned_delay))
     abandoned_domain = expression.normalize_domain([
         ('date_order', '<=', abandoned_datetime),
         ('website_id', '!=', False),
         ('state', '=', 'draft'),
         ('partner_id', '!=', self.env.ref('base.public_partner').id),
         ('order_line', '!=', False)
     ])
     # is_abandoned domain possibilities
     if (operator not in expression.NEGATIVE_TERM_OPERATORS and value) or (operator in expression.NEGATIVE_TERM_OPERATORS and not value):
         return abandoned_domain
     return expression.distribute_not(['!'] + abandoned_domain)  # negative domain
コード例 #2
0
ファイル: sale_order.py プロジェクト: yemanadep/Flectra
 def _search_abandoned_cart(self, operator, value):
     abandoned_delay = float(self.env['ir.config_parameter'].sudo().get_param('website_sale.cart_abandoned_delay', '1.0'))
     abandoned_datetime = fields.Datetime.to_string(datetime.utcnow() - relativedelta(hours=abandoned_delay))
     abandoned_domain = expression.normalize_domain([
         ('date_order', '<=', abandoned_datetime),
         ('team_id.team_type', '=', 'website'),
         ('state', '=', 'draft'),
         ('partner_id.id', '!=', self.env.ref('base.public_partner').id),
         ('order_line', '!=', False)
     ])
     # is_abandoned domain possibilities
     if (operator not in expression.NEGATIVE_TERM_OPERATORS and value) or (operator in expression.NEGATIVE_TERM_OPERATORS and not value):
         return abandoned_domain
     return expression.distribute_not(abandoned_domain)  # negative domain
コード例 #3
0
    def _compute_domain(self, model_name, mode="read"):
        if mode not in self._MODES:
            raise ValueError('Invalid mode: %r' % (mode, ))

        if self._uid == SUPERUSER_ID:
            return None

        query = """ SELECT r.id FROM ir_rule r JOIN ir_model m ON (r.model_id=m.id)
                    WHERE m.model=%s AND r.active AND r.perm_{mode}
                    AND (r.id IN (SELECT rule_group_id FROM rule_group_rel rg
                                  JOIN res_groups_users_rel gu ON (rg.group_id=gu.gid)
                                  WHERE gu.uid=%s)
                         OR r.global)
                """.format(mode=mode)
        self._cr.execute(query, (model_name, self._uid))
        rule_ids = [row[0] for row in self._cr.fetchall()]
        if not rule_ids:
            return []

        # browse user and rules as SUPERUSER_ID to avoid access errors!
        eval_context = self._eval_context()
        user_groups = self.env.user.groups_id
        global_domains = []  # list of domains
        group_domains = []  # list of domains
        for rule in self.browse(rule_ids).sudo():
            # evaluate the domain for the current user
            dom = safe_eval(rule.domain_force,
                            eval_context) if rule.domain_force else []
            dom = expression.normalize_domain(dom)
            if not rule.groups:
                global_domains.append(dom)
            elif rule.groups & user_groups:
                group_domains.append(dom)

        # combine global domains and group domains
        if not group_domains:
            return expression.AND(global_domains)
        return expression.AND(global_domains + [expression.OR(group_domains)])
コード例 #4
0
ファイル: ir_rule.py プロジェクト: sheetal4123/flectra
    def _compute_domain(self, model_name, mode="read"):
        rules = self._get_rules(model_name, mode=mode)
        if not rules:
            return

        # browse user and rules as SUPERUSER_ID to avoid access errors!
        eval_context = self._eval_context()
        user_groups = self.env.user.groups_id
        global_domains = []                     # list of domains
        group_domains = []                      # list of domains
        for rule in rules.sudo():
            # evaluate the domain for the current user
            dom = safe_eval(rule.domain_force, eval_context) if rule.domain_force else []
            dom = expression.normalize_domain(dom)
            if not rule.groups:
                global_domains.append(dom)
            elif rule.groups & user_groups:
                group_domains.append(dom)

        # combine global domains and group domains
        if not group_domains:
            return expression.AND(global_domains)
        return expression.AND(global_domains + [expression.OR(group_domains)])
コード例 #5
0
def is_true_domain(domain):
    return normalize_domain(domain) == TRUE_DOMAIN
コード例 #6
0
ファイル: ir_rule.py プロジェクト: sheetal4123/flectra
 def is_failing(r, ids=for_records.ids):
     dom = safe_eval(r.domain_force, eval_context) if r.domain_force else []
     return Model.search_count(expression.AND([
         [('id', 'in', ids)],
         expression.normalize_domain(dom)
     ])) < len(ids)