Odoo Help

0

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

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


1

Hilar

--Hilar--
1472
| 5 3 8
Rome, India
--Hilar--
  Blog:-
        https://hilarlive.wordpress.com/
  StackOverflow:
        http://stackoverflow.com/users/7561347/burmese-pythis
Hilar
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,
 })

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.

Register

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)

Stats

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