OColumn with odoo functional in Odoo Mobile Framework not working

本小妞迷上赌 提交于 2020-07-23 06:32:19

问题


I have this OColumn partner_name = new OColumn("Partner", OVarchar.class).setLocalColumn(); in my sale order model class with odoo functional method that depends on partner_id column. I would like to search the partner_name in my list using that column partner_name, but I'm a little confused on how to achieve this. Please needed some help.

This is what I've tried:

BaseFragment

  @Override
  public void onViewBind(View view, Cursor cursor, ODataRow row) {
      getPartnerIds(row);
      OControls.setText(view, R.id.partner_name,  row.getString("partner_name")); // displays false
      ....
    }
}

  private void getPartnerIds(ODataRow row){
      OValues oValues = new OValues();
      oValues.put("partner_id", row.get("partner_id"));
      saleOrder.storeManyToOne(oValues);
}

updated:

I noticed that even though I created

 @Odoo.Functional(method = "storeManyToOne", store = true, depends = {"partner_id"})
 OColumn partner_name = new OColumn("Partner", OVarchar.class).setLocalColumn();

no column was created.


回答1:


Define the partner_name field like below:

@Odoo.Functional(method="storePartnerName", store=true, depends={"partner_id"})
OColumn partner_name = new OColumn("Partner name", OVarchar.class)
                       .setLocalColumn();

public String storePartnerName(OValues values) {
    try {
        if (!values.getString("partner_id").equals("false")) {
            JSONArray partner_id = new JSONArray(values.getString("partner_id"));
            return partner_id.getString(1);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "false";
}

You can simply get the partner_name using:

row.getString("partner_name")

EDIT:

Note that database is created when you first time run your application, or when you clean your data from app setting. You need to clean application data everytime when you update your database column.

If the column was added after the database creation, it will not be added to the corresponding table. This is because the database is not upgraded. To fix this issue you can:

  • Clean application data to update your database column

  • Remove user account (This will delete database) or reinstall the application to recreate the database.

  • Or you can change DATABASE_VERSION in odoo/datas/OConstants then override onModelUpgrade method in sale order model and upgrade the table manually (alter sale order table and add the partner name column using SQL query: ALTER TABLE sale_order ADD partner_name VARCHAR(100)).
    When a new sale order is created and synchronized, the partner name should be computed and stored automaticaly.

    I noticed that the partner name was not set for existing records after synchrinization so I added another SQL query to compute and set the value of partner name for old records.

    Example:

      @Override
      public void onModelUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
              db.execSQL("ALTER TABLE sale_order ADD partner_name VARCHAR(100)");
              db.execSQL("UPDATE sale_order SET partner_name = (SELECT name from res_partner WHERE _id=partner_id) WHERE partner_name IS NULL AND partner_id IS NOT NULL");
      }
    


来源:https://stackoverflow.com/questions/62830462/ocolumn-with-odoo-functional-in-odoo-mobile-framework-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!