如何取消联系'来自' Many2one'在Odoo的领域?

时间:2015-10-15 05:48:32

标签: openerp odoo odoo-8 openerp-8

任何链接到hr.employee或res.users的Many2one字段在Many2one下拉工具中显示值Home地址或联系人。有人建议如何阻止这个?

1 个答案:

答案 0 :(得分:1)

您可以使用域名过滤器来避免不必要的结果。

例如: - 在销售订单中我们只看到客户,虽然其相关对象是res.patner,因为域名过滤器(请参阅代码)

public class PrintDialogActivity extends Activity {
private static final String PRINT_DIALOG_URL = "https://www.google.com/cloudprint/dialog.html";
private static final String JS_INTERFACE = "AndroidPrintDialog";
private static final String CONTENT_TRANSFER_ENCODING = "base64";

private static final String ZXING_URL = "http://zxing.appspot.com";
private static final int ZXING_SCAN_REQUEST = 65743;

/**
 * Post message that is sent by Print Dialog web page when the printing
 * dialog needs to be closed.
 */
private static final String CLOSE_POST_MESSAGE_NAME = "cp-dialog-on-close";

/**
 * Web view element to show the printing dialog in.
 */
private WebView dialogWebView;

/**
 * Intent that started the action.
 */
Intent cloudPrintIntent;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.activity_print_dialog);
    dialogWebView = (WebView) findViewById(R.id.webview);
    cloudPrintIntent = this.getIntent();

    WebSettings settings = dialogWebView.getSettings();
    settings.setJavaScriptEnabled(true);

    dialogWebView.setWebViewClient(new PrintDialogWebClient());
    dialogWebView.addJavascriptInterface(
            new PrintDialogJavaScriptInterface(), JS_INTERFACE);

    dialogWebView.loadUrl(PRINT_DIALOG_URL);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == ZXING_SCAN_REQUEST && resultCode == RESULT_OK) {
        dialogWebView.loadUrl(intent.getStringExtra("SCAN_RESULT"));
    }
}

final class PrintDialogJavaScriptInterface {

    @JavascriptInterface
    public String getType() {
        return cloudPrintIntent.getType();
    }

    @JavascriptInterface
    public String getTitle() {
        return cloudPrintIntent.getExtras().getString("title");
    }

    @JavascriptInterface
    public String getContent() {
        try {
            ContentResolver contentResolver = getContentResolver();
            InputStream is = contentResolver
                    .openInputStream(cloudPrintIntent.getData());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            byte[] buffer = new byte[4096];
            int n = is.read(buffer);
            while (n >= 0) {
                baos.write(buffer, 0, n);
                n = is.read(buffer);
            }
            is.close();
            baos.flush();

            return Base64
                    .encodeToString(baos.toByteArray(), Base64.DEFAULT);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    @JavascriptInterface
    public String getEncoding() {
        return CONTENT_TRANSFER_ENCODING;
    }

    @JavascriptInterface
    public void onPostMessage(String message) {
        if (message.startsWith(CLOSE_POST_MESSAGE_NAME)) {
            finish();
        }
    }
}

private final class PrintDialogWebClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith(ZXING_URL)) {
            Intent intentScan = new Intent(
                    "com.google.zxing.client.android.SCAN");
            intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
            try {
                startActivityForResult(intentScan, ZXING_SCAN_REQUEST);
            } catch (ActivityNotFoundException error) {
                view.loadUrl(url);
            }
        } else {
            view.loadUrl(url);
        }
        return false;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        if (PRINT_DIALOG_URL.equals(url)) {
            // Submit print document.
            view.loadUrl("javascript:printDialog.setPrintDocument(printDialog.createPrintDocument("
                    + "window."
                    + JS_INTERFACE
                    + ".getType(),window."
                    + JS_INTERFACE
                    + ".getTitle(),"
                    + "window."
                    + JS_INTERFACE
                    + ".getContent(),window."
                    + JS_INTERFACE
                    + ".getEncoding()))");

            // Add post messages listener.
            view.loadUrl("javascript:window.addEventListener('message',"
                    + "function(evt){window." + JS_INTERFACE
                    + ".onPostMessage(evt.data)}, false)");
        }
    }
}
}

此处域名过滤器为“ domain =”[('customer','=',True)]“

即。仅显示客户字段的记录 True

从您的评论中: - 如果您只想查看系统用户,请使用 res.users 而不是 res.partner 。如: -

                            <field name="partner_id" on_change="onchange_partner_id(partner_id, context)" domain="[('customer','=',True)]" context="{'search_default_customer':1, 'show_address': 1}" options='{"always_reload": True}'/>

希望这有帮助。