hello, lately i have successfully get the auto number. now. everytime i create a new record then im going to cancel then create a new one again the auto number is continiuosly add. what i want is everytime i click create button then i need to exit then add again. i want it to become a efault or back to the original number. can anyone help me please? for example. the new number is SN/00001 on the field if ever im going to exit it should be go back in SN/00001. Please help me.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilité
- Inventaire
- PoS
- Project
- MRP
Cette question a été signalée
Well good example for your problem is in two common odoo modules: sales orders and invoices...
Sales orders : takes next sequence number on object create ( every created order get its own sequence number)
Invoices : on create default value for number is '/' (or draft) and only when you validate invoice it triggers wkf activity and gets the next sequence number.. .
Wise thing is to decide in wich exact moment the sequence needs to be assigned...
As i can see, you need invoice - like beahviour, that assignes number but not until you are sure in all the data...
Check methods in those two modules and you will soon find the correct way to use sequences
may the source be with you !
can you give those code or step by step to do it? or i mean the codes to add on my code so that everytime i cancel the transaction it will go back to the original number and not continuously increment.
Hello,
You can override create method and call super method for the same, when it returns an id for record at successful creation of record, you can generate sequence and then update the last record with sequence id.
Thanks,
Ishwar Malvi
i need the code please. or the example code. i am newbie in openerp
def create(self, cr, uid, vals, context=None): ir_sequence_obj = self.pool.get('ir.sequence') cur_id = super(model_name, self).create(cr, uid, vals, context=context) if cur_id: self.write(cr, uid, cur_id, {'auto_num': ir_sequence_obj.get(cr, uid, 'seq_object_name')}, context=context) somekind of code you need to achieve this. thanks, Ishwar Malvi
Here I define a custom module code sample you can use any of your custom field....
--------define your model here-------
class----(--)
_columns={
'installment_number':fields.char('ID',readonly=True),
-------------first override create method
def create(self, cr, uid, vals, context=None):
vals['installment_number'] = self.pool.get('ir.sequence').get(cr, uid,'lending.info')
return super(lending_info, self).create(cr, uid, vals, context=context)
----------------
}
_defaults={
'installment_number': lambda obj, cr, uid, context: '/',
}
define .xml file for auto increment //auto_id.xml
<openerp><data noupdate="1"><!-- Sequences for loan_id --><record id="seq__loan_code_inh1" model="ir.sequence.type"><field name="name">Lending info1 ID</field><field name="code">lending.info</field></record>
<record id="seq_cloan_code_inh2" model="ir.sequence"><field name="name">Lending info1 ID</field><field name="code">lending.info</field><field name="prefix">LN</field><field name="padding">2</field></record></data></openerp>
check openerp.py,init.py also
Thanks
Libu
hello, can you give the code to add? because i successfully done already with the auto increment because my only problem is just everytime i create then cancel it or not save it. it will go back to the default number since i didnt save the record. thanks
def create(self, cr, uid, vals, context=None): vals['installment_number'] = self.pool.get('ir.sequence').get(cr, uid,'lending.info') return super(lending_info, self).create(cr, uid, vals, context=context)
the installment_number and the lending_info where did you get that? and where im going to insert this code?
the installment_number and the lending_info where did you get that? and where im going to insert this code?
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrire