如何在方法中设置条件并在 python 中的另一个方法中调用其输出?

how to set conditions in a method and call its output in another one in python?

我正在编写一口很长的代码,所以我需要尽可能缩短它

在我的代码中有很多在某些情况下要做什么 这是一个简短的例子

@api.multi
def product_summary_test(self):
    product_summary_dict = {}
    data = []

    if self.date_from and self.date_to and self.pos_config:
        order_detail = self.env['pos.order'].search([('date_order', '>=', self.date_from),
                                                     ('date_order', '<=', self.date_to),
                                                     ('config_id', '=', self.pos_config.id)])
   do something with order_detail....

   if self.date_from and self.date_to and self.pos_config:
        order_detail = self.env['pos.order'].search([('date_order', '>=', self.date_from),
                                                     ('date_order', '<=', self.date_to)])
   do the same something with order_detail......
    
   if  not nself.date_from and not self.date_to and self.pos_config:
        order_detail = self.env['pos.order'].search([('config_id', '=', self.pos_config.id)])
   
   also do the the same with order_detail......

所以唯一的事情是在每个条件下发生变化,return是我正在处理的数据 如果重复它正在服用

那么我怎样才能在每个条件下创建另一个 return order_detail 的方法,我只是在我的方法上调用它 returned 值以避免重复

我提出一个答案:

def product_summary_test(self):
    product_summary_dict = {}
    data = []
    
    dom = []
    
    if self.date_from:
        dom.append(('date_order', '>=', self.date_from))
    if self.date_to:
        dom.append(('date_order', '<=', self.date_to))
    if self.pos_config:
        dom.append(('config_id', '=', self.pos_config.id))
        
    order_detail = self.env['pos.order'].search(dom)
    #do something with order_detail....