Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequnces (auto increment a field) #305

Open
JennaVenka opened this issue Jan 17, 2017 · 2 comments
Open

Sequnces (auto increment a field) #305

JennaVenka opened this issue Jan 17, 2017 · 2 comments

Comments

@JennaVenka
Copy link

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

@jiangzhixiao
Copy link

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
Copy link
Author

JennaVenka commented Feb 25, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants