Odoo Help

Welcome!

This community 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.

0

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

By
Apoorv Soral
on 11/18/16, 4:13 AM 181 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


0

Hilar AK

--Hilar AK--
778
| 4 1 7
Italy
--Hilar AK--


Hilar AK
On 11/19/16, 1:17 AM

Check this example sequence generator

1.

@api.model

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)

2.

@api.one
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,
 })

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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