128 lines
4.7 KiB
Python
128 lines
4.7 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 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)
|
|
|
|
@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
|
|
|
|
@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"
|
|
line_ask = fields.Char('Ask', required=True, select=True)
|
|
# response = fields.Boolean('Response')
|
|
# sort=False, readonly=True
|
|
comment = fields.Text('Comments')
|
|
validated_by = fields.Many2One('res.user', 'User')
|
|
|
|
@classmethod
|
|
def table_query_consult(cls):
|
|
Opportunity = Pool().get('crm.opportunity.validation')
|
|
print(Opportunity.__name__)
|
|
print(Opportunity._history)
|
|
opportunity = Opportunity.__table_history__()
|
|
query = opportunity.select(
|
|
opportunity.line_ask,
|
|
opportunity.validated_by
|
|
)
|
|
print(opportunity,'tabla')
|
|
cursor = Transaction().connection.cursor()
|
|
cursor.execute(*query)
|
|
result = cursor.fetchall()
|
|
print(len(result),'result')
|
|
|
|
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')
|