Reputation: 11
I am working on student registration module. I want to to auto generate registration code and save it into database where as computed method having some issue. 1.. can't save Computed result in database. 2.. when i use store attribute with field and depends api then there is not increment in variable.
here is my code below.
reg_code = fields.Char(compute='code', string='Code', readonly=True)
@api.multi
def get_code(self):
count = 0
reg = "Reg #"
for record in self:
count += 1
record.reg_code = reg + " " + str(count)
if record.reg_code:
count += 1
record.reg_code = reg+" "+str(count)
else:
count += 1
record.reg_code = reg+" "+str(count)
Upvotes: 0
Views: 1237
Reputation: 931
You can use sequence in Odoo. find sequence in
Enable Active developer mode
Settings --> Sequence
Then add this code in your module:
change field as
reg_code = fields.Char(string='Code',required=True, copy=False, readonly=True, index=True, default= lambda self: self.env['ir.sequence'].next_by_code('student.registration'))
Create another xml file like if you want to create sequence by code.
shipping_sequence.xml
and add this code
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Sequences for student.registration -->
<record id="seq_student_registration" model="ir.sequence">
<field name="name">Student Registration</field>
<field name="code">student.registration</field>
<field name="prefix">Code-</field>
<field name="padding">1</field>
<field name="company_id" eval="False"/>
</record>
</data>
</odoo>
Upvotes: 0