Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added script to replace the contract payer by the owner #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions comer/mort_al_pagador/mata_el_pagador.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,43 @@ def get_polissa_ids_from_csv(filename):
return pol_ids


def kill_pagador(pol_ids):
pol_obj = O.GiscedataPolissa
partner_obj = O.ResPartner
partner_bank_obj = O.ResPartnerBank

for pol_id in pol_ids:
pol_vals = pol_obj.read(pol_id, ['titular', 'pagador', 'name'])

num_pol = pol_vals['name']
titular_id = pol_vals['titular'][0]
pagador_id = pol_vals['pagador'][0]

if titular_id == pagador_id:
warn("El titular i el pagador de la pòlissa són iguals per " + \
"la pòlissa {}".format(num_pol))
continue

try:
pbank_ids = partner_bank_obj.search([('partner_id','=',pagador_id)])
for pbank_id in pbank_ids:
partner_bank_obj.write(pbank_id, {'owner_id': pagador_id, 'partner_id': titular_id})
titular_address_id = partner_obj.address_get(titular_id)['default']
pol_obj.write(pol_id, {'pagador_sel': 'titular', 'pagador': titular_id,
'direccio_pagament': titular_address_id})
success("Pòlissa {} modificada correctament".format(num_pol))
except Exception as e:
error("Error al escriure els canvis per la pòlissa {}: {}".format(num_pol, str(e)))


if __name__ == '__main__':
args = parse_arguments()
O = connect_erp()

pol_ids = get_polissa_ids_from_csv(args.csv_file)
success("Extrets {} id's de polisses del csv", len(pol_ids))
kill_pagador(pol_ids)
success("Script finalitzat")


# vim: et ts=4 sw=4
8 changes: 8 additions & 0 deletions scriptlauncher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ gestiocontractes:
contracts:
type: FILE
description: Fitxer csv amb els nùmeros de contractes
killingPayer:
script: SOME_SRC/somenergia-scripts/comer/mort_al_pagador/mata_al_pagador.py --file {contracts} --doit
title: Script per matar el pagador (no utilitzar)
description: Agafa un fitxer csv amb els números de pòlissa i si el pagador és diferent al titular, posa el titular de pagador.
parameters:
contracts:
type: FILE
description: Fitxer csv amb els nùmeros de contractes
it:
description: Ronda IT
scripts:
Expand Down