DigitalSignage/controllers/dss_form_input_controller.py

329 lines
22 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import os
import os.path
import base64
import logging
import werkzeug
import datetime
import json
from odoo.addons.portal.controllers import portal
from odoo.http import request,Controller, route
from werkzeug.wrappers import Response
from ..models.dss_contract import dsscontracts
from odoo import fields, http, _
_logger = logging.getLogger(__name__)
#class WebContractsInput(Controller):
class CustomerPortal(portal.CustomerPortal):
@route(['/eingabe'],type='http', auth='user', website=True, csrf=False)
def web_form(self, **kwargs):
_logger.info("inside: start web_form")
return request.render("website.eingabe-phase1")
@route(['/my/invoiceinput'],type='http', auth='user', website=True, csrf=False)
def ad_portal_my_documents(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, search=None, search_in='all', groupby='none', **kwargs):
values = super()._prepare_home_portal_values({})
user = request.env.user
Attachment = request.env['dss.contracts'].sudo()
domain = [('contract_state', '=', 39),
('contract_creator', '=', user.id),
('web_contract_input_notfinished','=',True)]
documents = Attachment.search(domain)
grouped_documents = []
if documents:
grouped_documents = [documents]
values.update({
'grouped_documents': grouped_documents,
'documents': documents.sudo(),
'username':user.name,
'page_name': 'Kundenvertraege',
'base_url': http.request.env["ir.config_parameter"].sudo().get_param("web.base.url"),
'default_url': '/my/invoiceinput'
})
return request.render("DigitalSignage.portal_my_invoiceinput", values)
@route(['/eingabe/start'],type='http', auth='user', website=True, csrf=False)
def changeScreenView(self, **kwargs):
_logger.info("inside start: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
name = kwargs.get('websideusername')
user_id = request.env.user
projekt_id = kwargs.get('project')
project = request.env['dss.projects'].search([('id','=',int(projekt_id))],limit=1)
project.reservedkdnr=str(project.reservedkdnr)+';'+str(project.lastkdnr+1)
project.lastkdnr=project.lastkdnr+1
tempid = str(project.projectid) + str(user_id.id).zfill(2) + str(project.lastkdnr).zfill(2)
tempname = tempid + '_Vertrag'
contract_name = str(tempid)+' - Vertrag ' + str(project.lastkdnr).zfill(2)
contract_id = str(project.projectid) + str(project.lastrealkdnr).zfill(2)
grundsystem_webinput_template=project.web_input_template
if not grundsystem_webinput_template:
grundsystem_webinput_template = project.grundsystem_webinput_template
if not grundsystem_webinput_template:
return request.render("website.eingabe-phase2-notemplate",{'websideusername':name,'user_id':str(user_id.id)})
else:
new_contract = request.env['dss.contracts'].create({'project_id':project.projectid,'project':project.id,'client_id':str(project.lastkdnr).zfill(2),'contract_auto_id':str(tempid),'contract_auto_name':str(tempname),'contract_state':39,'contract_name':contract_name,'web_contract_input_notfinished':True,'contract_creator':int(user_id.id)})
contract_data_id=new_contract.id
_logger.info("inside start: "+str(name)+'--'+str(projekt_id)+'--'+str(grundsystem_webinput_template))
return request.render("website."+grundsystem_webinput_template,{'websideusername':name,'user_id':str(user_id.id),'projectid':str(project.projectid),'project':str(projekt_id),'contract_id':str(contract_id),'kd_id':str(str(project.lastrealkdnr).zfill(2)),'web_contract_paysum_gfx':'249','contract_data_id':str(contract_data_id)})
@route(['/eingabe/continue'],type='http', auth='user', website=True, csrf=False)
def inputcontinue(self, **kwargs):
_logger.info("inside continue: " + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
user_id = request.env.user
contract = request.env['dss.contracts'].search([('uuid','=',kwargs.get('uuid'))],limit=1)
project = contract.project
_logger.info("inside continue: "+str(contract.contract_auto_name)+'--'+str(project.id))
grundsystem_webinput_template=project.web_input_template
if not grundsystem_webinput_template:
grundsystem_webinput_template = project.grundsystem_webinput_template
_logger.info("inside continue: "+str(contract.contract_auto_name)+'--'+str(project.id)+'--'+str(grundsystem_webinput_template))
felder = request.env['dss.advertisefields'].search(['&','|',('contract','=',False),('isblocked','=',False),('project','=',project.id)])
fo =""
sfeld =""
for feld in felder:
fo = fo+"<option value=''>"+feld.feldname+"</option>"
for feld in contract.werbe_feld_selected:
sfeld = sfeld+feld.auto_feldname+", "
evtlcontract_id = str(contract.project.projectid) + str(contract.project.lastrealkdnr).zfill(2)
evtlcontract_name = str(evtlcontract_id)+'_'+str(contract.client_short_company) if contract.client_short_company else str(contract.client_short_name)+' '+str(contract.client_short_vorname)
olddata = {
'user_id':str(user_id),
'projectid':str(project.projectid),
'project':str(project.id),
'contract_id':str(evtlcontract_id),
'client_short_company':str(contract.client_short_company),
'client_short_strasse':str(contract.client_short_strasse),
'client_short_plz':str(contract.client_short_plz),
'client_short_telefon':str(contract.client_short_telefon),
'client_short_email':str(contract.client_short_email),
'client_short_rgemail':str(contract.client_short_rgemail),
'client_short_ort':str(contract.client_short_ort),
'client_short_mobil':str(contract.client_short_mobil),
'client_short_website':str(contract.client_short_website),
'client_short_vorname':str(contract.client_short_vorname),
'client_short_name':str(contract.client_short_name),
'web_contract_paysum_lz':contract.web_contract_paysum_lz,
'web_contract_paysum_all':contract.web_contract_paysum_all,
'web_contract_paysum_gfx':contract.web_contract_paysum_gfx,
'contract_data_id':str(contract.id),
'feldoptions':fo,
'feldselected':sfeld,'kd_id':evtlcontract_name,
'Datum': contract.web_contract_sign_datum,
'Ort': contract.web_contract_sign_ort,
'NameVorname': contract.web_contract_sign_name,
'bic': contract.client_short_BIC,
'iban': contract.client_short_IBAN,
'kapay': contract.web_contract_kapayment_info,
'alpay': contract.web_contract_alpayment_info,
'sonder_0': contract.web_contract_sonder_0,
'sonder_1': contract.web_contract_sonder_1,
'sonder_2': contract.web_contract_sonder_2,
}
return request.render("website."+grundsystem_webinput_template, olddata)
@route(['/eingabe/finish'],type='http', auth='user', website=True, csrf=False)
def finish_contract(self, **kwargs):
_logger.info("inside: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
uuid = kwargs.get('uuid')
contract = request.env['dss.contracts'].search([('uuid','=',uuid)],limit=1)
_logger.info("inside finish_contract: "+str(contract.id)+'--'+str(contract.contract_auto_id)+'--'+str(uuid))
contract.web_contract_input_notfinished=False
contract_id = str(contract.project.projectid) + str(contract.project.lastrealkdnr).zfill(2)
contract.contract_auto_id = contract_id
contract.contract_name = str(contract_id)+' - '+str(contract.client_short_company) if contract.client_short_company else str(contract.client_short_name)+' '+str(contract.client_short_vorname)
contract.contract_auto_name=str(contract_id)+'_'+str(contract.client_short_company) if contract.client_short_company else str(contract.client_short_name)+' '+str(contract.client_short_vorname)
dsscontracts.tokampagne(contract)
return request.render("website.eingabe-finished",{'contract':contract,'contract_auto_id':contract.contract_auto_id})
@route(['/eingabe/cancel'],type='http', auth='user', website=True, csrf=False)
def cancel_contract(self, **kwargs):
_logger.info("inside: start cancelcontract" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
uuid = kwargs.get('uuid')
contract = request.env['dss.contracts'].search([('uuid','=',uuid)],limit=1)
_logger.info("inside finish_contract: "+str(contract.id)+'--'+str(contract.contract_auto_id)+'--'+str(uuid))
contract.unlink()
return request.render("website.eingabe-finished-delete",{'contract_auto_id':''})
def setcontract(self,contract,kwargs):
projekt_id = kwargs.get('project')
contract.client_short_company = kwargs.get('client_short_company') if kwargs.get('client_short_company') else ''
contract.client_short_vorname = kwargs.get('client_short_vorname') if kwargs.get('client_short_vorname') else ''
contract.client_short_name = kwargs.get('client_short_name') if kwargs.get('client_short_name') else ''
contract.client_short_telefon = kwargs.get('client_short_telefon') if kwargs.get('client_short_telefon') else ''
contract.client_short_email = kwargs.get('client_short_email') if kwargs.get('client_short_email') else ''
contract.client_short_rgemail = kwargs.get('client_short_rgemail') if kwargs.get('client_short_rgemail') else ''
contract.client_short_strasse = kwargs.get('client_short_strasse') if kwargs.get('client_short_strasse') else ''
contract.client_short_plz = kwargs.get('client_short_plz') if kwargs.get('client_short_plz') else ''
contract.client_short_ort = kwargs.get('client_short_ort') if kwargs.get('client_short_ort') else ''
contract.client_short_mobil = kwargs.get('client_short_mobil') if kwargs.get('client_short_mobil') else ''
contract.client_short_website = kwargs.get('client_short_website') if kwargs.get('client_short_website') else ''
contract.runtimesystem = "M"
contract.runtime_m = kwargs.get('contract_time') if kwargs.get('contract_time') else '64'
contract.web_contract_paysum_lz = kwargs.get('web_contract_paysum_lz') if kwargs.get('web_contract_paysum_lz') else 0.0
contract.web_contract_paysum_gfx = kwargs.get('web_contract_paysum_gfx') if kwargs.get('web_contract_paysum_gfx') else 0.0
contract.web_contract_paysum_all = kwargs.get('web_contract_paysum_all') if kwargs.get('web_contract_paysum_all') else 0.0
contract.web_contract_sign_datum = kwargs.get('Datum') if kwargs.get('Datum') else ''
contract.web_contract_sign_ort = kwargs.get('Ort') if kwargs.get('Ort') else ''
contract.contract_date = datetime.datetime.strptime(contract.web_contract_sign_datum, "%d.%m.%Y").date()
contract.web_contract_sign_name = kwargs.get('NameVorname') if kwargs.get('NameVorname') else ''
contract.client_short_BIC = kwargs.get('bic') if kwargs.get('bic') else ''
contract.client_short_IBAN = kwargs.get('iban') if kwargs.get('iban') else ''
contract.web_contract_is_lastschrift = kwargs.get('lastschrift') == 'on' if kwargs.get('lastschrift') else False
contract.work_state_info = kwargs.get('sonder_2') if kwargs.get('sonder_2') else ''
contract.web_contract_kapayment_info = kwargs.get('kapay') if kwargs.get('kapay') else ''
contract.web_contract_alpayment_info = kwargs.get('alpay') if kwargs.get('alpay') else ''
contract.web_contract_sonder_0 = kwargs.get('sonder_0') if kwargs.get('sonder_0') else ''
contract.web_contract_sonder_1 = kwargs.get('sonder_1') if kwargs.get('sonder_1') else ''
contract.web_contract_sonder_2 = kwargs.get('sonder_2') if kwargs.get('sonder_2') else ''
gesamts = kwargs.get('sonder_0') if kwargs.get('sonder_0') else ''
gesamts = gesamts+' //// '+kwargs.get('sonder_1') if kwargs.get('sonder_1') else ''
contract.remark = gesamts
wfields = kwargs.get('werbefeld') if kwargs.get('werbefeld') else ''
wfarray = wfields.split(',') if wfields else []
contract.werbe_feld_selected = [(6, 0, [])]
for wfa in wfarray:
if wfa:
if '_' in wfa:
wfa = wfa.split('_')[1]
wfaid = request.env['dss.advertisefields'].search([('feldname','=',wfa.strip()),('project','=',contract.project.id)],limit=1)
_logger.info("inside update : "+str(projekt_id)+'/'+str(contract.project.id)+'--'+str(wfields)+'--'+str(wfa.strip()+'--'+str(wfaid)))
if wfaid:
contract.werbe_feld_selected = [(4, wfaid.id)]
return contract
@route(['/eingabe/submit_lcdtouch'],type='http', auth='user', website=True, csrf=False)
def submit_lcdtouch(self, **kwargs):
_logger.info("inside: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
name = kwargs.get('websideusername')
projekt_id = kwargs.get('project')
projectid = kwargs.get('projectid')
user_id = kwargs.get('user_id')
contract_id = kwargs.get('contract_id')
kd_id = kwargs.get('kd_id')
contract_data_id = kwargs.get('contract_data_id')
_logger.info("inside: "+str(name)+'--'+str(projekt_id)+'--'+str(kd_id)+'--'+str(contract_id)+'--'+str(contract_data_id)+'--'+str(projectid)+'--'+str(kwargs.get('kamail')))
contract = self.setcontract(request.env['dss.contracts'].search([('id','=',contract_data_id)],limit=1),kwargs)
return request.render("website.eingabe-phase3-upload",{'websideusername':name,'user_id':str(user_id),'projectid':str(projectid),'project':str(projekt_id),'contract_id':str(contract_id),'kd_id':str(kd_id),'contract_data_id':str(contract_data_id)})
@route(['/eingabe/submit_kfz'],type='http', auth='user', website=True, csrf=False)
def submit_kfz(self, **kwargs):
_logger.info("inside: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
name = kwargs.get('websideusername')
projekt_id = kwargs.get('project')
projectid = kwargs.get('projectid')
user_id = kwargs.get('user_id')
contract_id = kwargs.get('contract_id')
contract_data_id = kwargs.get('contract_data_id')
kd_id = kwargs.get('kd_id')
contract = self.setcontract(request.env['dss.contracts'].search([('id','=',contract_data_id)],limit=1),kwargs)
_logger.info("inside: "+str(name)+'--'+str(projekt_id)+'--'+str(kd_id)+'--'+str(contract_id)+'--'+str(contract_data_id))
return request.render("website.eingabe-phase3-upload",{'websideusername':name,'user_id':str(user_id),'projectid':str(projectid),'project':str(projekt_id),'contract_id':str(contract_id),'kd_id':str(kd_id),'contract_data_id':str(contract_data_id)})
@route(['/eingabe/submit_stream'],type='http', auth='user', website=True, csrf=False)
def submit_stream(self, **kwargs):
_logger.info("inside: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
name = kwargs.get('websideusername')
projekt_id = kwargs.get('project')
projectid = kwargs.get('projectid')
user_id = kwargs.get('user_id')
contract_id = kwargs.get('contract_id')
kd_id = kwargs.get('kd_id')
contract_data_id = kwargs.get('contract_data_id')
contract = self.setcontract(request.env['dss.contracts'].search([('id','=',contract_data_id)],limit=1),kwargs)
_logger.info("inside: "+str(name)+'--'+str(projekt_id)+'--'+str(kd_id)+'--'+str(contract_id)+'--'+str(contract_data_id))
return request.render("website.eingabe-phase3-upload",{'websideusername':name,'user_id':str(user_id),'projectid':str(projectid),'project':str(projekt_id),'contract_id':str(contract_id),'kd_id':str(kd_id),'contract_data_id':str(contract_data_id)})
@route(['/eingabe/submit_upload'],type='http', auth='user', website=True, csrf=False)
def submit_upload(self, **kwargs):
_logger.info("inside: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
name = kwargs.get('websideusername')
projekt_id = kwargs.get('project')
projectid = kwargs.get('projectid')
user_id = kwargs.get('user_id')
contract_id = kwargs.get('contract_id')
kd_id = kwargs.get('kd_id')
contract_data_id = kwargs.get('contract_data_id')
_logger.info("inside: "+str(name)+'--'+str(projekt_id)+'--'+str(kd_id)+'--'+str(contract_id)+'--'+str(contract_data_id))
return request.render("website.eingabe-phase4-finish",{'websideusername':name,'user_id':str(user_id),'projectid':str(projectid),'project':str(projekt_id),'contract_id':str(contract_id),'kd_id':str(kd_id),'contract_data_id':str(contract_data_id)})
@route(['/eingabe/submit_finish'],type='http', auth='user', website=True, csrf=False)
def submit_finish(self, **kwargs):
_logger.info("inside: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' --'+str(request.httprequest.data))
name = kwargs.get('websideusername')
projekt_id = kwargs.get('project')
projectid = kwargs.get('projectid')
user_id = kwargs.get('user_id')
contract_id = kwargs.get('contract_id')
kd_id = kwargs.get('kd_id')
contract_data_id = kwargs.get('contract_data_id')
submit_finish = kwargs.get('submit')
_logger.info("inside finish : "+str(name)+'--'+str(projekt_id)+'--'+str(kd_id)+'--'+str(contract_id)+'--'+str(contract_data_id)+'--'+str(submit_finish))
if submit_finish == 'Eingabe beenden':
return request.render("website.eingabe-phase1")
if submit_finish == 'Neuen Vertrag im gleichen Projekt':
return self.changeScreenView(**kwargs)
if submit_finish == 'Neuen Vertrag in anderen Projekt':
return self.ad_portal_my_documents(self, **kwargs)
@route(['/xrechnungin'],type='http', auth='public', website=True, csrf=False)
def Xrechnungask(self, **kwargs):
project = request.env['x_dss.tempkd'].search([('x_guid','=',request.params.get('token'))],limit=1)
if not project:
return request.render("website.xrechnung",{'requestid':request.params.get('token'),'errorstyle':'display:block','contentstyle':'display:none'})
else :
mobile = '' if (not project.x_mobil) or (project.x_mobil == 'False') else project.x_mobil
telefon = '' if (not project.x_telefon) or (project.x_telefon == 'False') else project.x_telefon
email = '' if (not project.x_Email) or (project.x_Email == 'False') else project.x_Email
return request.render("website.xrechnung",{'requestid':request.params.get('token'),'errorstyle':'display:none','contentstyle':'display:block','kdid':project.id,'kdnr':project.x_kdnr,'name':project.x_name,'email':email,'telefon':telefon,'mobil':mobile,'rgemail':project.x_rgemail,'leitweg':project.x_leitwegid})
@route(['/xrechnung/submit'],type='http', auth='public', website=True, csrf=False)
def Xrechnungssubmit(self, **kwargs):
_logger.info("inside: start changeScreenTemplateView" + str(request.params)+' --'+str(kwargs)+' -- #'+str(request.httprequest.data)+'#')
kunden_id = kwargs.get('kdid')
client = request.env['x_dss.tempkd'].search([('id','=',kunden_id)],limit=1)
if client:
if client.x_guid == kwargs.get('requestid'):
if client.x_kdnr == kwargs.get('kdnr'):
orgclientt=request.env['x_dss.tempkd'].search([('x_kdnr','=',client.x_kdnr)])
if kwargs.get('rgemail')=='':
orgclientt.write({'x_rgemail': kwargs.get('email')})
else:
orgclientt.write({'x_rgemail': kwargs.get('rgemail')})
orgclientt.write({'x_leitwegid': kwargs.get('leitweg')})
orgclientt.write({'x_finished': True})
# orgclient=request.env['dss.contracts'].search([('contract_auto_id','=',client.x_kdnr)])
# if orgclient:
# if kwargs.get('rgemail')=='':
# orgclient.write({'client_short_rgemail': kwargs.get('email')})
# else:
# orgclient.write({'client_short_rgemail': kwargs.get('rgemail')})
# orgclient.write({'client_short_mobil': kwargs.get('mphone')})
# orgclient.write({'client_short_leitwegid': kwargs.get('leitweg')})
# if orgclient.client_short_email != kwargs.get('email'):
# orgclient.write({'client_short_email': kwargs.get('email')})
# if orgclient.client_short_telefon != kwargs.get('phone'):
# orgclient.write({'client_short_telefon': kwargs.get('phone')})
# if orgclient.client:
# org_contact_client=orgclient.client
# org_contact_client.rgemail = orgclient.client_short_rgemail
# org_contact_client.email = orgclient.client_short_email
# org_contact_client.leitwegid = orgclient.client_short_leitwegid
# org_contact_client.mobil = orgclient.client_short_mobil
# return request.redirect('/danke-xrechnung')
# else :
# errorcode='EF004'
return request.redirect('/danke-xrechnung')
else : errorcode='EF003-'+str(kwargs.get('kdnr'))
else : errorcode='EF002'
else : errorcode='EF001-'+str(kwargs.get('kdid'))
return request.render('website.error-xrechnung',{'error':errorcode})