我正在开发基于Odoo框架的android应用程序。当用户选择称为补偿的休假类型时,我需要显示“补偿休假”字段,这是“多对多”字段类型。
我尝试了一些代码,但是当我将“多对多”字段绑定到XML时遇到错误:
这是我在xml中尝试过的代码
<odoo.controls.OField
android:id="@+id/com_off_ids"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
app:fieldName="compoff_ids"
app:fieldTextAppearance="?android:textAppearanceMedium"/>
这是HrHolidays的odoo模型
OColumn employee_id = new OColumn("Employee", HrEmployee.class, OColumn.RelationType.ManyToOne);
OColumn department_id = new OColumn("Department", HrDepartment.class, OColumn.RelationType.ManyToOne);
OColumn company_id = new OColumn("Company", ResCompany.class, OColumn.RelationType.ManyToOne);
OColumn holiday_type = new OColumn("Mode", OSelection.class).addSelection("employee", "By Employee").addSelection("category", "By Employee Tag");
OColumn type = new OColumn("Type", OSelection.class).addSelection("remove", "Remove").addSelection("add", "Add").setDefaultValue("remove");
@Odoo.Domain("[['line_id', '=', @leave_year_id]]")
@Odoo.onChange(method = "partnerIdOnChange")
OColumn holiday_status_id = new OColumn("Leave Type", HrHolidayStatus.class, OColumn.RelationType.ManyToOne);
OColumn leave_year_id = new OColumn("Leave Year", LeaveYear.class, OColumn.RelationType.ManyToOne);
OColumn compoff_ids = new OColumn("",CompLeaveRel.class, OColumn.RelationType.ManyToMany).setRelBaseColumn("leave_id").setRelRelationColumn("comp_id").setRelTableName("comp_leave_rel");
上面的代码“ Compoff_ids”字段中是“多对多”字段,我需要存储这些值。
这是CompLeaveRel模型字段
OColumn name = new OColumn("", OVarchar.class);
OColumn leave_id = new OColumn("", OVarchar.class);
OColumn comp_id = new OColumn("",OVarchar.class);
这是我将OColum绑定到XML小部件时遇到的错误:
java.lang.NullPointerException: Attempt to invoke virtual method 'int odoo.controls.OField$FieldType.ordinal()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int odoo.controls.OField$FieldType.ordinal()' on a null object reference
任何人都可以告诉我如何在odoo移动框架中使用和获取多对多字段的数据。
自从过去两天以来,我一直在这里被封锁
对不起,我的英语。
答案 0 :(得分:0)
您可以将列定义为:
OColumn column_name = new OColumn("Description", table_name.class, OColumn.RelationType.ManyToMany);
,并使用与CRM应用中相同的结构来显示一个one2many字段(ExpandableListControl及其Adapter)或类似简单标签的内容。