Skip to content

Commit

Permalink
Merge pull request #700 from Som-Energia/add_current_modcon_to_wizard…
Browse files Browse the repository at this point in the history
…_k_change

allow current modcon
  • Loading branch information
pauboixsom authored Aug 1, 2024
2 parents 5f90703 + 199a083 commit bb51c82
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import logging
from oopgrade.oopgrade import load_data_records


def up(cursor, installed_version):
if not installed_version:
return

logger = logging.getLogger('openerp.migration')
logger.info("Updating XML wizard/wizard_massive_k_change.xml view")

data_records = ['view_wizard_massive_k_change_form']
load_data_records(
cursor, 'som_indexada', 'wizard/wizard_massive_k_change.xml', data_records, mode="update"
)
logger.info("View succesfully updated")


def down(cursor, installed_version):
pass


migrate = up
32 changes: 24 additions & 8 deletions som_indexada/wizard/wizard_massive_k_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,40 @@ def change_k_from_csv(self, cursor, uid, ids, context=None): # noqa: C901
polissa_obj.write(cursor, uid, polissa_id[0], vals_mod, context=context)
wz_crear_mc_obj = self.pool.get("giscedata.polissa.crear.contracte")
ctx = {"active_id": polissa_id[0]}
params = {
"duracio": "nou",
"accio": "nou",
}
if wiz_og.modcon_actual:
params = {
"duracio": "actual",
}
else:
params = {
"duracio": "nou",
"accio": "nou",
}
wiz_id = wz_crear_mc_obj.create(cursor, uid, params, context=ctx)
wiz = wz_crear_mc_obj.browse(cursor, uid, [wiz_id])[0]
res = wz_crear_mc_obj.onchange_duracio(
cursor, uid, [wiz.id], str(data_activacio), wiz.duracio, context=ctx
)
if res.get("warning", False):
polissa.send_signal("undo_modcontractual")
raise osv.except_osv("Error", res["warning"])
else:
if wiz_og.modcon_actual:
wiz.write(
{
"data_inici": str(data_activacio),
"data_final": str(data_activacio + timedelta(days=364)),
}
)
wiz.action_crear_contracte()
else:
if res.get("warning", False):
polissa.send_signal("undo_modcontractual")
raise osv.except_osv("Error", res["warning"])
else:
wiz.write(
{
"data_inici": str(data_activacio),
"data_final": str(data_activacio + timedelta(days=364)),
}
)
wiz.action_crear_contracte()
except Exception:
polissa.send_signal("undo_modcontractual")
failed_polisses.append(polissa.name)
Expand Down Expand Up @@ -220,13 +234,15 @@ def import_k_from_csv(self, cursor, uid, ids, context=None):
),
"pending_modcon": fields.boolean("Modcon pendent"),
"update_pricelist": fields.boolean("Actualitzar llista de preus"),
"modcon_actual": fields.boolean("Utilitza la modcon Actual"),
}

_defaults = {
"state": lambda *a: "init",
"process_type": _default_process_type,
"pending_modcon": lambda *a: False,
"update_pricelist": lambda *a: False,
"modcon_actual": lambda *a: False,
}


Expand Down
1 change: 1 addition & 0 deletions som_indexada/wizard/wizard_massive_k_change.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
string="Format del CSV: a la primera columna hi ha d'haver els números dels contractes, un a cada fila. Les següents columnes que hi hagi han de correspondre al valors K, D i H"
colspan="4" />
<field name="pending_modcon" colspan="4" string="Modcon Pendent" attrs="{'readonly':[('state','!=', 'init')]}"/>
<field name="modcon_actual" colspan="4" string="Modcon Actual" attrs="{'readonly':[('state','!=', 'init')]}"/>
<field name="update_pricelist" colspan="4" string="Actualitzar la llista de preus" attrs="{'readonly':[('state','!=', 'init')]}"/>
<button
attrs="{'invisible': [('state','!=', 'init')]}"
Expand Down

0 comments on commit bb51c82

Please sign in to comment.