def _search_open_hours(self, operator, value): dt = fields.Datetime.now() - relativedelta(hours=value) d1, d2 = False, False if operator in ['<', '<=', '>', '>=']: d1 = [ '&', ('close_date', '=', False), ('create_date', expression.TERM_OPERATORS_NEGATION[operator], dt) ] d2 = [ '&', ('close_date', '!=', False), ('close_hours', operator, value) ] elif operator in ['=', '!=']: subdomain = [ '&', ('close_date', expression.TERM_OPERATORS_NEGATION[operator], dt), ('create_date', '>=', dt.replace(minutes=0, seconds=0, microseconds=0)), ('create_date', '<', dt.replace(minutes=59, seconds=59, microseconds=99)) ] if operator in expression.NEGATIVE_TERM_OPERATORS: subdomain = expression.distribute_not(subdomain) d1 = ['&', ('close_date', '=', False), subdomain] d2 = [ '&', ('close_date', '!=', False), ('close_hours', operator, value) ] return expression.OR([d1, d2])
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), ('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
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), ('team_id.team_type', '=', 'website'), ('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
def _search_pricing_type(self, operator, value): """ Search method for pricing_type field. This method returns a domain based on the operator and the value given in parameter: - operator = '=': - value = 'task_rate': [('sale_line_employee_ids', '=', False), ('sale_line_id', '=', False), ('allow_billable', '=', True)] - value = 'fixed_rate': [('sale_line_employee_ids', '=', False), ('sale_line_id', '!=', False), ('allow_billable', '=', True)] - value = 'employee_rate': [('sale_line_employee_ids', '!=', False), ('allow_billable', '=', True)] - value is False: [('allow_billable', '=', False)] - operator = '!=': - value = 'task_rate': ['|', ('sale_line_employee_ids', '!=', False), ('sale_line_id', '!=', False), ('allow_billable', '=', True)] - value = 'fixed_rate': ['|', ('sale_line_employee_ids', '!=', False), ('sale_line_id', '=', False), ('allow_billable', '=', True)] - value = 'employee_rate': [('sale_line_employee_ids', '=', False), ('allow_billable', '=', True)] - value is False: [('allow_billable', '!=', False)] :param operator: the supported operator is either '=' or '!='. :param value: the value than the field should be is among these values into the following tuple: (False, 'task_rate', 'fixed_rate', 'employee_rate'). :returns: the domain to find the expected projects. """ if operator not in ('=', '!='): raise UserError(_('Operation not supported')) if not ((isinstance(value, bool) and value is False) or (isinstance(value, str) and value in ('task_rate', 'fixed_rate', 'employee_rate'))): raise UserError(_('Value does not exist in the pricing type')) if value is False: return [('allow_billable', operator, value)] sol_cond = ('sale_line_id', '!=', False) mapping_cond = ('sale_line_employee_ids', '!=', False) if value == 'task_rate': domain = [ expression.NOT_OPERATOR, sol_cond, expression.NOT_OPERATOR, mapping_cond ] elif value == 'fixed_rate': domain = [sol_cond, expression.NOT_OPERATOR, mapping_cond] else: # value == 'employee_rate' domain = [sol_cond, mapping_cond] domain = expression.normalize_domain(domain) if operator != '=': domain.insert(0, expression.NOT_OPERATOR) domain = expression.distribute_not(domain) domain = expression.AND([domain, [('allow_billable', '=', True)]]) return domain
def _search_abandoned_cart(self, operator, value): website_ids = self.env['website'].search_read(fields=['id', 'cart_abandoned_delay', 'partner_id']) deadlines = [[ '&', '&', ('website_id', '=', website_id['id']), ('date_order', '<=', fields.Datetime.to_string(datetime.utcnow() - relativedelta(hours=website_id['cart_abandoned_delay'] or 1.0))), ('partner_id', '!=', website_id['partner_id'][0]) ] for website_id in website_ids] abandoned_domain = [ ('state', '=', 'draft'), ('order_line', '!=', False) ] abandoned_domain.extend(expression.OR(deadlines)) abandoned_domain = expression.normalize_domain(abandoned_domain) # 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