Odoo Help


How can i create auto increament(sequance) field in new api?

Apoorv Soral
on 11/18/16, 4:13 AM 730 views

class sales_auction(models.Model):

        _name = "sales.auction"

auction_id = fields.Char("Auction Number")

product_auc_id = fields.Many2one("product.product","Product")

start_auc_date = fields.Date("Auction Start Date")

end_auc_date = fields.Date("Auction End Date")

product_auc_id = fields.Many2one("product.product","Product")

initial_price = fields.Float("Minimum Price")

buy_now_price = fields.Float("Maximum Price")

no_of_bids = fields.Integer("No. of Bids Receive")

seller_name = fields.Char("Seller Name")

bid_multiples = fields.Integer("Bid Multiples")

state= fields.Selection([('draft','Draft'), ('confirm','Confirm'), ('done','Done') ],'Status',readonly=True,copy=False,select=True) customer_bid_id = fields.One2many("customer.auction","product_id","Customer")

@api.model def create(self, vals):

        vals['auction_id'] = self.env['ir.sequence'].get('sales.auction')

 return super(sales_auction, self).create(vals)

here i want to create auction_id it's auto increment field when create a record

id like =  AUC00001 , AUC00002. in this order

On 11/19/16, 1:17 AM

Check this example sequence generator



def create(self, vals):
        if vals.get('name', 'New') == 'New':
            vals['name'] = self.env['ir.sequence'].next_by_code('purchase.order') or '/'

            return super(PurchaseOrder, self).create(vals)


def _create_check_sequence(self):
""" Create a check sequence for the journal """
 self.check_sequence_id = self.env['ir.sequence'].sudo().create({
 'name': self.name + _(" : Check Number Sequence"),
 'implementation': 'no_gap',
 'padding': 5,
 'number_increment': 1,
 'company_id': self.company_id.id,

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/18/16, 4:13 AM
Seen: 730 times
Last updated: 11/19/16, 1:17 AM