Commit 349a141a by Damien Moulard

BDM: increase member delay

parent 53918063
dev_cooperatic #5673_bug_calendrier_echange_service 4081 4444_improve_presence_recording 4709 4778-reception-dont-get-finished-orders 4809-remove-shelf-value-col-to-reduce-server-load 4880-rapports-reception-faux 4950-douchage-appli-reception 5474-et-5462-Voir-les-rattrapages-choisis-dans-admin-bdm-et-corrige-lenteur-affichage-admin-rattrapages 5641-reception-trier-a-la-maj-prix-dans-ordre-de-pointage-quantites 6286_bug_encaissement_souscription_cheque_espece 6813-marking-parent-gone-when-unpairing-binom-does-not-unsuscribe-parent-from-shift-template 6832--certaines-absences-engendrent-une-erreur 7723-7559-change-purchase-order-workflow-django-side 7731-third-party-side-brinks-pos-export-not-working 7747-inventaire-par-article 7800-make-test-solution-work 7848-cannot-validate-qty-with-decimal-on-kg-product adpatation_chouette assistance_import_article coop_dev_necessitant_modules_bdm_odoo_modifies correctif_nb_rattrapages_creation_binome_avec_ajout_automatique_au_point_negatif export_capital_detenu fix_bug_process_picking fusion_custom_graoucoop graoucoop_backup graoucoop_prod graoucoop_tmp hot_fix_shelf_labels_auto_print impression_etiquettes_rayons integration_lien_precommandes_dans_espace_membre lacagette_prod local_branch meal-voucher-and-label-printer-software-bug migration-v12 pour_graoucoop_prod pour_version_prod_cagette refonte_espace_membre_sc retouches_tickets_supercoop sc-setup-stock-app supercafoutch-preprod supercafoutch-prod-20221003 supercafoutch_prod ticket_4146 supercafoutch_20250120_151258 supercafoutch_20250120_150340 supercafoutch_20240909_080630 supercafoutch_20240609_115709 supercafoutch_20240212_082431 supercafoutch_20240107_181851 supercafoutch_prod_until_240107 supercafoutch-230911 supercafoutch-230824 supercafoutch-230823-the-true-one migration-v12-tag lacagette_20240310_074751 lacagette_20240107_122554 lacagette_20240107_120916 graoucoop_20240609_122614 cagette_testtag cagette-230814 cagette-230630
2 merge requests!2073817 bdm increase delay,!218Ticket 4292
Pipeline #2429 passed with stage
in 1 minute 26 seconds
......@@ -8,7 +8,7 @@ from members.models import CagetteMember
from shifts.models import CagetteServices
from shifts.models import CagetteShift
from outils.common import MConfig
from datetime import datetime
from datetime import datetime, date
default_msettings = {'msg_accueil': {'title': 'Message borne accueil',
'type': 'textarea',
......@@ -419,9 +419,28 @@ def regenerate_member_delay(request):
""" From BDM admin, close existing extension if exists & recreate for 6 months """
res = {}
is_connected_user = CagetteUser.are_credentials_ok(request)
if is_connected_user is True:
data = json.loads(request.body.decode())
print(data["member_id"])
raw_data = json.loads(request.body.decode())
# Close extension if has one
member_id = int(raw_data["member_id"])
cm = CagetteMember(member_id)
cm.close_extension()
# Recreate starting now
cs = CagetteShift()
data = {
"idPartner": member_id,
"start_date": date.today().isoformat()
}
duration = raw_data["duration"]
ext_name = "Délai étendue depuis l'admin BDM"
res["create_delay"] = cs.create_delay(data=data, duration=duration, ext_name=ext_name)
res["member_data"] = CagetteMembers.get_makeups_members([member_id])[0]
response = JsonResponse(res, safe=False)
else:
......
......@@ -1007,14 +1007,7 @@ class CagetteMember(models.Model):
if changing_shift is False:
# Close extensions if just unsubscribing, else keep it
c = [['partner_id', '=', self.id], ['date_start', '<=', now], ['date_stop', '>=', now]]
f = ['id']
res_ids = self.o_api.search_read("shift.extension", c, f)
ids = [d['id'] for d in res_ids]
if ids:
f = {'date_stop': now}
res["close_extensions"] = self.o_api.update('shift.extension', ids, f)
res["close_extensions"] = self.close_extension()
return res
......@@ -1035,6 +1028,20 @@ class CagetteMember(models.Model):
return res
def close_extension(self):
now = datetime.datetime.now().isoformat()
c = [['partner_id', '=', self.id], ['date_start', '<=', now], ['date_stop', '>=', now]]
f = ['id']
res_ids = self.o_api.search_read("shift.extension", c, f)
ids = [d['id'] for d in res_ids]
if ids:
f = {'date_stop': now}
return self.o_api.update('shift.extension', ids, f)
else:
return False
class CagetteMembers(models.Model):
"""Class to manage operations on all members or part of them."""
......@@ -1257,9 +1264,13 @@ class CagetteMembers(models.Model):
return res
@staticmethod
def get_makeups_members():
def get_makeups_members(ids=[]):
api = OdooAPI()
cond = [['makeups_to_do','>', 0]]
if len(ids) > 0:
cond.append(['id','in', ids])
fields = ['id', 'name', 'display_std_points', 'display_ftop_points', 'shift_type', 'makeups_to_do', 'date_delay_stop']
res = api.search_read('res.partner', cond, fields)
return res
......
......@@ -237,6 +237,7 @@ function display_makeups_members() {
const member = makeups_members.find(m => m.id == member_id);
let modal = $("#modal_extend_delay_template");
modal.find(".member_name").text(member.name);
openModal(
......@@ -322,13 +323,21 @@ function update_members_makeups(member_ids, action) {
/**
* Send request to extend the member's delay, or create one if none open.
* @param {Object} member
* @param {Object} member
*/
function extend_member_delay(member) {
openModal();
let today = new Date();
let today_plus_six_month = new Date();
today_plus_six_month.setMonth(today_plus_six_month.getMonth()+6);
const diff_time = Math.abs(today_plus_six_month - today);
const diff_days = Math.ceil(diff_time / (1000 * 60 * 60 * 24));
let data = {
member_id: member.id
member_id: member.id,
duration: diff_days
};
$.ajax({
......@@ -338,7 +347,11 @@ function extend_member_delay(member) {
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function() {
success: function(result) {
let i = makeups_members.findIndex(m => m.id == result.member_data.id);
makeups_members[i].date_delay_stop = result.member_data.date_delay_stop;
display_makeups_members();
closeModal();
},
......
......@@ -188,39 +188,39 @@ function set_subscription_area() {
retrieve_and_draw_shift_tempates({shift_listener: false});
$("#shifts_calendar_area").show();
// Cancel listeners from subscription page & set custom listeners
$(document).off("click", "#shifts_calendar_area button[data-select='Volant']");
$(document).on("click", "#shifts_calendar_area button[data-select='Volant']", function() {
// Subscribe to comitee/ftop shift
msg = (has_committe_shift === "True")
? `Inscrire ${selected_member.name} au service des Comités ?`
: `Inscrire ${selected_member.name} en Volant ?`;
openModal(
msg,
() => {
shift_subscrition(2);
},
"Confirmer",
false
);
});
$(document).off("click", ".shift");
$(document).on("click", ".shift", function() {
// Subscribe to shift template
let shift_template_id = select_shift_among_compact(null, this, false); // method from common.js
let shift_template_data = shift_templates[shift_template_id].data;// shift_templates: var from common.js
let shift_template_name = get_shift_name(shift_template_data);
openModal(
`Inscrire ${selected_member.name} au créneau ${shift_template_name} ?`,
() => {
shift_subscrition(1, parseInt(shift_template_id), shift_template_name);
},
"Confirmer",
false
);
});
// Cancel listeners from subscription page & set custom listeners
$(document).off("click", "#shifts_calendar_area button[data-select='Volant']");
$(document).on("click", "#shifts_calendar_area button[data-select='Volant']", function() {
// Subscribe to comitee/ftop shift
msg = (has_committe_shift === "True")
? `Inscrire ${selected_member.name} au service des Comités ?`
: `Inscrire ${selected_member.name} en Volant ?`;
openModal(
msg,
() => {
shift_subscrition(2);
},
"Confirmer",
false
);
});
$(document).off("click", ".shift");
$(document).on("click", ".shift", function() {
// Subscribe to shift template
let shift_template_id = select_shift_among_compact(null, this, false); // method from common.js
let shift_template_data = shift_templates[shift_template_id].data;// shift_templates: var from common.js
let shift_template_name = get_shift_name(shift_template_data);
openModal(
`Inscrire ${selected_member.name} au créneau ${shift_template_name} ?`,
() => {
shift_subscrition(1, parseInt(shift_template_id), shift_template_name);
},
"Confirmer",
false
);
});
}
......
......@@ -127,7 +127,7 @@ function create_new_coop() {
$('.chosen_associate_area').hide();
$('.member_choice').removeClass('choice_active');
$(".remove_binome_icon").on("click", hide_chosen_associate);
$('input[name="binome"]').prop('checked',false);
$('input[name="binome"]').prop('checked', false);
local_in_process = getLocalInProcess();
if (getLocalInProcess().length > 0) {
empty_waiting_local_processes();
......@@ -270,7 +270,7 @@ function store_new_coop(event) {
}
if ($('#associate_area').is(':visible')) {
// If user choose yes for binome, a type of association must be selected
// If user choose yes for binome, a type of association must be selected
let associated_data_selected = false;
if (
......
......@@ -318,7 +318,7 @@ class CagetteShift(models.Model):
coop_logger.error("Reopen shift : %s", str(e))
return response
def create_delay(self, data, duration=28):
def create_delay(self, data, duration=28, ext_name="Extension créée depuis l'espace membre"):
"""
Create a delay for a member.
If no duration is specified, a delay is by default 28 days from the given start_date.
......@@ -327,14 +327,16 @@ class CagetteShift(models.Model):
Else, create a 28 days delay.
Args:
idPartner: int
start_date: string date at iso format (eg. "2019-11-19")
Date from which the delay end date is calculated
(optionnal) extension_beginning: string date at iso format
If specified, will be the actual starting date of the extension.
Should be inferior than start_date.
(at creation only: odoo ignores delays if today's not inside)
data
idPartner: int
start_date: string date at iso format (eg. "2019-11-19")
Date from which the delay end date is calculated
(optionnal) extension_beginning: string date at iso format
If specified, will be the actual starting date of the extension.
Should be inferior than start_date.
(at creation only: odoo ignores delays if today's not inside)
duration: nb of days
ext_name: will be displayed in odoo extensions list
"""
action = 'create'
......@@ -392,7 +394,7 @@ class CagetteShift(models.Model):
"type_id": ext_type_id,
"date_start": starting_date.isoformat(),
"date_stop": ending_date.isoformat(),
"name": "Extension créée depuis l'espace membre"
"name": ext_name
}
response = self.o_api.create('shift.extension', fields)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment