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 to add product internal reference as prefix to sequence Serial Number?

By
Alaa Alnajjar
on 6/27/16, 7:33 AM 344 views

Is there away to add product's internal reference as prefix to a sequence? more specifically, sequence "Serial Number"?

Details: 

In Manufacturing a product and clicking on button "Produce", user must create a new LOT for manufactured product, this is the screen of creating new LOT, notice that Serial Number is generated automatically :


I want to customise the format of this serial number to be i.e : CO-0000039 , CO is the internal reference of Cookies in the example above, but for another product it could be PO-0000039 or NU-00000039...etc, which means sequence of serial number must be dynamic and reads product internal reference, I opened the edit form of sequence "Serial Number" which I think this is the one the system is using,but I couldn't figure out what to type in Prefix? how to do that??


0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 6/28/16, 1:24 AM

Sure you can do it, at the time of creating you can set the prefix or suffix to the sequence based on your preference.

Look at the below code, I have done the Prefix for my logic, you may refer the same do it for yours.


@api.model

def _generate_Sequence(self, vals):

    cr, context = self._cr, self._context

    refNo = ''

    sale_type = vals.get('sale_type', '')

    if sale_type == 'quote': refNo += 'CQ-'

    else: refNo += 'SO-'

    cr.execute(""" select id from sale_order where name ilike '""" + str(refNo) + """%'

        order by to_number(substr(name,(length('""" + str(refNo) + """')+1)),'9999999999')

        desc limit 1

        """)

    rec = cr.fetchone()

    if rec:

        case = self.sudo().browse(rec[0])

        auto_gen = case.name[len(refNo) : ]

        refNo = refNo + str(int(auto_gen) + 1).zfill(5)

    else:

        refNo = refNo + '00001'

return refNo


I'm familiar with development but not sure where to use/write this kind of code, I'm guessing you're overriding the sequence method? I can't find this method in the source code, any help in this regard would be great, thanks!

Alaa Alnajjar
on 6/28/16, 8:15 AM

This method is written by me, you will never find it any of standard module, you call this method in Create method of ur object.

deep
on 6/29/16, 4:29 AM

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: 6/27/16, 7:33 AM
Seen: 344 times
Last updated: 6/30/16, 9:14 AM