【问题标题】:openerp XML RPC search by many2one idopenerp XML RPC 通过 many2one id 搜索
【发布时间】:2016-05-05 06:46:06
【问题描述】:

我目前正在使用 XMLRPC API 将网站连接到 openerp 。我们的想法是我们想从 openerp 获取最新的库存数量。目前我正在使用 this connector library 。这是来自我的 openerp api 的示例数据

[0] => Array
        (
            [create_date] => 2016-01-26 03:02:29
            [qty] => 6
            [propagated_from_id] => 
            [package_id] => 
            [cost] => 1500000
            [inventory_value] => 9000000
            [lot_id] => 
            [reservation_id] => 
            [id] => 2
            [negative_dest_location_id] => 
            [create_uid] => Array
                (
                    [0] => 1
                    [1] => Administrator
                )

            [display_name] => 17326: 6.0Unit(s)
            [__last_update] => 2016-01-26 03:02:29
            [location_id] => Array
                (
                    [0] => 19
                    [1] => Warehouse 1/Stock
                )

            [company_id] => Array
                (
                    [0] => 1
                    [1] => PT. ONE WAY
                )

            [history_ids] => Array
                (
                    [0] => 2
                )

            [owner_id] => 
            [write_date] => 2016-01-26 03:02:29
            [write_uid] => Array
                (
                    [0] => 1
                    [1] => Administrator
                )

            [name] => 17326: 6.0Unit(s)
            [product_id] => Array
                (
                    [0] => 2756
                    [1] => [17326]  AEG Vacuum Cleaner Dust Extractor Wet & Dry AP 20
                )

            [packaging_type_id] => 
            [negative_move_id] => 
            [in_date] => 2016-01-26 03:02:29
        )

如何按 product_id 过滤该数据

[product_id] => Array
                (
                    [0] => 2756
                    [1] => [17326]  AEG Vacuum Cleaner Dust Extractor Wet & Dry AP 20
                )

这是我的代码

$rpc = new OpenERP();

$x = $rpc->login("supermin", "my_site", "my_pass", "http://111.222.33.44:8069/xmlrpc/");

$data = $rpc->searchread(
    array(
        array("model", "=", "product.product"),
        array("module", "=", "sale"),
        array("product_id", "=", "2756"),
    ),
    "stock.quant"
);  

任何示例都会有所帮助。谢谢

【问题讨论】:

    标签: php api openerp xml-rpc


    【解决方案1】:

    尝试使用这个:

    //... your source
    $data = $rpc->searchread(
        array(
            array('model', '=', 'product.product'),
            array('module', '=', 'sale'),
            array('product_id', '=', '2756'),
        ),
        'stock.quant',
        array(), // default
        0, // default
        10, // default
        'product_id DESC' // default value was 'id DESC'
    );  
    

    我没有使用connector lib,但是如果我们检查searchread() method of OpenERP class,我们可以看到默认的$order = "id DESC"

    希望对您有所帮助。

    【讨论】:

    • 感谢代码示例,我正在使用此代码:$data = $rpc->searchread(array(array('product_id', '=', 2756)),"stock.quant ");其中 product_id 实际上是产品的变体 ID,因此您必须先获取产品变体 ID 才能在此搜索过滤器中使用,然后才能获取库存量化数据,
    • 我不明白。如我所见$model_name = 'stock.quant'。这意味着将在表stock_quant中搜索数据(Odoo对象stock.quant,我们可以在插件stock中看到默认列)。 stock.py 的此处列:'product_id': fields.many2one('product.product', 'Product', required=True, ondelete="restrict", readonly=True, select=True)。您想如何对数据进行排序?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多