Odoo Help

0

How to get database ID from XML ID in XML ?

By
elalaoui
on 5/16/15, 6:13 AM 4,022 views

Hello ,

this is my code xml:

<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data noupdate="1">

<!-- Product Sequences -->

<record id="seq_type_ean13_sequence" model="ir.sequence.type">

<field name="name">EAN13 code</field>

<field name="code">product.ean13.code</field>

</record>

<record id="seq_ean13_sequence" model="ir.sequence">

<field name="name">Ean13 code</field>

<field name="code">product.ean13.code</field>

<field name="prefix">000000</field>

<field name="padding">6</field>

<field name="number_next">1</field>

</record>

</data>

</openerp>

and my code python:

class product_product(orm.Model):

_inherit = 'product.product'

_columns = {

'ean_sequence_id': fields.many2one('ir.sequence', 'Ean Sequence'),

}


 my question is :

how can i get the ID of ean_sequence_id from ID XML( seq_type_ean13_sequence)?

7.0, 8.0 ?

Temur
on 5/16/15, 6:16 AM

hello Temur, i want exectly to get a default value to ean_sequence_id by use id xml : class product_product(orm.Model): _inherit = 'product.product' _columns = { 'ean_sequence_id': fields.many2one('ir.sequence', 'Ean Sequence'), } _defaults = { 'ean_sequence_id': the default value }

elalaoui
on 5/18/15, 5:18 AM
1
Temur
On 5/16/15, 6:26 AM

seq_type_ean13_sequence is an ID as it may referred inside the same xml. from refer this ID externally, you'll need external ID. it means you've to prefix this id with it's module name and add a single dot, between module name and ID. then external id will become somthing like: module_name.seq_type_ean13_sequence

in v8.0 you lookup for a record corresponding of this xml id as follows: 

xml_record = self.env.ref("module_name.seq_type_ean13_sequence")

then xml_record.id should be database id.


About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/16/15, 6:13 AM
Seen: 4022 times
Last updated: 5/18/15, 5:18 AM