Skip to content

Commit

Permalink
Merge branch '141_version2' into R_10.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s committed Feb 16, 2017
2 parents f54bfb2 + 9cd430f commit e796b46
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 0 deletions.
2 changes: 2 additions & 0 deletions odoo/data/upgrade/10_0_4/base.action.rule.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,active,model_id/id,sequence,name,kind,filter_pre_id/id,filter_id/id,server_action_ids/id,filter_pre_domain,filter_domain
__setup__.bar_crm_lead_3_arrival,True,crm.model_crm_lead,1,"cannot go to collect information state",on_write,__setup__.filter_crm_lead_1_2,__setup__.filter_crm_lead_3,"__setup__.server_action_crm_lead_check_3_arrival","['|',('stage_id.name', 'ilike', '1'), ('stage_id.name', 'ilike', '2')]","[('stage_id.name', 'ilike', '3')]"
23 changes: 23 additions & 0 deletions odoo/data/upgrade/10_0_4/ir.actions.server.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
id,name,state,type,model_id/id,condition,sequence,code
__setup__.server_action_crm_lead_check_3_arrival,check fields,code,ir.actions.server,crm.model_crm_lead,True,1,"# Available variables:
# - time, datetime, dateutil, timezone: Python libraries
# - env: Odoo Environement
# - model: Model of the record on which the action is triggered
# - record: Record on which the action is triggered if there is one, otherwise None
# - records: Records on which the action is triggered if there is one, otherwise None
# - log : log(message), function to log debug information in logging table
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {...}

fields = ['project_id', 'start_date', 'end_date', 'signature_ids']
record.check_fields(fields=fields)
"
__setup__.server_action_crm_lead_check_4_arrival,check fields,code,ir.actions.server,crm.model_crm_lead,True,1,"
fields = ['survey_id', 'survey_inputs']
record.check_fields(fields=fields)

record.check_survey_state()
"
__setup__.server_action_crm_lead_check_4_arrival2,create task,code,ir.actions.server,crm.model_crm_lead,True,5,"
record.create_linked_task()
"
4 changes: 4 additions & 0 deletions odoo/data/upgrade/10_0_4/ir.filters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,active,domain,name,model_id
__setup__.filter_crm_lead_1_2,True,"['|',('stage_id.name', 'ilike', '1'), ('stage_id.name', 'ilike', '2')]",Demand |NDA,crm.lead
__setup__.filter_crm_lead_3,True,"[('stage_id.name', 'ilike', '3')]",Lead TRF,crm.lead
__setup__.filter_crm_lead_4,True,"[('stage_id.name', 'ilike', '4')]",Lead Feasability,crm.lead
1 change: 1 addition & 0 deletions odoo/local-src/specific_crm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'views/crm_lead_view.xml',
'views/survey_templates.xml',
'views/crm_team.xml',
'views/project_task.xml',
],
'installable': True,
}
1 change: 1 addition & 0 deletions odoo/local-src/specific_crm/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from . import crm_lead
from . import survey
from . import crm_team
from . import project_task
24 changes: 24 additions & 0 deletions odoo/local-src/specific_crm/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# Author: Damien Crier
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import uuid
from datetime import datetime, timedelta

from odoo import models, fields, api
from odoo import exceptions, _


class CrmLead(models.Model):
Expand Down Expand Up @@ -90,3 +92,25 @@ def answer_selected_survey(self):
# 'target': 'new',
'url': url,
}

def check_fields(self, fields=None):
msg = []
if fields:
for f in fields:
if not self[f]:
msg.append(('%s not filled.') % f)

if msg:
raise exceptions.Warning('\n'.join(msg))

def check_survey_state(self):
for s_input in self.survey_inputs:
if s_input.state == 'done':
return True

raise exceptions.Warning(_('Survey not completly answered'))

def create_linked_task(self):
self.env['project.task'].create({'project_id': self.project_id.id,
'lead_id': self.id,
'name': self.name})
14 changes: 14 additions & 0 deletions odoo/local-src/specific_crm/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Author: Damien Crier
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields


