如何在Odoo V8中更新所选行的目标位置

时间:2019-03-07 10:08:06

标签: javascript python function odoo odoo-8

我在Function 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;
   },
}); 
}

这是我的Class 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您要访问的文档之一已删除,请刷新后重试

我可以获取更多信息,谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我认为您不需要javascript,只需一个带有向导的小模块,仅使用python和xml编写即可。在Odoo本身的源代码中,您有很多作为示例,只需查找所使用的模型models.TransientModel。