I am trying to create a sequence that would be on the form_serial_no field of a formdownload model at the click of save button. This form_serial_no field will pick the company_short_code field of companyname model in the same models.py file and padded it with seven(7) digit number e.g CHN0000001 where CHN is the value of company_short_code field and 0000001 is the first sequence of the record. Below are my code snippets:
models.py code
class CompanyName(models.Model):
_name = 'companyname'
_rec_name = 'company_name'
company_name = fields.Char(string="Company Name", required=True)
company_short_code = fields.Char(string="Company short code", required=True)
class FormDownload(models.Model):
_name = 'formdownload'
name = fields.Many2one('companyname', string="Company Name", ondelete='cascade',
required=True)
form_serial_no = fields.Char(string="Form Serial No", readonly=True)
status = fields.Boolean(string="Status", default=False)
@api.model
def create(self, vals):
vals['form_serial_no'] = vals['name']
if vals:
vals['form_serial_no'] = self.env['ir.sequence'].get('formdownload')
return super(FormDownload, self).create(vals)
sequences.xml code
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Sequence for form download serial number -->
<record id="ref_code_form_serial_no" model="ir.sequence.type">
<field name="name">Sequence for form download serial number</field>
<field name="code">formdownload.form_serial_no</field>
</record>
<record id="seq_form_serial_no" model="ir.sequence">
<field name="name">Sequence for form download serial number</field>
<field name="code">formdownload.form_serial_no</field>
<field name="prefix">company_short_code</field>
<field name="padding">7</field>
<field name="company_id" eval="False"/>
</record>
</data>
</openerp>
When i check the formdownload table there is no record created for form_serial_no field. Kindly help me look into this.