2017-11-05 7 views
1

私はOdoo v10を使用しています。バーコードをスキャンしているとき、文字列にはcharフィールド値の文字がいくつか含まれています。 Odoo v10のターゲットフィールド文字列の文字を含む文字列でレコードを検索するにはどうすればよいですか?

を行うための任意の方法があり、例えば、

  • フィールド値( 'tracknum')= "20171103"
  • が "xxxxxx20171103" または "xxxx20171103yyy" の文字列を入力してフィールドを検索しますそれ? 私は、検索ビューを変更した:

    <field name="tracknum" string="Tracknum" filter_domain="..."/> 
    

    enter image description here

    関連レコードを掘るためにどのように?

    enter image description here

+0

enter image description hereフィールド名に表示されます:... <フィールド名=「tracknum」文字列= "追跡番号" filter_domain = "...." />それを変更するための任意のアイデア? – cyliinhk

+0

Point of Saleモジュールを意味しますか? – ChesuCR

+0

は正確ではありません。一般的な検索に使用する必要があります。フィールドに格納されている値よりも長い文字列を入力しますが、その文字には単語が含まれています。私は、検索文字列でレコードを掘り起こすことを願っています。 – cyliinhk

答えて

1

あなたは、あなたは、このような検索ビューにこのフィールドを追加することができ、この

custom_name = fields.Char(
    string='Custom', 
    compute='_compute_custom_name', 
    search='_search_custom_name' 
) 

@api.multi 
@api.depends() 
def _compute_custom_name(self): 
    ''' The field has to be a computed field 
     You do not need to do anything here 
    ''' 
    pass  

def _search_custom_name(self, operator, value): 
    ''' Actually this converts a domain into another one. 
     With this new domain Odoo can search well 

     Arguments: 
      * operator: if you are searchig words it is going to be ilike 
      * value: the string ro search 

     The method could return something like this 
      * [('id', 'in', id_list)] 
    ''' 

    all_records = self.search([]) # recordset with all the values of the current model 
    ids = [] 
    if operator == 'ilike':    
     ids = all_records.filtered(lambda r: r.tracknum in value).mapped('id') 


    return [('id', 'in', ids)] 

ようAUXILIAR、計算フィールドを作成することができます。

<field name="custom_name" string="Tracking Number" /> 

そのことを覚えておいてくださいストアドフィールドではないため、非常に非効率的になります。また、検索を行うたびにすべての値を繰り返し処理する必要があります。

あなたは検索にフィールドを追加したら、それはこのようになりshoul表示、追跡番号はSearchView

+0

'は'適切なpostgresql構文ではありません。私はこれを試してみますが、エラーで失敗します。私は、PostgreSQLが文字列にマッチする%をチェックします。私は( 'tracknum'、 'in'、 '%' + self)を使用しても動作しませんが、エラーは発生しません。どのようなアイデアを改善する? – cyliinhk

+0

ああ、確かに、 'in'はリストのためだけです。利用可能なすべての演算子を[ここ](https://stackoverflow.com/questions/29442993/which-are-the-available-domain-operators-in-openerp-odoo)にチェックしてください。私はそれがPython演算子として動作すると思った – ChesuCR

+0

新しい答えが@cyliinhkに役立つかどうかを確認してください。検索方法がうまくいかない場合は、ダミーの計算フィールドを作成する必要があります – ChesuCR

関連する問題