DigitalSignage/models/dss_web_contracts_stream.py

283 lines
16 KiB
Python
Executable File

# -*- coding: utf-8 -*
# Test
# Test2
import ast
import datetime
import json
import re
import uuid
import logging
import base64
import subprocess
import tempfile
import easywebdav
import os
import os.path
from odoo import api, fields, models, _
from odoo import tools
from . import dss_settings
from . import dss_ads
from odoo.exceptions import ValidationError
from datetime import date
from datetime import datetime
from babel.dates import format_date
from dateutil.relativedelta import relativedelta
from pyffmpeg import FFmpeg
from tuya_iot import TuyaOpenAPI, TUYA_LOGGER
from tuya_connector import TuyaOpenAPI, TUYA_LOGGER
import sys
TUYA_LOGGER.setLevel(logging.DEBUG)
_logger = logging.getLogger(__name__)
class dsswebcontracts_stream(models.Model):
_name = "dss.web_contracts.stream"
_description = "DigitalSignage Web_Vertraege Stream"
_rec_name = "contract_auto_name"
_inherit = ['mail.thread','mail.activity.mixin','dss.triggermodel']
uuid = fields.Char(default=lambda self: self._default_uuid(), required=True, readonly=True, copy=False, string='UUID')
cruuid = fields.Char(related='uuid')
contract_id = fields.Char("Kundennummer",store=True,tracking=True)
contract_auto_id = fields.Char("Kundennummer automatisch",tracking=True,help="Wird berechnet aus Projektnummer + Kunden ID")
contract_name = fields.Char('Kurzbezeichnung', required=True,tracking=True)
contract_auto_name = fields.Char('Vertragskennung',tracking=True,help="Wird berechnet aus Kundennummer + Vertragskennung")
contract_date = fields.Date('Vertragsdatum',tracking=True)
contract_writer = fields.Many2one('res.partner', domain="['&',('dsspartner','=',True),('dsspartner_vertrieb','=',True)]", tracking=True)
contract_writer_formular = fields.Char('Vertragsschreiber Formular', tracking=True)
#contract_type = fields.Selection([('TV','TV'),('Web','Web')], 'Vertragstyp', tracking=True)
#contract_writer_projects = fields.Many2many('dss.projects',string="Vertragsschreiber Projekte", tracking=True, compute='_get_contractwriter_projects', store=True)
contract_writer_projects_string = fields.Char("Vertragsschreiber Projekte S", tracking=True)
contract_writer_projects_MM = fields.Many2many('dss.projects',string="Vertragsschreiber Projekte MM", tracking=True, domain="[('id','in',self.env.user.dss_projects.ids)]", store=True)
websideusername = fields.Char('Webseite Benutzername',tracking=True,compute='_compute_websideusername', store=True)
werbe_feld = fields.Char(string='Werbefelde(r)',tracking=True)
werbe_feld_selected = fields.Many2many('dss.advertisefields',string='Werbefelder',tracking=True)
remark = fields.Char('Bemerkungen',tracking=True)
contract_remark = fields.Html('Vertragshinweise',tracking=True)
project = fields.Many2one('dss.projects' , string='Project', store=True,tracking=True)
project_id = fields.Integer(related='project.projectid', string='Project ID')
projectIid = fields.Integer('Project IID',tracking=True)
client = fields.Many2one('res.partner',string="Kunde (wenn angelegt)",domain="['&',('dsspartner','=',True),('dsspartner_werbung','=',True)]",tracking=True,help="Nur zu Benutzen wenn Kunden als Kontakt angelegt wurde")
client_id = fields.Char(string="KundenID (2Stellen)",help="Nur der 2 stellige letzte Teil der Kundennummer",tracking=True)
client_short_company = fields.Char('Firmenname Kunde',tracking=True)
client_short_vorname = fields.Char('Vorname Kunde',tracking=True)
client_short_name = fields.Char('Name Kunde',tracking=True)
client_short_strasse = fields.Char('Strasse Kunde',tracking=True)
client_short_plz = fields.Char('PLZ Kunde',tracking=True)
client_short_ort = fields.Char('Ort Kunde',tracking=True)
client_short_land = fields.Many2one('res.country','Land Kunde',tracking=True)
client_short_email = fields.Char('Email Kunde',tracking=True)
client_short_finemail = fields.Char('Rechnungs Email Kunde',tracking=True)
client_short_telefon = fields.Char('Telefon Kunde',tracking=True)
client_short_mobil = fields.Char('Mobilfunk Kunde',tracking=True)
client_short_website = fields.Char('Webseite Kunde',tracking=True)
client = fields.Many2one('res.partner',string="Kunde (wenn angelegt)",domain="['&',('dsspartner','=',True),('dsspartner_werbung','=',True)]",tracking=True,help="Nur zu Benutzen wenn Kunden als Kontakt angelegt wurde")
bookingpack = fields.Char(string='Packet',tracking=True)
runtime_m = fields.Integer('Laufzeit Monate',tracking=True)
boarding = fields.Boolean(string='Boarding',tracking=True)
grafikerstellung = fields.Boolean(string='Grafik',tracking=True)
payment = fields.Selection([('FULL','Gesamtzahlung')],string='Zahlung',tracking=True)
reach_PLZ = fields.Char('Reichweite PLZ',tracking=True)
grafik_zuarbeitBis = fields.Date("Zuarbeit bis", tracking=True)
date_start_planed = fields.Date(string='geplantes Startdatum', tracking=True)
date_remove_planed = fields.Date(string='geplantes Enddatum', tracking=True)
scan_vertrag = fields.Binary('Datei')
file_name = fields.Char(string='Dateiname')
erfasst_in_odoo = fields.Boolean('In Odoo erfasst')
erfasst_in_agenda = fields.Boolean('In Agenda erfasst')
# def action_send_email(self):
# """ Sendet eine E-Mail mit den Inhalten des Objekts """
# template = self.env.ref('dss.email_template_my_model')
# if template:
#
#
# template.send_mail(self.id, force_send=True)
def _get_contractwriter_projects(self):
if self.env.user:
self.contract_writer_projects = self.env.user.dss_projects.ids
else:
self.contract_writer_projects = False
def _compute_websideusername(self):
self.websideusername = self.env.user.name
def pydonewpartner1(self):
_logger.info("create new partner...")
@api.model
def _default_uuid(self):
return str(uuid.uuid4())
def pydonewpartner(self):
_logger.info("create new partner...")
fullname = str(self.client_short_vorname) + ' ' +str(self.client_short_name)
newcontact = self.env['res.partner'].create({'name': fullname,
'dsspartner_vorname': self.client_short_vorname,
'dsspartner_name': self.client_short_name,
'email': self.client_short_email,
'phone': self.client_short_telefon,
'mobile': self.client_short_mobil,
'street': self.client_short_strasse,
'city': self.client_short_ort,
'zip': self.client_short_plz,
'country_id': self.env['res.country'].search([('code', '=', 'DE')], limit=1).id,
'company_type': 'person', # 'company' oder 'person',
'website': self.client_short_website,
'company_name': self.client_short_company,
'dsspartner': True,
'dsspartner_werbung': True
})
self.client = newcontact.id
def pydonewcontract_streaming(self):
_logger.info("create new contract...")
bookingpack = fields.Char(string='Packet',tracking=True)
werbe_feld = self.project_id + '_'+self.bookingpack
werbe_feld_selected = self.env['dss.advertisefields'].search([('id','in',self.werbe_feld_selected.ids)])
if not werbe_feld_selected:
_logger.info("kein Werbefeld ausgewählt, Abbruch...")
return
else :
newcontract = self.env['dss.contracts'].create({'project_id': self.project_id,
'project': self.project.id,
'client_id': self.client_id,
'contract_auto_name': self.contract_auto_name,
'contract_auto_id': self.contract_auto_id,
'contract_name': self.contract_name,
'contract_state': self.env['dss.contractstate'].search([("statusname","=","Angelegt")]).id,
'paymentinterval': self.paymentinterval.id,
'werbe_feld_selected': self.werbe_feld_selected,
'client': self.client.id,
'client_short_vorname': self.client_short_vorname,
'client_short_name': self.client_short_name,
'client_short_email': self.client_short_email,
'client_short_telefon': self.client_short_telefon,
'client_short_mobil': self.client_short_mobil,
'client_short_strasse': self.client_short_strasse,
'client_short_ort': self.client_short_ort,
'client_short_plz': self.client_short_plz,
'client_short_website': self.client_short_website,
'client_short_company': self.client_short_company,
'runtimesystem': 'M',
'runtime_m': self.runtime_m,
'contract_auto_extend': False,
'contract_cancel_date': False,
'runtime_events': False,
'tv_reach_PLZ': self.reach_PLZ,
'web_contract':self.id,
'contract_auto_extend': self.contract_auto_extend,
'contract_date': self.contract_date,
'work_state_info': self.remark,
'scan_vertrag': self.scan_vertrag,
'contract_grafik': self.grafikerstellung,
'contract_boarding': self.boarding,
'grafik_zuarbeitBis': self.grafik_zuarbeitBis
# payment = fields.Selection([('FULL','Gesamtzahlung')],string='Zahlung',tracking=True)
})
_logger.info("create new Werbekampagne...")
newWK = self.env['dss.ads'].create({'contract': newcontract.id,
'project': newcontract.project.id,
'adname': 'WK '+self.contract_auto_name,
'adtype': 'MAIN',
'date_start_planed': self.date_start_planed,
'date_remove_planed': self.date_remove_planed,
#'work_state_info': 'ZA bis: '+str(self.grafik_zuarbeitBis)+' / '+self.remark
'work_state_info': 'ZA bis: '+format_date(self.grafik_zuarbeitBis,format='dd.MM.yy',locale='de_DE')
})
self.erfasst_in_odoo = True
#Vertragskennungen bei onChange anpassen
@api.onchange('client_id')
def _onchange_client_id(self):
for record in self :
if record.contract_name == '' :
cname = 'unbekannter Kunden'
else:
cname = record.contract_name
resstr = "%s%s %s" % (record.project_id,record.client_id,cname)
cidstr = "%s%s" % (record.project_id,record.client_id)
if resstr is None :
resstr = 'nicht ermittelbar'
_logger.info('Contract_client_id_change : C_' + str(self.id) + ' - '+str(cidstr)+' vs. '+str(self.contract_auto_id)+'/'+str(resstr)+' vs '+str(self.contract_auto_name))
self.contract_auto_name = resstr
self.contract_auto_id = cidstr
@api.onchange('project_id')
def _onchange_project_id(self):
for record in self :
if record.contract_name == '' :
cname = 'unbekannter Kunden'
else:
cname = record.contract_name
resstr = "%s%s %s" % (record.project_id,record.client_id,cname)
cidstr = "%s%s" % (record.project_id,record.client_id)
if resstr is None :
resstr = 'nicht ermittelbar'
_logger.info('project_id_change : C_' + str(self.id) + ' - '+str(cidstr)+' vs. '+str(self.contract_auto_id)+'/'+str(resstr)+' vs '+str(self.contract_auto_name))
self.contract_auto_name = resstr
self.contract_auto_id = cidstr
# @api.onchange('project')
# def _onchange_project(self):
# self.project_id = self.project.project_id
@api.onchange('contract_name')
def _onchange_contract_name(self):
for record in self :
if record.contract_name == '' :
cname = 'unbekannter Kunden'
else:
cname = record.contract_name
resstr = "%s%s %s" % (record.project_id,record.client_id,cname)
cidstr = "%s%s" % (record.project_id, record.client_id)
if resstr is None :
resstr = 'nicht ermittelbar'
_logger.info('Contract_Name_Change : C_' + str(self.id) + ' - '+str(cidstr)+' vs. '+str(self.contract_auto_id)+'/'+str(resstr)+' vs '+str(self.contract_auto_name))
if not self.contract_auto_name:
self.contract_auto_name = resstr
if not self.contract_auto_id:
self.contract_auto_id = cidstr
if self.contract_auto_id == "":
self.contract_auto_id = cidstr
@api.onchange('contract_auto_id')
def _onchange_contract_auto_id(self):
for record in self :
if record.contract_name == '' :
cname = 'unbekannter Kunden'
else:
cname = record.contract_name
resstr = "%s%s %s" % (record.project_id,record.client_id,cname)
cidstr = "%s%s" % (record.project_id, record.client_id)
if resstr is None:
resstr = 'nicht ermittelbar'
_logger.info('Contract_auto_id_change : C_' + str(self.id) + ' - '+str(cidstr)+' vs. '+str(self.contract_auto_id)+'/'+str(resstr)+' vs '+str(self.contract_auto_name))
if not self.contract_auto_name:
self.contract_auto_name = resstr
if not self.contract_auto_id:
self.contract_auto_id = cidstr
if self.contract_auto_id == "":
self.contract_auto_id = cidstr