Reputation: 3907
I need to load a sequence number in a specific field.
For this i'm using the ir.sequence
model, as i have seen in other modules.
Problem is , it is not working yet, i don't know what i'm doing wrong here, perhaps the examples i'm using just work for a "title" field?
This is my code:
... _name = "product.product"
_description = "Product"
_table = "product_product"
_inherits = {'product.template': 'product_tmpl_id'}
_inherit = ['mail.thread']
_order = 'default_code,name_template'
_columns = {
'codigo_n' : fields.char('Codigo Arancelario', size=64),
'tec_esp' : fields.char('Especificaciones tecnicas', size=72),
'qty_available': fields.function(_product_qty_available, type='float', string='Quantity On Hand'),
'virtual_available': fields.function(_product_virtual_available, type='float', string='Quantity Available'),
'incoming_qty': fields.function(_product_incoming_qty, type='float', string='Incoming'),
'outgoing_qty': fields.function(_product_outgoing_qty, type='float', string='Outgoing'), ... code keeps going...
Here the interesting field is codigo_n
whic is of type char
i added the _defaults
statement for this to work with ir.sequence
as follows:
_defaults = {
'codigo_n': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid,'product.product'),
}
Obviously i created the .xml sequence file, added to the data
dependencies in the __openerp__.py
file, and this is the code of the custom_sequence.xml
:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Secuencias para product.product -->
<record id="seq_type_product_product" model="ir.sequence.type">
<field name="name">Product</field>
<field name="code">product.product</field>
</record>
<record id="seq_product_product" model="ir.sequence">
<field name="name">Product</field>
<field name="code">product.product</field>
<field name="prefix">NG</field>
<field name="padding">5</field>
<field name="company_id" eval="False"/>
</record>
</data>
</openerp>
I think this is the correct way to setup this, i just need to make codigo_n
to work with this sequence, any ideas of why it is not working?
I hope i've explained myself.
Thanks in advance.
Upvotes: 0
Views: 1940
Reputation: 223
You can create a sequence dynamically in your module_name_view.xml using xml, it's a desired way to avoid manually creating dependents sequences during the module installation.
Here's the code to pute in your module_name_view.xml file :
<record forcecreate="1" id="seq_type_id" model="ir.sequence.type">
<field name="name">my_seq</field>
<field name="code">my_seq_code</field>
</record>
<record forcecreate="1" id="seq_id" model="ir.sequence">
<field name="name">my_seq</field>
<field name="code">my_seq_code</field>
<field name="prefix">SEQ_</field>
<field name="suffix"></field>
</record>
Good luck.
Upvotes: 2
Reputation: 416
One possibility I see is that you many not have the xml/module updated properly. Check "Settings / Technical / Sequences & Identifiers / Sequences" and look for the sequence you created.
Upvotes: 1