Traceability Opportunity
This commit is contained in:
parent
aa3880bbd6
commit
913eb3c2b3
|
@ -5,7 +5,7 @@ from trytond.model import fields
|
|||
class Contract(metaclass=PoolMeta):
|
||||
__name__ = 'sale.contract'
|
||||
|
||||
department = fields.Many2One('company.department','Department',states={'required':True})
|
||||
department = fields.Many2One('company.department','Department',states={'required':False})
|
||||
@classmethod
|
||||
def _get_origin(cls):
|
||||
'Return list of Model names for origin Reference'
|
||||
|
|
171
opportunity.py
171
opportunity.py
|
@ -405,15 +405,27 @@ class Opportunity(
|
|||
@classmethod
|
||||
def create(cls, vlist):
|
||||
pool = Pool()
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
Config = pool.get('crm.configuration')
|
||||
|
||||
config = Config().get_configuration()
|
||||
vlist = [x.copy() for x in vlist]
|
||||
default_company = cls.default_company()
|
||||
for vals in vlist:
|
||||
if vals.get('number') is None and config:
|
||||
vals['number'] = config.opportunity_sequence.get()
|
||||
return super(Opportunity, cls).create(vlist)
|
||||
|
||||
opportunity = super(Opportunity, cls).create(vlist)
|
||||
# print(opportunity,'oportunidad')
|
||||
# value = {
|
||||
# 'opportunity':opportunity[id],
|
||||
# 'validated_by':Transaction().user,
|
||||
# 'create_date':date.today(),
|
||||
# 'action':'Creación de la oportunidad'
|
||||
# }
|
||||
# history.append(value)
|
||||
# history = traceability.create(history)
|
||||
return opportunity
|
||||
|
||||
@classmethod
|
||||
def copy(cls, opportunities, default=None):
|
||||
|
@ -497,6 +509,17 @@ class Opportunity(
|
|||
'''
|
||||
Create a sale for the opportunity and return the sale
|
||||
'''
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
|
||||
value = {
|
||||
'opportunity':self.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Creación de venta para la oportunidad'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
sale = self._get_sale_opportunity()
|
||||
sale_lines = []
|
||||
for line in self.lines:
|
||||
|
@ -508,6 +531,17 @@ class Opportunity(
|
|||
'''
|
||||
Create a contract for the opportunity and return the contract
|
||||
'''
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
|
||||
value = {
|
||||
'opportunity':self.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Creación de contrato para la oportunidad'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
contract = self._get_contract_opportunity()
|
||||
# Contract = Pool().get('sale.contract')
|
||||
# contract = opportunity.create_contract()
|
||||
|
@ -534,15 +568,16 @@ class Opportunity(
|
|||
@Workflow.transition('prospecting')
|
||||
def prospecting(cls, records):
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
print(traceability,'Traceability conection')
|
||||
history = []
|
||||
for record in records:
|
||||
traceability.opportunity = record.id
|
||||
traceability.validated_by = Transaction().user
|
||||
traceability.date_action = date.today()
|
||||
traceability.action = 'change state to Prospect'
|
||||
print(traceability.validated_by)
|
||||
# cls.write([record],{'traceability':('add', traceability)})
|
||||
traceability.save(records)
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Prospecto'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
@ -550,6 +585,17 @@ class Opportunity(
|
|||
def analysis(cls, records):
|
||||
cls.check_party(records)
|
||||
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'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):
|
||||
|
@ -557,7 +603,6 @@ class Opportunity(
|
|||
ValidationLine = Pool().get('crm.opportunity.validation')
|
||||
def get_lines(template,validation_lines):
|
||||
lines = []
|
||||
print(validation_lines,'validation lines')
|
||||
for line in template.lines:
|
||||
print(line.id, 'validation')
|
||||
if line.id not in validation_lines:
|
||||
|
@ -570,7 +615,6 @@ class Opportunity(
|
|||
}
|
||||
lines.append(value)
|
||||
lines = ValidationLine.create(lines)
|
||||
print(lines,'lines')
|
||||
return lines
|
||||
|
||||
for record in records:
|
||||
|
@ -597,31 +641,71 @@ class Opportunity(
|
|||
@ModelView.button
|
||||
@Workflow.transition('review')
|
||||
def review(cls, records):
|
||||
pass
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Reconsideración'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('quote_revision')
|
||||
def quote_revision(cls, records):
|
||||
pass
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Revisión'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('quote_approbation')
|
||||
def quote_approbation(cls, records):
|
||||
pass
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Aprobación Interna'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('customer_approbation')
|
||||
def customer_approbation(cls, records):
|
||||
pass
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Aprobacion del Cliente'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('quote_approbation')
|
||||
def quote_approbation(cls, records):
|
||||
pass
|
||||
# @classmethod
|
||||
# @ModelView.button
|
||||
# @Workflow.transition('quote_approbation')
|
||||
# def quote_approbation(cls, records):
|
||||
# pass
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
@ -631,6 +715,17 @@ class Opportunity(
|
|||
# Analyze if party validation is true in all lines
|
||||
cls.get_party_validation(records)
|
||||
# cls.procces_opportunity(records)
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Cotización'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@property
|
||||
def is_forecast(self):
|
||||
|
@ -643,6 +738,17 @@ class Opportunity(
|
|||
@Workflow.transition('accepted')
|
||||
def accepted(cls, records):
|
||||
cls.procces_opportunity(records)
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Aceptado'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
def get_party_validation(cls, records):
|
||||
|
@ -687,6 +793,17 @@ class Opportunity(
|
|||
'end_date': Date.today(),
|
||||
'state': 'lost',
|
||||
})
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Perdido'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
@ -697,6 +814,17 @@ class Opportunity(
|
|||
cls.write([o for o in records if o.cancelled_reason], {
|
||||
'end_date': Date.today(),
|
||||
})
|
||||
traceability = Pool().get('crm.opportunity_traceability')
|
||||
history = []
|
||||
for record in records:
|
||||
value = {
|
||||
'opportunity':record.id,
|
||||
'validated_by':Transaction().user,
|
||||
'create_date':date.today(),
|
||||
'action':'Cambio de estado a Anulado'
|
||||
}
|
||||
history.append(value)
|
||||
history = traceability.create(history)
|
||||
|
||||
@staticmethod
|
||||
def _sale_won_states():
|
||||
|
@ -805,7 +933,6 @@ class OpportunityTraceability(ModelSQL, ModelView):
|
|||
__name__ = 'crm.opportunity_traceability'
|
||||
action = fields.Char('Action')
|
||||
opportunity = fields.Many2One('crm.opportunity', 'Opportunity', required=True )
|
||||
date_action = fields.Date('Date', required=True)
|
||||
observation = fields.Text('Observation')
|
||||
validated_by = fields.Many2One('res.user', 'User')
|
||||
|
||||
|
|
Loading…
Reference in New Issue