fix
This commit is contained in:
parent
c56cb67f2e
commit
6f841b0286
|
@ -28,22 +28,6 @@ from trytond.ir.attachment import AttachmentCopyMixin
|
|||
from trytond.ir.note import NoteCopyMixin
|
||||
from trytond.modules.company.model import employee_field, set_employee
|
||||
|
||||
# class PartyEvaluationConcept(ModelSQL, ModelView):
|
||||
# ''' Model to create concepts to Party Evaluation '''
|
||||
# 'Party Evaluation Concept'
|
||||
# __name__ = 'crm.party_evaluation_concept'
|
||||
# name = fields.Char('Concept Name', required=True)
|
||||
#
|
||||
# class PartyEvaluation(ModelSQL, ModelView):
|
||||
# ''' Model to make analisys of economic behavior of party'''
|
||||
# 'Party Evaluation'
|
||||
# __name__ = 'crm.party_evaluation'
|
||||
# concept = fields.Many2One('crm.party_evaluation_concept', 'Concept', required=True )
|
||||
# opportunity = fields.Many2One('crm.opportunity', 'Opportunity', required=True )
|
||||
# date = fields.Date('Date', required=True)
|
||||
# observation = fields.Text('Observation')
|
||||
# approved = fields.Boolean('Approved')
|
||||
|
||||
|
||||
class Opportunity(
|
||||
Workflow, ModelSQL, ModelView,
|
||||
|
@ -74,19 +58,10 @@ class Opportunity(
|
|||
states={
|
||||
'readonly': ~Eval('state').in_(['prospecting', 'quote_revision', 'review'])
|
||||
})
|
||||
|
||||
# reference = fields.Selection([
|
||||
# ('physical', "Physical"),
|
||||
# ('electronic', "Electronic")], "Reference", select=True, sort=False,
|
||||
# states={
|
||||
# 'readonly': ~Eval('state').in_(['prospecting', 'analysis'])
|
||||
# })
|
||||
|
||||
party = fields.Many2One(
|
||||
'party.party', "Party", select=True,
|
||||
states={
|
||||
'readonly': ~Eval('state').in_(['prospecting', 'quote_revision', 'review']),
|
||||
# 'required': ~Eval('state').in_(['lead', 'lost', 'cancelled']),
|
||||
},
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
|
@ -224,7 +199,6 @@ class Opportunity(
|
|||
'get_total_opportunity')
|
||||
total_without_tax = fields.Function(fields.Float('Total'),
|
||||
'get_total_without_tax_opportunity')
|
||||
|
||||
# cancelled_reason = fields.Selection([
|
||||
# ('',''),
|
||||
# ('Sin acuerdo', "No se llego a un acuerdo"),
|
||||
|
@ -249,8 +223,6 @@ class Opportunity(
|
|||
is_approved = fields.Function(fields.Boolean('Is Approved'), 'get_is_approved')
|
||||
traceability = fields.One2Many('crm.opportunity_traceability',
|
||||
'opportunity', 'Opportunity Traceability', readonly=False)
|
||||
# del _states_start, _depends_start
|
||||
# del _states_stop, _depends_stop
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -339,15 +311,15 @@ class Opportunity(
|
|||
})
|
||||
|
||||
@fields.depends('party')
|
||||
def get_is_prospect(self,name=None):
|
||||
def get_is_prospect(self, name=None):
|
||||
res = True
|
||||
if self.party:
|
||||
Invoice = Pool().get('account.invoice')
|
||||
invoices = Invoice.search([
|
||||
('party','=',self.party.id),
|
||||
('type','=','out'),
|
||||
('state','!=','draft')
|
||||
])
|
||||
('party','=',self.party.id),
|
||||
('type','=','out'),
|
||||
('state','!=','draft')
|
||||
])
|
||||
if len(invoices) > 0:
|
||||
res = False
|
||||
return res
|
||||
|
@ -587,62 +559,58 @@ class Opportunity(
|
|||
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'opportunity': record.id,
|
||||
'validated_by': Transaction().user,
|
||||
'create_date': date.today(),
|
||||
'action':'Cambio de estado a Análisis'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
def check_party(cls,records):
|
||||
def check_party(cls, records):
|
||||
pool = Pool()
|
||||
ValidationTemplate = pool.get('crm.validation_template')
|
||||
ValidationLine = pool.get('crm.opportunity.validation')
|
||||
|
||||
def get_lines(template,validation_lines):
|
||||
def get_lines(template, validation_lines):
|
||||
lines = []
|
||||
for line in template.lines:
|
||||
print(line.id, 'validation')
|
||||
if line.id not in validation_lines:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'party':record.party.id,
|
||||
'sequence':line.sequence,
|
||||
'line_ask':line.ask,
|
||||
'template':line.id
|
||||
'opportunity': record.id,
|
||||
'party': record.party.id,
|
||||
'sequence': line.sequence,
|
||||
'line_ask': line.ask,
|
||||
'template': line.id
|
||||
}
|
||||
lines.append(value)
|
||||
lines = ValidationLine.create(lines)
|
||||
return lines
|
||||
|
||||
for record in records:
|
||||
for record in records:
|
||||
lines = None
|
||||
party_validations = [v.template.id for v in record.party_validations]
|
||||
if record.is_prospect:
|
||||
templates = ValidationTemplate.search([
|
||||
('type','=','prospect'),
|
||||
])
|
||||
if not templates:
|
||||
continue
|
||||
lines = get_lines(templates[0], party_validations)
|
||||
party_validations = [
|
||||
v.template.id for v in record.party_validations
|
||||
]
|
||||
|
||||
else:
|
||||
templates = ValidationTemplate.search([
|
||||
('type','=','client'),
|
||||
])
|
||||
if not templates:
|
||||
continue
|
||||
lines = get_lines(templates[0], party_validations)
|
||||
_type = 'client'
|
||||
if record.is_prospect:
|
||||
_type = 'prospect'
|
||||
|
||||
templates = ValidationTemplate.search([
|
||||
('type', '=', _type),
|
||||
])
|
||||
print( 'templates ...', templates)
|
||||
|
||||
if not templates:
|
||||
continue
|
||||
lines = get_lines(templates[0], party_validations)
|
||||
|
||||
if lines:
|
||||
cls.write([record],{'party_validations':[('add', lines)]})
|
||||
# record.party_validations = [('create',lines)]
|
||||
# record.party_validations = ('add', lines)
|
||||
# record.save()
|
||||
cls.write([record], {'party_validations': [('add', lines)]})
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
|
|
@ -8,11 +8,9 @@ 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
|
||||
|
||||
# Templates for prospects and Cients...
|
||||
|
||||
class ValidationTemplate(ModelSQL, ModelView):
|
||||
"Validation Template"
|
||||
__name__ = "crm.validation_template"
|
||||
|
@ -26,9 +24,10 @@ class ValidationTemplate(ModelSQL, ModelView):
|
|||
lines = fields.One2Many('crm.validation_template.ask',
|
||||
'template', 'Asks')
|
||||
|
||||
# Ask/concept for each template
|
||||
|
||||
class ValidationTemplateAsk(ModelSQL, ModelView):
|
||||
"Validation Template Ask"
|
||||
# Ask/concept for each template
|
||||
__name__ = "crm.validation_template.ask"
|
||||
_rec_name = 'ask'
|
||||
template = fields.Many2One('crm.validation_template',
|
||||
|
@ -36,9 +35,10 @@ class ValidationTemplateAsk(ModelSQL, ModelView):
|
|||
sequence = fields.Integer('Sequence', required=True, select=True)
|
||||
ask = fields.Char('Ask', required=True, select=True)
|
||||
|
||||
# Validation for each opportunity
|
||||
|
||||
class OpportunityValidation(ModelSQL, ModelView):
|
||||
"Opportunity Validation"
|
||||
# Validation for each opportunity
|
||||
__name__ = "crm.opportunity.validation"
|
||||
_history = True
|
||||
opportunity = fields.Many2One('crm.opportunity', 'Opportunity',
|
||||
|
@ -55,10 +55,7 @@ class OpportunityValidation(ModelSQL, ModelView):
|
|||
('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')
|
||||
|
|
Loading…
Reference in New Issue