Odoo-mobile / framework

Odoo Mobile Framework
https://play.google.com/store/apps/dev?id=8607973775002477408
Other
327 stars 374 forks source link

One2Many field not created #290

Open jiangzhixiao opened 7 years ago

jiangzhixiao commented 7 years ago

i define a field called staffs in Department model. OColumn staffs= new OColumn("Staff",Staff.class, OColumn.RelationType.OneToMany) .setRelatedColumn("staff_id"); when runs app,in sqlite there is no column called staffs.but other columns was created. any one can give me an answer,best regards!

dpr-odoo commented 7 years ago

@jiangzhixiao

One2many field; the value of such a field is the records of all the records in comodel_name such that the field inverse_name is equal to the current record.

comodel_name: target model inverse_name: name of the inverse Many2one field in comodel_name

OneToMany is virtual column and it will not created in table columns.

As in your sample code, If Department holds staffs as oneToMany column of Staff model, then in Staff model there must be ManyToOne field reference to the department_id which you have to add in setRelatedColumn("department_id") of OneToMany field in Department model


// for department model
class Department extends OModel {
     ....
    // you can create one to many only if this model's reference (many to one) exists in relation model
    OColumn staffs= new OColumn("Staff",Staff.class, OColumn.RelationType.OneToMany)
        .setRelatedColumn("department_id");
}

// for staff model
class Staff extends OModel {
     ....
    OColumn department_id= new OColumn("Department",Department.class, OColumn.RelationType.ManyToOne);
}

Note: for oneToMany columns, if there is no any column exists on Odoo Server, than you have to create that column local only by calling chain method setLocalColumn() Ref: http://mobile.odoo.co.in/v2/getting-started/working-with-odoo-mobile/components/base-classes.html#setlocalcolumn

For getting staff detail from department, browse or select record of department and just call chain method as:


Department department = new Department(context,null);
ODatarow row = depeartment.browse(2);

List<ODataRow> staffs = row.getO2MRecord("staffs").browseEach();
jiangzhixiao commented 7 years ago

@dpr-odoo hi, dpr-odoo, sorry for my late reply,and thank you for your patience and help. here is another question.

i create two models,Department & Staff in odoo 9.0. with the same field and relation as defined in app,when i create a department with two staffs. eg: i create a department "Sales" which has two employee john &mike. now table department has a record called sales ,and another two records john & mike in table staff.

for sync the data between app and odoo server. i do some work in the app 1.Define a Provider called DepartmentProvider

  1. Define a service called DepartmentService
  2. Define provider an service in AndroidMainfest.xml

    so i run the app. but unfortunately, only the department data was synced from odoo server to app the staff did not synced

    Question1:For sync staff data,s if i have to define the staff provider & service ,just do three step above? in my opinion when the department synced ,the staff data should be synced automaticaly. Question2:How to call a method on odoo server?there has a create method in department.py

 @api.model
   def create(self, vals):
        if vals.get('name', 'New') == 'New':
           vals['name'] = self.env['ir.sequence'].next_by_code('department') or '/'
        return super(Department, self).create(vals)

Thanks for your reply again,Best wishes to you @drp-odoo 💯

jiangzhixiao commented 7 years ago

@dpr-odoo hi,sorry to trouble you,can you help me out with my issue?i can't login my stackoverflow now. i define a method called get_order_no on odoo 10

    @api.one
    @api.returns('self')
    def get_order_no(self):
        order_no = self.env['ir.sequence'].next_by_code('car.seat')
        return order_no

then i call it on mobile side,here is code

 ServerDataHelper helper = getServerDataHelper();
 OArguments oArguments = new OArguments();
 oArguments.add(new JSONArray().put(2));
 Object billno = helper.callMethod("get_order_no", oArguments);

finaly i got an exception from odoo 10. 170108027 is generated by next_by_code method

 TypeError:Mixing apples and oranger:car.seat().concat(170108027)

a strange thing is only first time call the get_order_no method success. when i debug the app again,can't call success,even not go into breakpoint in get_order_no method. only when i reinstall the app.the method can be called with the error above. thanks Dharmang Soni.

joseluiselp commented 7 years ago

Getting same error, any updates on this?