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

Leads: Entitats i Empreses Firma de Signaturit #822

Open
wants to merge 1 commit into
base: main
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
1 change: 1 addition & 0 deletions som_leads_polissa/__terp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"giscedata_crm_leads",
"giscedata_crm_importador",
"som_polissa",
"giscedata_crm_leads_signatura"
],
"init_xml": [],
"demo_xml": [],
Expand Down
39 changes: 39 additions & 0 deletions som_leads_polissa/giscedata_crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,40 @@ class GiscedataCrmLead(osv.OsvInherits):

_inherit = "giscedata.crm.lead"

def get_contract_template_from_delivery_type(
self, cursor, uid, lead_id, delivery_type='email', context=None
):
'''
Returns powersms or poweremail template depending on delivery type
'''
if context is None:
context = context
imd_obj = self.pool.get('ir.model.data')
crm_lead_type = self.read(
cursor, uid, lead_id, ['crm_lead_type']
)['crm_lead_type']
is_renovation = crm_lead_type == 'renovation'
if delivery_type == 'sms':
tmpl_id = imd_obj.get_object_reference(
cursor, uid, 'giscedata_crm_leads_signatura',
'alta_lead_signatura_sms'
)[1]
elif delivery_type == 'email' and not is_renovation:
# Obtenim el valor del camp many2one signature_template_id
lead = self.browse(cursor, uid, lead_id, context=context)
tmpl_id = lead.signature_template_id.id
elif is_renovation:
tmpl_id = imd_obj.get_object_reference(
cursor, uid, 'giscedata_crm_leads_signatura',
'renovacio_lead_signatura'
)[1]
else:
tmpl_id = imd_obj.get_object_reference(
cursor, uid, 'giscedata_crm_leads_signatura',
'alta_lead_signatura'
)[1]
return tmpl_id

def contract_pdf(self, cursor, uid, ids, context=None):
if context is None:
context = {}
Expand Down Expand Up @@ -132,6 +166,11 @@ def onchange_set_custom_potencia(self, cursor, uid, ids, set_custom_potencia):
"preu_fix_potencia_p4": fields.float("Preu Fix Potència P4", digits=(16, 6)),
"preu_fix_potencia_p5": fields.float("Preu Fix Potència P5", digits=(16, 6)),
"preu_fix_potencia_p6": fields.float("Preu Fix Potència P6", digits=(16, 6)),
"signature_template_id": fields.many2one(
'poweremail.templates',
'Plantilla de Signatura',
help="Selecciona la plantilla de signatura per a l'email."
),
}

_defaults = {
Expand Down
11 changes: 11 additions & 0 deletions som_leads_polissa/giscedata_crm_lead_view.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?xml version="1.0" ?>
<openerp>
<data>
<record id="giscedata_crm_leads_signature_view_som" model="ir.ui.view">
<field name="name">giscedata.crm.lead.form</field>
<field name="model">giscedata.crm.lead</field>
<field name="type">form</field>
<field name="inherit_id" ref="giscedata_crm_leads_signatura.giscedata_crm_leads_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='data_firma']" position="after">
<field name="signature_template_id" colspan="8" select="1"/>
</xpath>
</field>
</record>
<record id="giscedata_crm_leads_som_view" model="ir.ui.view">
<field name="name">giscedata.crm.lead.som</field>
<field name="model">giscedata.crm.lead</field>
Expand Down
3 changes: 3 additions & 0 deletions som_leads_polissa/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from test_giscedata_crm_lead import *
57 changes: 57 additions & 0 deletions som_leads_polissa/tests/test_giscedata_crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-

from destral import testing
from destral.transaction import Transaction


class TestGiscedataCrmLead(testing.OOTestCase):

def setUp(self):
self.txn = Transaction().start(self.database)
self.cursor = self.txn.cursor
self.uid = self.txn.user
self.lead_o = self.openerp.pool.get('giscedata.crm.lead')
self.poweremail_template_o = self.openerp.pool.get('poweremail.templates')
self.imd_o = self.openerp.pool.get('ir.model.data')
# Crea una plantilla de prova
self.test_template = self.poweremail_template_o.create(self.cursor, self.uid, {
'name': 'Test Template',
'template_language': 'mako',
})

# Crea un lead de prova
self.test_lead = self.lead_o.create(self.cursor, self.uid, {
'name': 'Test Lead',
'crm_lead_type': 'activation', # o 'renovation' segons el cas
'signature_template_id': self.test_template,
})

def tearDown(self):
self.txn.stop()

def test_get_contract_template_from_delivery_type_email(self):
# Test per delivery_type 'email' i no renovació
tmpl_id = self.lead_o.get_contract_template_from_delivery_type(
self.cursor, self.uid, self.test_lead, delivery_type='email'
)
self.assertEqual(
tmpl_id, self.test_template,
"El template ID no coincideix amb el camp signature_template_id"
)

def test_get_contract_template_from_delivery_type_renovation(self):
# Test per renovació
self.lead_o.write(
self.cursor, self.uid, self.test_lead, {'crm_lead_type': 'renovation'}
)
tmpl_id = self.lead_o.get_contract_template_from_delivery_type(
self.cursor, self.uid, self.test_lead, delivery_type='email'
)
# Aquí hauries de posar l'ID esperat per a la renovació
expected_renovation_template_id = self.imd_o.get_object_reference(
self.cursor, self.uid, 'giscedata_crm_leads_signatura', 'renovacio_lead_signatura'
)[1]
self.assertEqual(
tmpl_id, expected_renovation_template_id,
"El template ID no coincideix amb l'esperat per renovació"
)
Loading