class ProjectTask(models.Model):
_inherit = 'project.task'

lead_id = fields.Many2one(comodel_name='crm.lead',
string="Linked Opportunity")
survey_input_lines = fields.One2many(related='lead_id.survey_input_lines')
21 changes: 21 additions & 0 deletions odoo/local-src/specific_crm/views/project_task.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_task_form2_lead" model="ir.ui.view">
<field name="name">project.task.form lead</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field eval="2" name="priority"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='project_id']" position="after">
<field name="lead_id"/>
</xpath>
<xpath expr="//notebook" position="inside">
<page string="Survey Result" name="lead_survey" attrs="{'invisible': [('lead_id', '=', False)]}">
<field name="survey_input_lines"/>
</page>
</xpath>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions odoo/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ migration:
- anthem songs.install.crm::import_crm_stages
- anthem songs.install.crm::create_sales_team
- anthem songs.install.crm::add_stage_to_sale_team
- anthem songs.upgrade.10_0_4.crm::main
addons:
upgrade:
- specific_crm
Expand Down
Empty file.
79 changes: 79 additions & 0 deletions odoo/songs/upgrade/10_0_4/crm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from pkg_resources import resource_stream

import anthem
from anthem.lyrics.records import create_or_update
from anthem.lyrics.loaders import load_csv_stream
from ...common import req


@anthem.log
def import_filters(ctx):
content = resource_stream(req, 'data/upgrade/10_0_4/ir.filters.csv')
load_csv_stream(ctx, 'ir.filters', content, delimiter=',')


@anthem.log
def import_server_actions(ctx):
content = resource_stream(req, 'data/upgrade/10_0_4/ir.actions.server.csv')
load_csv_stream(ctx, 'ir.actions.server', content, delimiter=',')


@anthem.log
def import_action_rule(ctx):
content = resource_stream(req, 'data/upgrade/10_0_4/base.action.rule.csv')
load_csv_stream(ctx, 'base.action.rule', content, delimiter=',')


@anthem.log
def create_base_action_rules(ctx):
lead_model = ctx.env['ir.model'].search([('model', '=', 'crm.lead')],
limit=1)
bar = {
'__setup__.bar_crm_lead_3_arrival': {
'active': True,
'model_id': lead_model.id,
'sequence': 1,
'name': 'cannot go to collect information state',
'kind': 'on_write',
'filter_pre_id': ctx.env.ref('__setup__.filter_crm_lead_1_2').id,
'filter_pre_domain': "['|',('stage_id.name', 'ilike', '1'),"
"('stage_id.name', 'ilike', '2')]",
'filter_id': ctx.env.ref('__setup__.filter_crm_lead_3').id,
'filter_domain': "[('stage_id.name', 'ilike', '3')]",
'server_action_ids': [
(4, ctx.env.ref(
'__setup__.server_action_crm_lead_check_3_arrival').id)],
},
'__setup__.bar_crm_lead_4_arrival': {
'active': True,
'model_id': lead_model.id,
'sequence': 1,
'name': 'cannot go to feasability state',
'kind': 'on_write',
'filter_pre_id': ctx.env.ref('__setup__.filter_crm_lead_3').id,
'filter_pre_domain': "[('stage_id.name', 'ilike', '3')]",
'filter_id': ctx.env.ref('__setup__.filter_crm_lead_4').id,
'filter_domain': "[('stage_id.name', 'ilike', '4')]",
'server_action_ids': [
(4, ctx.env.ref(
'__setup__.server_action_crm_lead_check_4_arrival').id),
(4, ctx.env.ref(
'__setup__.server_action_crm_lead_check_4_arrival2').id)],
}
}

for k, v in bar.iteritems():
create_or_update(ctx, 'base.action.rule', k, v)


@anthem.log
def main(ctx):
""" Main: creating demo data """
import_filters(ctx)
import_server_actions(ctx)
# import_action_rule(ctx)
create_base_action_rules(ctx)
Empty file added odoo/songs/upgrade/__init__.py
Empty file.

0 comments on commit e796b46

Please sign in to comment.