From 63dcfd44dedeeee5216a944437d2f65ad76a62d6 Mon Sep 17 00:00:00 2001 From: Fran Cubero Date: Tue, 15 Oct 2024 17:27:59 +0200 Subject: [PATCH 01/21] Initial wizard commit Co-authored-by: Pere Montagud Ferragud --- som_auvidi/__terp__.py | 3 ++ som_auvidi/security/ir.model.access.csv | 4 ++ som_auvidi/tests/__init__.py | 0 som_auvidi/wizard/__init__.py | 1 + .../wizard_change_to_indexada_auvidi_multi.py | 54 +++++++++++++++++++ ...wizard_change_to_indexada_auvidi_multi.xml | 45 ++++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 som_auvidi/security/ir.model.access.csv create mode 100644 som_auvidi/tests/__init__.py create mode 100644 som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.py create mode 100644 som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.xml diff --git a/som_auvidi/__terp__.py b/som_auvidi/__terp__.py index 2b6cc8ce5..5fdd4d015 100644 --- a/som_auvidi/__terp__.py +++ b/som_auvidi/__terp__.py @@ -10,6 +10,7 @@ "base", "giscedata_serveis_generacio", "giscedata_polissa_category", + "som_indexada", ], "init_xml": [], "demo_xml": [], @@ -17,6 +18,8 @@ "giscedata_polissa_view.xml", "giscedata_serveis_generacio_data.xml", "giscedata_serveis_generacio_view.xml", + "wizard/wizard_change_to_indexada_auvidi_multi.xml", + "security/ir.model.access.csv", ], "active": False, "installable": True, diff --git a/som_auvidi/security/ir.model.access.csv b/som_auvidi/security/ir.model.access.csv new file mode 100644 index 000000000..24d3d1ccc --- /dev/null +++ b/som_auvidi/security/ir.model.access.csv @@ -0,0 +1,4 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_wizard_change_to_indexada_auvidi_multi_r","wizard.change.to.indexada.auvidi.multi","model_wizard_change_to_indexada_auvidi_multi","giscedata_serveis_generacio.group_serveis_generacio_r",1,0,0,0 +"access_wizard_change_to_indexada_auvidi_multi_rcw","wizard.change.to.indexada.auvidi.multi","model_wizard_change_to_indexada_auvidi_multi","giscedata_serveis_generacio.group_serveis_generacio_w",1,1,1,0 +"access_wizard_change_to_indexada_auvidi_multi_rcwd","wizard.change.to.indexada.auvidi.multi","model_wizard_change_to_indexada_auvidi_multi","giscedata_serveis_generacio.group_serveis_generacio_u",1,1,1,1 diff --git a/som_auvidi/tests/__init__.py b/som_auvidi/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/som_auvidi/wizard/__init__.py b/som_auvidi/wizard/__init__.py index 12f5403ba..800098eb7 100644 --- a/som_auvidi/wizard/__init__.py +++ b/som_auvidi/wizard/__init__.py @@ -1,3 +1,4 @@ # -*- encoding: utf-8 -*- from __future__ import absolute_import from . import wizard_load_servei_gen_records_from_file +from . import wizard_change_to_indexada_auvidi_multi diff --git a/som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.py b/som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.py new file mode 100644 index 000000000..65617a579 --- /dev/null +++ b/som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +from osv import osv, fields + + +class WizardChangeToIndexadaAuvidiMulti(osv.osv_memory): + + _name = "wizard.change.to.indexada.auvidi.multi" + + def change_to_indexada_auvidi_multi(self, cursor, uid, ids, context=None): + if context is None: + context = {} + + wiz_og = self.browse(cursor, uid, ids[0], context=context) + + pol_ids = context.get("active_ids") + wz_chng_to_indx_obj = self.pool.get("wizard.change.to.indexada") + pol_obj = self.pool.get("giscedata.polissa") + failed_polisses = [] + for pol_id in pol_ids: + ctx = { + "active_id": pol_id, + "business_pricelist": wiz_og.pricelist.id, + "coeficient_k": wiz_og.coeficient_k, + } + params = {"change_type": "from_period_to_index"} + wiz_id = wz_chng_to_indx_obj.create(cursor, uid, params, context=ctx) + wiz = wz_chng_to_indx_obj.browse(cursor, uid, [wiz_id])[0] + try: + wz_chng_to_indx_obj.change_to_indexada(cursor, uid, [wiz.id], context=ctx) + except Exception: + pol_name = pol_obj.read(cursor, uid, pol_id, ["name"]) + failed_polisses.append(pol_name["name"]) + + info = "" + if failed_polisses: + info += "\nLes pòlisses següents han fallat: {}".format(str(failed_polisses)) + if not failed_polisses: + info = "Procés acabat correctament!" + + wiz_og.write({"state": "end", "info": info}) + + _columns = { + "state": fields.selection([("init", "Init"), ("end", "End")], "State"), + "info": fields.text("Description"), + "pricelist": fields.many2one("product.pricelist", "Tarifa"), + "coeficient_k": fields.float("Coeficient K", digits=(9, 3)), + } + + _defaults = { + "state": lambda *a: "init", + } + + +WizardChangeToIndexadaAuvidiMulti() diff --git a/som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.xml b/som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.xml new file mode 100644 index 000000000..35bf1fde6 --- /dev/null +++ b/som_auvidi/wizard/wizard_change_to_indexada_auvidi_multi.xml @@ -0,0 +1,45 @@ + + + + + wizard.change.to.indexada.auvidi.multi.form + wizard.change.to.indexada.auvidi.multi + form + +
+ + + + + +