You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.9 KiB

  1. odoo.define('easy_my_coop.oe_easymy_coop', function (require) {
  2. $(document).ready(function () {
  3. "use strict";
  4. var ajax = require('web.ajax');
  5. $('.oe_easymy_coop').each(function () {
  6. var oe_easymy_coop = this;
  7. $('#share_product_id').change(function () {
  8. var share_product_id = $("#share_product_id").val();
  9. ajax.jsonRpc("/subscription/get_share_product", 'call', {
  10. 'share_product_id': share_product_id
  11. })
  12. .then(function (data) {
  13. $('#share_price').text(data[share_product_id].list_price);
  14. $('input.js_quantity').val(data[share_product_id].min_qty);
  15. $('input.js_quantity').change();
  16. var $share_price = $('#share_price').text()
  17. $('input[name="total_parts"]').val($('input.js_quantity').val()*$share_price);
  18. $('input[name="total_parts"]').change();
  19. });
  20. });
  21. $(oe_easymy_coop).on('click', 'a.js_add_cart_json', function (ev) {
  22. var $share_price = $('#share_price').text()
  23. var $link = $(ev.currentTarget);
  24. var $input = $link.parent().parent().find("input");
  25. var $input_total = $("div").find(".total");
  26. var min = parseFloat($input.data("min") || 1);
  27. var amount_max = parseFloat($('input[name="total_parts"]').data("max"));
  28. var quantity = ($link.has(".fa-minus").length ? -1 : 1) + parseFloat($input.val(),10);
  29. var total_part = quantity * $share_price;
  30. var quantity_max = amount_max / $share_price;
  31. $input.val(quantity > min ? (total_part <= amount_max ? quantity : quantity_max) : min);
  32. $input.change();
  33. $('input[name="total_parts"]').val($input.val()*$share_price);
  34. return false;
  35. });
  36. $(oe_easymy_coop).on('focusout', 'input.js_quantity', function (ev) {
  37. $('a.js_add_cart_json').trigger('click');
  38. });
  39. $('#share_product_id').trigger('change');
  40. $("[name='birthdate']").inputmask();
  41. });
  42. });
  43. });