簡體   English   中英

如何在Odoo V8中更新所選行的目標位置

[英]How to update Destination Location of selected lines in Odoo V8

我在Python函數中遇到問題,無法更新交貨單中選定行的目標位置。

這是我的用於選擇行的javascript(在JS中,我稱之為update_locations()函數):

openerp.web_one2many_selectable = function(instance, m) 
{
var _t = instance.web._t,
    _lt = instance.web._lt;
QWeb = instance.web.qweb;

instance.web.form.widgets = instance.web.form.widgets.extend(
{
    'one2many_selectable' : 'instance.web.form.One2ManySelectable',
});

instance.web.form.One2ManySelectable = 
instance.web.form.FieldOne2Many.extend(
{
    multi_selection: true,
    start: function() 
    {
        this._super.apply(this, arguments);
        var self=this;
        self.on("change:effective_readonly", this, function(){
            if(this.get("effective_readonly"))
                self.$(".ep_button_confirm").attr("disabled", "");
            else
                self.$(".ep_button_confirm").removeAttr("disabled", "");
        });
        this.$el.prepend(QWeb.render("One2ManySelectable", {widget: this}));
        this.$el.find(".ep_button_confirm").click(function(){
            self.action_selected_lines();
        });
   },

   action_selected_lines: function()
   {
       var self=this;
       selected_ids=self.get_selected_ids_one2many();

        var model_obj=new instance.web.Model("stock.picking");
        model_obj.call('update_locations',
                    [selected_ids],{context:self.dataset.context})
        .then(function(result){
        });

   },
   get_selected_ids_one2many: function ()
   {
       var ids =[];
       this.$el.find('th.oe_list_record_selector input:checked')
               .closest('tr').each(function () {
                ids.push(parseInt($(this).context.dataset.id));
       });
       return ids;
   },
}); 
}

這是我的Python類(我認為問題出在update_locations()函數中):

from openerp import models, fields, api


class stock_picking(models.Model):
_inherit = 'stock.picking'

new_location_dest_id = fields.Many2one(
    'stock.location', 'Destination Location',
    readonly=True,
    states={
        'draft': [('readonly', False)],
        'waiting': [('readonly', False)],
        'confirmed': [('readonly', False)],
        },
    help="Location where the system will stock the finished products. This will be the default of the associated stock moves.")

@api.one
def update_locations(self):
    vals = {
        'location_dest_id': self.new_location_dest_id.id
        }
    self.move_lines.write(vals)

當我選擇一些行並指定位置目的地后,單擊更改目的地的按鈕。 出現消息錯誤:

Odoo MissingError您嘗試訪問的文檔之一已被刪除,請刷新后重試

我可以獲取更多信息,謝謝您的幫助。

我認為您不需要javascript,只需一個帶有向導的小模塊,僅使用python和xml編寫即可。 在Odoo本身的源代碼中,您有很多作為示例,只需查找所使用的模型models.TransientModel。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM