Odoo-mobile / framework

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

Sequnces (auto increment a field) #305

Open JennaVenka opened 7 years ago

JennaVenka commented 7 years ago

Hello, how to auto increment a field with a prefix ?

jiangzhixiao commented 7 years ago

you should call a method from odoo server.

  1. you can use createOnServer method,in fact this method will call create method on odoo server side. create() method will create a prefix value, just like bill_no = PO20170225001
  2. you can use getBillNoFromServer to get the generated bill_no.
    public String getBillNoFromServer(Integer serverId) {
        ODomain domain = new ODomain();
        domain.add("id", "=", serverId);
        OdooFields fields = new OdooFields();
        fields.addAll(new String[]{"name"});
        OdooResult result = getServerDataHelper().read(fields, serverId);
        String billNo = "false";
        if (result != null && result.has("name")) {
            billNo = result.getString("name");
        }
        return billNo;
    }

    odoo server code

      @api.model
    def create(self, vals):
        if not vals.get('name') or vals.get('name', 'New'):
            vals['name'] = self.env['ir.sequence'].next_by_code('seq_bill_no') or '/'
        record = super(Order, self).create(vals)
        return record
JennaVenka commented 7 years ago

Hello is there any code or sample where i can insert data with the framwork?

Thank you.

On 25 Feb 2017 18:47, "jiangzhixiao" notifications@github.com wrote:

you should call a method from odoo server.

  1. you can use createOnServer method,in fact this method will call create method on odoo server side. create() method will create a prefix value, just like bill_no = PO20170225001
  2. you can use getBillNoFromServer to get the generated bill_no.

public String getBillNoFromServer(Integer serverId) { ODomain domain = new ODomain(); domain.add("id", "=", serverId); OdooFields fields = new OdooFields(); fields.addAll(new String[]{"name"}); OdooResult result = getServerDataHelper().read(fields, serverId); String billNo = "false"; if (result != null && result.has("name")) { billNo = result.getString("name"); } return billNo; }

odoo server code

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Odoo-mobile/framework/issues/305#issuecomment-282488439, or mute the thread https://github.com/notifications/unsubscribe-auth/AVWl8egjVipGW0mpGRd0M68CMD856dAvks5rgD8FgaJpZM4Llklo .