mirror of
https://bitbucket.org/presik/trytonpsk-crm.git
synced 2023-12-14 05:22:56 +01:00
175 lines
6.8 KiB
Python
175 lines
6.8 KiB
Python
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
from datetime import datetime, date
|
|
from trytond.report import Report
|
|
from trytond.model import ModelView, ModelSQL, fields, Workflow
|
|
from trytond.pyson import Eval, If, In, Get
|
|
from trytond.pool import Pool, PoolMeta
|
|
from trytond.transaction import Transaction
|
|
from .exceptions import CrmConfigurationError
|
|
from trytond.i18n import gettext
|
|
# from sql import Null, Literal
|
|
# from sql.functions import CurrentTimestamp
|
|
from trytond.modules.company.model import employee_field, set_employee
|
|
|
|
# STATES = {'readonly': (Eval('state') != 'draft')}
|
|
|
|
# Templates for prospects and Cients...
|
|
class ValidationTemplate(ModelSQL, ModelView):
|
|
"Validation Template"
|
|
__name__ = "crm.validation_template"
|
|
name = fields.Char('Name', required=True, select=True)
|
|
code = fields.Char('Code', required=True, select=True)
|
|
type = fields.Selection([('prospect','Prospect'),('client','Client')],'Type')
|
|
active = fields.Boolean('Active')
|
|
lines = fields.One2Many('crm.validation_template.ask',
|
|
'template', 'Asks')
|
|
|
|
# Ask/concept for each template
|
|
class ValidationTemplateAsk(ModelSQL, ModelView):
|
|
"Validation Template Ask"
|
|
__name__ = "crm.validation_template.ask"
|
|
_rec_name = 'ask'
|
|
template = fields.Many2One('crm.validation_template',
|
|
'Template Validation', required=True)
|
|
sequence = fields.Integer('Sequence', required=True, select=True)
|
|
ask = fields.Char('Ask', required=True, select=True)
|
|
|
|
# Validation for each opportunity
|
|
class ValidationAsk(ModelSQL, ModelView):
|
|
"Validation Ask"
|
|
__name__ = "crm.opportunity.validation"
|
|
_history = True
|
|
opportunity = fields.Many2One('crm.opportunity',
|
|
'Opportunity', required=True)
|
|
party = fields.Many2One('party.party',
|
|
'Party', required=True)
|
|
template = fields.Many2One('crm.validation_template.ask',
|
|
'Template Ask', required=True)
|
|
sequence = fields.Integer('Sequence', required=True)
|
|
date_validation = fields.Date('Date')
|
|
line_ask = fields.Char('Ask', required=True, select=True)
|
|
# response = fields.Boolean('Response')
|
|
response = fields.Selection([
|
|
("", ""),
|
|
('approved', 'Approved'),
|
|
('rejected', 'Rejected'),
|
|
], "Response")
|
|
# required=True, select=True,
|
|
# sort=False, readonly=True
|
|
comment = fields.Text('Comments')
|
|
# validated_by = employee_field("Validated By")
|
|
validated_by = fields.Many2One('res.user', 'User')
|
|
blocked = fields.Boolean('Blocked', readonly=True)
|
|
history = fields.Function(fields.Text('history'), 'get_history')
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(ValidationAsk, cls).__setup__()
|
|
cls._order.insert(0, ('sequence', 'ASC'))
|
|
|
|
def get_user(self, name):
|
|
return self.create_uid.rec_name
|
|
|
|
def get_history(self, name):
|
|
# return 'Historial'
|
|
list_ids = [self.id,]
|
|
show_list_as_str = 'Fecha | Pregunta | Usuario' + '\n'
|
|
OpportunityHistory = Pool().get('crm.opportunity.validation')
|
|
#HistoryByAsk = OpportunityHistory.personalized_history_revisions(list_ids)
|
|
HistoryByAsk = OpportunityHistory.history_revisions(list_ids)
|
|
for record in HistoryByAsk:
|
|
print(record[0],'rec')
|
|
show_list_as_str += str(record[0]) + ' | ' + str(record[1]) + ' | ' + str(record[2]) + '\n'
|
|
return str(show_list_as_str)
|
|
# return str(HistoryByAsk)
|
|
|
|
@fields.depends('response')
|
|
def on_change_response(self):
|
|
if self.response:
|
|
self.validated_by = Transaction().user
|
|
self.date_validation = date.today()
|
|
else:
|
|
self.date_validation = None
|
|
|
|
class ValidationHistoryAsk(ModelView, ModelSQL):
|
|
"Validation History Ask"
|
|
__name__ = "crm.opportunity.validation.history"
|
|
#__id = fields.Integer('id')
|
|
id = fields.Integer('id')
|
|
company = fields.Many2One('company.company', 'Company')
|
|
# id = fields.Integer('id', required=True)
|
|
line_ask = fields.Char('Ask')
|
|
response = fields.Char('Response')
|
|
opportunity = fields.Integer('Opportunity')
|
|
# sort=False, readonly=True
|
|
comment = fields.Text('Comments')
|
|
validated_by = fields.Integer('Validated By')
|
|
|
|
|
|
@classmethod
|
|
def table_query(cls):
|
|
OpportunityHistory = Pool().get('crm.opportunity.validation')
|
|
Opportunity = Pool().get('crm.opportunity')
|
|
# print(OpportunityHistory.__name__)
|
|
# print(Opportunity._history)
|
|
opportunityhistory = OpportunityHistory.__table_history__()
|
|
opportunity = Opportunity.__table__()
|
|
query = opportunityhistory.join(opportunity,
|
|
condition=opportunity.id==opportunityhistory.opportunity
|
|
).select(
|
|
#opportunityhistory.__id.as_('__id'),
|
|
# opportunityhistory.__id__,
|
|
opportunityhistory.id,
|
|
opportunityhistory.create_uid,
|
|
opportunityhistory.create_date,
|
|
opportunityhistory.write_uid,
|
|
opportunityhistory.write_date,
|
|
# Literal(0).as_('create_uid'),
|
|
# CurrentTimestamp().as_('create_date'),
|
|
# cls.write_uid.sql_cast(Literal(Null)).as_('write_uid'),
|
|
# cls.write_date.sql_cast(Literal(Null)).as_('write_date'),
|
|
opportunity.company,
|
|
opportunityhistory.line_ask,
|
|
opportunityhistory.comment,
|
|
# opportunity.date_validation,
|
|
opportunityhistory.opportunity,
|
|
opportunityhistory.validated_by,
|
|
# opportunity.party,
|
|
# opportunity.response,
|
|
# opportunity.sequence,
|
|
# opportunity.template,
|
|
opportunityhistory.response,
|
|
|
|
)
|
|
print(opportunityhistory,'tabla')
|
|
cursor = Transaction().connection.cursor()
|
|
cursor.execute(*query)
|
|
result = cursor.fetchall()
|
|
print(query,'query')
|
|
print(result,'result')
|
|
return query
|
|
# return opportunity.select(
|
|
#
|
|
# # Max(opportunity.create_uid).as_('create_uid'),
|
|
# # Max(opportunity.create_date).as_('create_date'),
|
|
# # Max(opportunity.write_uid).as_('write_uid'),
|
|
# # Max(opportunity.write_date).as_('write_date'),
|
|
# opportunity.line_ask,
|
|
# opportunity.validated_by
|
|
# )
|
|
|
|
|
|
# class PartyValidationTraceability(ModelSQL, ModelView):
|
|
# ''' Model to save traceability of the Party Validation'''
|
|
# 'Party Validation Traceability'
|
|
# __name__ = 'crm.party_validation_traceability'
|
|
# response = fields.Selection([
|
|
# ("", ""),
|
|
# ('approved', 'Approved'),
|
|
# ('rejected', 'Rejected'),
|
|
# ], "Response")
|
|
# opportunity = fields.Many2One('crm.opportunity', 'Opportunity', required=True )
|
|
# comment = fields.Text('Comments')
|
|
# validated_by = fields.Many2One('res.user', 'User')
|