Odoo Help

Welcome!

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

0

How to get database ID from XML ID in XML ?

By
elalaoui
on 5/16/15, 6:13 AM 2,381 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

--Temur--
2894
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
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.


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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