简体   繁体   English

如何从sale_order_line onchange方法获取sale_order.id? 在odoo 9

[英]How can I get the sale_order.id from sale_order_line onchange method? In odoo 9

I want to get the id value of sale.order from a sale.order.line onchange method. 我想从sale.order.line onchange方法获取sale.orderid值。

I have this code: 我有以下代码:

class SaleOrderLineExt(models.Model):
    _inherit = ['sale.order.line']

    @api.multi
    @api.onchange('my_field')
    def my_field_change(self):

        related_sale_order = self.order_id
        print 'related_sale_order: ', related_sale_order
        print 'related_sale_order.id: ', related_sale_order.id

But the output that I have is this: 但是我的输出是这样的:

related_sale_order: sale.order(<openerp.models.NewId object at 0x7f7566029810>,)
related_sale_order.id: <openerp.models.NewId object at 0x7f7566029810>

I can check other values of the sale order, but not the Id. 我可以检查销售订单的其他值,但不能检查ID。 Why is that and how can I get it? 为什么会这样,我如何得到它?

in onchange method the frame pass d dummy object that have the values in the view in order to get the original record you do : 在onchange方法中,在视图中具有值的帧传递d虚拟对象,以获取您执行的原始记录:

self._origin.related_sale_order.id

but you should keep in mind that the related sale order when you create a record is not yet saved in database you will keep getting the same result but in edit mode you will have the id. 但是,请记住,创建记录时相关的销售订单尚未保存在数据库中,您将获得相同的结果,但是在编辑模式下,您将拥有ID。

Hope this helps you. 希望这对您有所帮助。

Try This 尝试这个

class SaleOrderLineExt(models.Model):
    _inherit = ['sale.order.line']

    @api.multi
    @api.onchange('my_field')
    def my_field_change(self):

        related_sale_order = self.order_id.id
        print "related_sale_order " related_sale_order

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Odoo 8的sale.order.line中的onchange_product_id方法中添加功能? - How to add a functionality to onchange_product_id method in sale.order.line in Odoo 8? 我可以根据Odoo中的销售订单值隐藏销售订单行中的字段列吗? - Can i hide the field's column from Sale order line Based on sale order value In Odoo? 在其他 model [Odoo] 中获取带有 ID 的 sale.order - Get a sale.order with an ID in other model [Odoo] 如何根据 sale_order_line 中的自定义日期时间字段更新 stock_move 文档中的 date_expected 值 - How to update date_expected value in stock_move document based on custom datetime field in sale_order_line 如何计算odoo 13销售订单行上的字段? - how to compute field on odoo 13 sale order line? 如何以编程方式创建销售订单行 (Odoo 13) - How to programmatically create a sale order line (Odoo 13) 新的 orm 方法出现问题 AttributeError: 'sale.order.line' object has no attribute 'get' odoo - problem whit the new orm method AttributeError: 'sale.order.line' object has no attribute 'get' odoo 如何从sale.order.line发送自定义值到stock.move in odoo - how to send custom value from sale.order.line to stock.move in odoo 如何在Odoo v12中将数据从销售订单行发送到发票行? - How to send data from sale order line to invoice line in Odoo v12? 在Odoo中通过销售订单通知购买 - Notify purchases by Sale Order in Odoo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM