【问题标题】:Sequence number in field - OpenErp字段中的序列号 - OpenErp
【发布时间】:2013-05-29 01:00:45
【问题描述】:

我需要在特定字段中加载序列号。

为此,我使用ir.sequence 模型,正如我在其他模块中看到的那样。

问题是,它还没有工作,我不知道我在这里做错了什么,也许我使用的示例只适用于“标题”字段?

这是我的代码:

... _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...

这里有趣的字段是codigo_n,其类型为char,我添加了_defaults 语句,以便与ir.sequence 一起使用,如下所示:

_defaults = {
    'codigo_n': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid,'product.product'),
}

显然我创建了.xml序列文件,添加到__openerp__.py文件中的data依赖,这就是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>

我认为这是设置它的正确方法,我只需要让codigo_n 来处理这个序列,关于它为什么不起作用的任何想法?

我希望我已经解释过了。

提前致谢。

【问题讨论】:

    标签: python orm module openerp


    【解决方案1】:

    您可以使用 xml 在 module_name_view.xml 中动态创建序列,这是避免在模块安装期间手动创建依赖序列的理想方法。

    这是要放入 module_name_view.xml 文件的代码:

    <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>
    

    祝你好运。

    【讨论】:

    • 已经解决了,但是所有新形式的问题解决总是有用的,非常感谢!
    【解决方案2】:

    我看到的一种可能性是你们很多人没有正确更新 xml/module。 检查“设置/技术/序列和标识符/序列”并查找您创建的序列。

    【讨论】:

    • 已解决,我不得不重新启动服务器,序列确实出现在“设置/技术/序列和标识符/序列”中,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    相关资源
    最近更新 更多