Skip to Content
Menu
This question has been flagged
1 Reply
8337 Views

0down votefavorite   
In my customization product price varies with respect to customer it works when add from products ,barcode , changing qty (numpad). After all orderlines are created if customer is change i want to reload all Lines


 var _super_orderline = models.Orderline;
 models.Orderline = models.Orderline.extend({
get_display_price: function(){    return custom_price;
}});


if order lines is created get_display_price , this doesn't work when changing customer ,


 save_changes: function(){    var self = this;
    var order = this.pos.get_order(); // got only client details }


How to reload orderlines when changing customer in POS ?

Avatar
Discard
Best Answer

Silviaa,

To reload all of you order lines, you need to write your customize functionality,

i also faced this scenario, so i have created one for me,

Whenever you select a client  from client widget, and click on 'Change Customer' you have to call this customized method(under click event of '.next' button of ClientListScreenWidget).

this.$('.next').click(function(){ var order = self.pos.get_order();

   self.save_changes();

   self.refresh_orderlines(order); //CUSTOMIZED METHOD

   self.gui.back(); // FIXME HUH ?

  });


And here is the method:

refresh_orderlines: function(order){

    var lines = jQuery.extend(true, {}, order['orderlines']['models']);    

     //looping through each line  

    $.each(lines, function(k, line){

         var my_prod = line['product'];

         order.select_orderline(line); 

         //simulating product click event and create new duplicate order line

         if ($(".product[data-product-id='"+my_prod['id']+"']").length == 0){             order.pos.gui.screen_instances.products.click_product(my_prod);

         }

         else{

             $(".product[data-product-id='"+my_prod['id']+"']").trigger('click');

         }

         //removing original order line

         line.set_quantity('remove');

  });

  //saving new created lines

  order.trigger('change');

 },


Hope it helps!

Avatar
Discard
Author

Yes it reload and add new lines but not removing (i.e) when changing customer am getting 2 lines

Author

I used to change quantity instead of triger product click

line.set_quantity(line['quantity']);

// $(".product[data-product-id='"+my_prod['id']+"']").trigger('click'); //line.set_quantity('remove');

Works for me. Thank you for idea

line.set_quantity('remove') should delete the current line for order, infact it totally depends on wat you exactly want to do... in my scenario i was to reset and recalculate many data, thats why i was creating new lines and removing old one.

You can go as per the one which suites you.

Thanks

Related Posts Replies Views Activity
3
Jul 17
15457
0
Dec 18
2030
1
Oct 18
5131
1
Nov 24
105
4
Oct 24
1423