0

I have a problem in the Function Python for updating the destination location of selected lines in a Delivery order.

This is my javascript for selecting lines (in the JS, i call the function 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;
   },
}); 
}

And here is my Class Python (I think the problem is in the function 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)

When i select some lines and specify the location destination and click on the button for changing destination. a Message Error Appears :

Odoo MissingError One of the documents you are trying to access has been deleted, please try again after refreshing

i'm available for more informations, Thank you for your help guys.

1 Answers1

0

I think that you do not need javascript, just a small module with a wizard, written using python and xml only. In the source code of Odoo itself you have a lot of them as examples, just look for the model used, models.TransientModel.

Victor G.
  • 121
  • 5