From 7699504d62f33dd0b124ff66850485add6641637 Mon Sep 17 00:00:00 2001 From: "Ravish (Open ERP)" Date: Fri, 28 Mar 2014 15:28:35 +0530 Subject: [PATCH] [Add new sale_team module] --- addons/crm/__openerp__.py | 1 + addons/crm/crm.py | 100 +------ addons/crm/crm_case_section_view.xml | 244 +++------------ addons/crm/crm_lead.py | 13 +- addons/crm/res_config_view.xml | 11 - addons/crm/security/crm_security.xml | 14 +- addons/crm/security/ir.model.access.csv | 3 - addons/sale/__openerp__.py | 3 +- addons/sale/report/__init__.py | 3 +- .../report/sale_analysis_report.py} | 0 .../report/sale_analysis_report_view.xml} | 0 .../sales_crm_account_invoice_report.py | 0 addons/sale/sale.py | 81 ++++- addons/sale/sale_view.xml | 237 +++++++++++++++ addons/sale_crm/report/__init__.py | 4 +- addons/sale_crm/sale_crm.py | 108 +------ addons/sale_crm/sale_crm_view.xml | 278 +----------------- addons/sale_team/__init__.py | 25 ++ addons/sale_team/__openerp__.py | 36 +++ addons/sale_team/ir.model.access.csv | 5 + addons/sale_team/res_config_view.xml | 27 ++ addons/sale_team/sale_team.py | 153 ++++++++++ addons/sale_team/sale_team.xml | 232 +++++++++++++++ addons/sale_team/sale_team_config.py | 45 +++ addons/sale_team/sale_team_security.xml | 18 ++ 25 files changed, 917 insertions(+), 724 deletions(-) rename addons/{sale_crm/report/sale_report.py => sale/report/sale_analysis_report.py} (100%) rename addons/{sale_crm/report/sale_report_view.xml => sale/report/sale_analysis_report_view.xml} (100%) rename addons/{sale_crm => sale}/report/sales_crm_account_invoice_report.py (100%) create mode 100644 addons/sale_team/__init__.py create mode 100644 addons/sale_team/__openerp__.py create mode 100644 addons/sale_team/ir.model.access.csv create mode 100644 addons/sale_team/res_config_view.xml create mode 100644 addons/sale_team/sale_team.py create mode 100644 addons/sale_team/sale_team.xml create mode 100644 addons/sale_team/sale_team_config.py create mode 100644 addons/sale_team/sale_team_security.xml diff --git a/addons/crm/__openerp__.py b/addons/crm/__openerp__.py index 1b0cbed7937..7d5052c1c4e 100644 --- a/addons/crm/__openerp__.py +++ b/addons/crm/__openerp__.py @@ -51,6 +51,7 @@ Dashboard for CRM will include: 'depends': [ 'base_action_rule', 'base_setup', + 'sale_team', 'process', 'mail', 'email_template', diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 20e2a6e8aff..eb10e468602 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -90,45 +90,8 @@ class crm_case_stage(osv.osv): class crm_case_section(osv.osv): """ Model for sales teams. """ - _name = "crm.case.section" - _inherits = {'mail.alias': 'alias_id'} - _inherit = "mail.thread" + _inherit = 'crm.case.section' _description = "Sales Teams" - _order = "complete_name" - # number of periods for lead/opportunities/... tracking in salesteam kanban dashboard/kanban view - _period_number = 5 - - def get_full_name(self, cr, uid, ids, field_name, arg, context=None): - return dict(self.name_get(cr, uid, ids, context=context)) - - def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, context=None): - """ Generic method to generate data for bar chart values using SparklineBarWidget. - This method performs obj.read_group(cr, uid, domain, read_fields, groupby_field). - - :param obj: the target model (i.e. crm_lead) - :param domain: the domain applied to the read_group - :param list read_fields: the list of fields to read in the read_group - :param str value_field: the field used to compute the value of the bar slice - :param str groupby_field: the fields used to group - - :return list section_result: a list of dicts: [ - { 'value': (int) bar_column_value, - 'tootip': (str) bar_column_tooltip, - } - ] - """ - month_begin = date.today().replace(day=1) - section_result = [{ - 'value': 0, - 'tooltip': (month_begin + relativedelta.relativedelta(months=-i)).strftime('%B %Y'), - } for i in range(self._period_number - 1, -1, -1)] - group_obj = obj.read_group(cr, uid, domain, read_fields, groupby_field, context=context) - pattern = tools.DEFAULT_SERVER_DATE_FORMAT if obj.fields_get(cr, uid, groupby_field)[groupby_field]['type'] == 'date' else tools.DEFAULT_SERVER_DATETIME_FORMAT - for group in group_obj: - group_begin_date = datetime.strptime(group['__domain'][0][2], pattern) - month_delta = relativedelta.relativedelta(month_begin, group_begin_date) - section_result[self._period_number - (month_delta.months + 1)] = {'value': group.get(value_field, 0), 'tooltip': group.get(groupby_field, 0)} - return section_result def _get_opportunities_data(self, cr, uid, ids, field_name, arg, context=None): """ Get opportunities-related data for salesteam kanban view @@ -155,25 +118,7 @@ class crm_case_section(osv.osv): return res _columns = { - 'name': fields.char('Sales Team', size=64, required=True, translate=True), - 'complete_name': fields.function(get_full_name, type='char', size=256, readonly=True, store=True), - 'code': fields.char('Code', size=8), - 'active': fields.boolean('Active', help="If the active field is set to "\ - "true, it will allow you to hide the sales team without removing it."), - 'change_responsible': fields.boolean('Reassign Escalated', help="When escalating to this team override the salesman with the team leader."), - 'user_id': fields.many2one('res.users', 'Team Leader'), - 'member_ids': fields.many2many('res.users', 'sale_member_rel', 'section_id', 'member_id', 'Team Members'), - 'reply_to': fields.char('Reply-To', size=64, help="The email address put in the 'Reply-To' of all emails sent by OpenERP about cases in this sales team"), - 'parent_id': fields.many2one('crm.case.section', 'Parent Team'), - 'child_ids': fields.one2many('crm.case.section', 'parent_id', 'Child Teams'), - 'resource_calendar_id': fields.many2one('resource.calendar', "Working Time", help="Used to compute open days"), - 'note': fields.text('Description'), - 'working_hours': fields.float('Working Hours', digits=(16, 2)), 'stage_ids': fields.many2many('crm.case.stage', 'section_stage_rel', 'section_id', 'stage_id', 'Stages'), - 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, - help="The email address associated with this team. New emails received will automatically " - "create new leads assigned to the team."), - 'color': fields.integer('Color Index'), 'use_leads': fields.boolean('Leads', help="The first contact you get with a potential customer is a lead you qualify before converting it into a real business opportunity. Check this box to manage leads in this sales team."), @@ -190,52 +135,11 @@ class crm_case_section(osv.osv): return ids _defaults = { - 'active': 1, 'stage_ids': _get_stage_common, 'use_leads': True, } - _sql_constraints = [ - ('code_uniq', 'unique (code)', 'The code of the sales team must be unique !') - ] - - _constraints = [ - (osv.osv._check_recursion, 'Error ! You cannot create recursive Sales team.', ['parent_id']) - ] - - def name_get(self, cr, uid, ids, context=None): - """Overrides orm name_get method""" - if not isinstance(ids, list): - ids = [ids] - res = [] - if not ids: - return res - reads = self.read(cr, uid, ids, ['name', 'parent_id'], context) - - for record in reads: - name = record['name'] - if record['parent_id']: - name = record['parent_id'][1] + ' / ' + name - res.append((record['id'], name)) - return res - - def create(self, cr, uid, vals, context=None): - if context is None: - context = {} - create_context = dict(context, alias_model_name='crm.lead', alias_parent_model_name=self._name) - section_id = super(crm_case_section, self).create(cr, uid, vals, context=create_context) - section = self.browse(cr, uid, section_id, context=context) - self.pool.get('mail.alias').write(cr, uid, [section.alias_id.id], {'alias_parent_thread_id': section_id, 'alias_defaults': {'section_id': section_id, 'type': 'lead'}}, context=context) - return section_id - - def unlink(self, cr, uid, ids, context=None): - # Cascade-delete mail aliases as well, as they should not exist without the sales team. - mail_alias = self.pool.get('mail.alias') - alias_ids = [team.alias_id.id for team in self.browse(cr, uid, ids, context=context) if team.alias_id] - res = super(crm_case_section, self).unlink(cr, uid, ids, context=context) - mail_alias.unlink(cr, uid, alias_ids, context=context) - return res - + class crm_case_categ(osv.osv): """ Category of Case """ _name = "crm.case.categ" diff --git a/addons/crm/crm_case_section_view.xml b/addons/crm/crm_case_section_view.xml index d3ad226dbea..a56459a7065 100644 --- a/addons/crm/crm_case_section_view.xml +++ b/addons/crm/crm_case_section_view.xml @@ -84,195 +84,34 @@ crm.case.section.kanban crm.case.section + - + + - - - - - - - - - - - - - - - - - - - Case Sections - Search - crm.case.section - - - - - - - - - - - - - - - - - - - - Sales Teams - crm.case.section - form - kanban,tree,form - {'search_default_personal': True} - - -

- Click here to define a new sales team. -

- Use sales team to organize your different salespersons or - departments into separate teams. Each team will work in - its own list of opportunities. -

-
-
- - - - - crm.case.section.form - crm.case.section - -
- -
-
- - - - - - - - - - - - - - - - - - -
- X -
-
- -
-
-
-
-
-
-
-
- - - - - - - -
-
-
- - + + + + + + @@ -303,29 +142,26 @@ crm.case.section [('parent_id','=',False)] tree - + - - Sales Teams - crm.case.section - form - - -

- Click here to define a new sales team. -

- Use sales team to organize your different salespersons or - departments into separate teams. Each team will work in - its own list of opportunities. -

+ + crm.case.section.form + crm.case.section + + + +
+
+
+ + + + + +
- - \ No newline at end of file diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 4da0a509ed1..f97b7d0adf8 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -346,7 +346,18 @@ class crm_lead(format_address, osv.osv): if section_ids: section_id = section_ids[0] return {'value': {'section_id': section_id}} - + + def on_change_user(self, cr, uid, ids, user_id, context=None): + """ Override of on change user_id on lead/opportunity; when having sale + the new logic is : + - use user.default_section_id + - or fallback on previous behavior """ + if user_id: + user = self.pool.get('res.users').browse(cr, uid, user_id, context=context) + if user.default_section_id and user.default_section_id.id: + return {'value': {'section_id': user.default_section_id.id}} + return super(sale_crm_lead, self).on_change_user(cr, uid, ids, user_id, context=context) + def stage_find(self, cr, uid, cases, section_id, domain=None, order='sequence', context=None): """ Override of the base.stage method Parameter of the stage search taken from the lead: diff --git a/addons/crm/res_config_view.xml b/addons/crm/res_config_view.xml index b964cca5c7f..0ef4cfa6f1e 100644 --- a/addons/crm/res_config_view.xml +++ b/addons/crm/res_config_view.xml @@ -23,17 +23,6 @@
- - - diff --git a/addons/crm/security/crm_security.xml b/addons/crm/security/crm_security.xml index dfc3a56858e..bd2c3cdb3a4 100644 --- a/addons/crm/security/crm_security.xml +++ b/addons/crm/security/crm_security.xml @@ -24,19 +24,7 @@
- - Do Not Use Sales Teams - - - - - - - - Manage Sales Teams - - - + Manage Fund Raising diff --git a/addons/crm/security/ir.model.access.csv b/addons/crm/security/ir.model.access.csv index f3c6bdf5c1f..fde894e4c31 100644 --- a/addons/crm/security/ir.model.access.csv +++ b/addons/crm/security/ir.model.access.csv @@ -5,15 +5,12 @@ access_crm_segmentation,crm.segmentation,model_crm_segmentation,base.group_sale_ access_crm_segmentation_line,crm.segmentation.line,model_crm_segmentation_line,base.group_sale_manager,1,1,1,1 access_crm_case_channel_user,crm.case.channel user,model_crm_case_channel,base.group_sale_salesman,1,0,0,0 access_crm_case_channel_manager,crm.case.channel manager,model_crm_case_channel,base.group_sale_manager,1,1,1,1 -access_crm_case_section,crm.case.section,model_crm_case_section,base.group_user,1,0,0,0 access_crm_case_categ,crm.case.categ,model_crm_case_categ,base.group_sale_salesman,1,1,1,0 access_crm_lead_manager,crm.lead.manager,model_crm_lead,base.group_sale_manager,1,1,1,1 access_crm_phonecall_manager,crm.phonecall.manager,model_crm_phonecall,base.group_sale_manager,1,1,1,1 access_crm_case_categ,crm.case.categ,model_crm_case_categ,base.group_user,1,0,0,0 access_crm_lead,crm.lead,model_crm_lead,base.group_sale_salesman,1,1,1,0 access_crm_phonecall,crm.phonecall,model_crm_phonecall,base.group_sale_salesman,1,1,1,0 -access_crm_case_section_user,crm.case.section.user,model_crm_case_section,base.group_sale_salesman,1,0,0,0 -access_crm_case_section_manager,crm.case.section.manager,model_crm_case_section,base.group_sale_manager,1,1,1,1 access_crm_case_stage,crm.case.stage,model_crm_case_stage,,1,0,0,0 access_crm_case_stage_manager,crm.case.stage,model_crm_case_stage,base.group_sale_manager,1,1,1,1 access_crm_case_resource_type_user,crm_case_resource_type user,model_crm_case_resource_type,base.group_sale_salesman,1,1,1,0 diff --git a/addons/sale/__openerp__.py b/addons/sale/__openerp__.py index bb5bac89e46..44cbb3227ca 100644 --- a/addons/sale/__openerp__.py +++ b/addons/sale/__openerp__.py @@ -59,7 +59,7 @@ The Dashboard for the Sales Manager will include 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', 'images': ['images/sale_dashboard.jpeg','images/Sale_order_line_to_invoice.jpeg','images/sale_order.jpeg','images/sales_analysis.jpeg'], - 'depends': ['account_voucher'], + 'depends': ['sale_team','account_voucher'], 'data': [ 'wizard/sale_make_invoice_advance.xml', 'wizard/sale_line_invoice.xml', @@ -73,6 +73,7 @@ The Dashboard for the Sales Manager will include 'sale_view.xml', 'res_partner_view.xml', 'report/sale_report_view.xml', + 'report/sale_analysis_report_view.xml', 'process/sale_process.xml', 'board_sale_view.xml', 'edi/sale_order_action_data.xml', diff --git a/addons/sale/report/__init__.py b/addons/sale/report/__init__.py index 12d484c3e25..f1d48dd38e9 100644 --- a/addons/sale/report/__init__.py +++ b/addons/sale/report/__init__.py @@ -18,7 +18,8 @@ # along with this program. If not, see . # ############################################################################## - +import sales_crm_account_invoice_report import sale_report +import sale_analysis_report # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale_crm/report/sale_report.py b/addons/sale/report/sale_analysis_report.py similarity index 100% rename from addons/sale_crm/report/sale_report.py rename to addons/sale/report/sale_analysis_report.py diff --git a/addons/sale_crm/report/sale_report_view.xml b/addons/sale/report/sale_analysis_report_view.xml similarity index 100% rename from addons/sale_crm/report/sale_report_view.xml rename to addons/sale/report/sale_analysis_report_view.xml diff --git a/addons/sale_crm/report/sales_crm_account_invoice_report.py b/addons/sale/report/sales_crm_account_invoice_report.py similarity index 100% rename from addons/sale_crm/report/sales_crm_account_invoice_report.py rename to addons/sale/report/sales_crm_account_invoice_report.py diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 667f15a375d..93e4d90f612 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -18,9 +18,11 @@ # along with this program. If not, see . # ############################################################################## - -from datetime import datetime, timedelta +import calendar +from openerp import tools +from datetime import date, datetime, timedelta from dateutil.relativedelta import relativedelta +from dateutil import relativedelta import time from openerp.osv import fields, osv from openerp.tools.translate import _ @@ -162,6 +164,11 @@ class sale_order(osv.osv): if not company_id: raise osv.except_osv(_('Error!'), _('There is no default company for the current user!')) return company_id + + def _get_default_section_id(self, cr, uid, context=None): + """ Gives default section by checking if present in the context """ + section_id = self.pool.get('res.users').browse(cr, uid, uid, context).default_section_id.id or False + return section_id _columns = { 'name': fields.char('Order Reference', size=64, required=True, @@ -226,6 +233,7 @@ class sale_order(osv.osv): 'payment_term': fields.many2one('account.payment.term', 'Payment Term'), 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'), 'company_id': fields.many2one('res.company', 'Company'), + 'section_id': fields.many2one('crm.case.section', 'Sales Team'), } _defaults = { 'date_order': fields.date.context_today, @@ -237,7 +245,9 @@ class sale_order(osv.osv): 'invoice_quantity': 'order', 'partner_invoice_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['invoice'])['invoice'], 'partner_shipping_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['delivery'])['delivery'], - 'note': lambda self, cr, uid, context: self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.sale_note + 'note': lambda self, cr, uid, context: self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.sale_note, + 'section_id': lambda s, cr, uid, c: s._get_default_section_id(cr, uid, c), + } _sql_constraints = [ ('name_uniq', 'unique(name, company_id)', 'Order Reference must be unique per Company!'), @@ -372,12 +382,14 @@ class sale_order(osv.osv): 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, 'date_invoice': context.get('date_invoice', False), 'company_id': order.company_id.id, - 'user_id': order.user_id and order.user_id.id or False + 'user_id': order.user_id and order.user_id.id or False, + 'section_id' : order.section_id.id } # Care for deprecated _inv_get() hook - FIXME: to be removed after 6.1 invoice_vals.update(self._inv_get(cr, uid, order, context=context)) return invoice_vals + def _make_invoice(self, cr, uid, order, lines, context=None): inv_obj = self.pool.get('account.invoice') @@ -1000,11 +1012,14 @@ class mail_compose_message(osv.Model): context = dict(context, mail_post_autofollow=True) self.pool.get('sale.order').signal_quotation_sent(cr, uid, [context['default_res_id']]) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context) - + class account_invoice(osv.Model): _inherit = 'account.invoice' - + _columns = { + 'section_id': fields.many2one('crm.case.section', 'Sales Team'), + } + def confirm_paid(self, cr, uid, ids, context=None): sale_order_obj = self.pool.get('sale.order') res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context) @@ -1023,5 +1038,59 @@ class account_invoice(osv.Model): for id in ids: workflow.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr) return super(account_invoice, self).unlink(cr, uid, ids, context=context) + + _defaults = { + 'section_id': lambda self, cr, uid, c=None: self.pool.get('res.users').browse(cr, uid, uid, c).default_section_id.id or False, + } + +class crm_case_section(osv.osv): + _inherit = 'crm.case.section' + + def _get_sale_orders_data(self, cr, uid, ids, field_name, arg, context=None): + obj = self.pool.get('sale.order') + res = dict.fromkeys(ids, False) + month_begin = date.today().replace(day=1) + date_begin = (month_begin - relativedelta.relativedelta(months=self._period_number - 1)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + date_end = month_begin.replace(day=calendar.monthrange(month_begin.year, month_begin.month)[1]).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + for id in ids: + res[id] = dict() + created_domain = [('section_id', '=', id), ('state', '=', ['draft']), ('date_order', '>=', date_begin), ('date_order', '<=', date_end)] + res[id]['monthly_quoted'] = self.__get_bar_values(cr, uid, obj, created_domain, ['amount_total', 'date_order'], 'amount_total', 'date_order', context=context) + validated_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'sent', 'cancel']), ('date_order', '>=', date_begin), ('date_order', '<=', date_end)] + res[id]['monthly_confirmed'] = self.__get_bar_values(cr, uid, obj, validated_domain, ['amount_total', 'date_order'], 'amount_total', 'date_order', context=context) + return res + + def _get_invoices_data(self, cr, uid, ids, field_name, arg, context=None): + obj = self.pool.get('account.invoice.report') + res = dict.fromkeys(ids, False) + month_begin = date.today().replace(day=1) + date_begin = (month_begin - relativedelta.relativedelta(months=self._period_number - 1)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + date_end = month_begin.replace(day=calendar.monthrange(month_begin.year, month_begin.month)[1]).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + for id in ids: + created_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'cancel']), ('date', '>=', date_begin), ('date', '<=', date_end)] + res[id] = self.__get_bar_values(cr, uid, obj, created_domain, ['price_total', 'date'], 'price_total', 'date', context=context) + return res + + _columns = { + 'invoiced_forecast': fields.integer(string='Invoice Forecast', + help="Forecast of the invoice revenue for the current month. This is the amount the sales \n" + "team should invoice this month. It is used to compute the progression ratio \n" + " of the current and forecast revenue on the kanban view."), + 'invoiced_target': fields.integer(string='Invoice Target', + help="Target of invoice revenue for the current month. This is the amount the sales \n" + "team estimates to be able to invoice this month."), + 'monthly_quoted': fields.function(_get_sale_orders_data, + type='string', readonly=True, multi='_get_sale_orders_data', + string='Rate of created quotation per duration'), + 'monthly_confirmed': fields.function(_get_sale_orders_data, + type='string', readonly=True, multi='_get_sale_orders_data', + string='Rate of validate sales orders per duration'), + 'monthly_invoiced': fields.function(_get_invoices_data, + type='string', readonly=True, + string='Rate of sent invoices per duration'), + } + + def action_forecast(self, cr, uid, id, value, context=None): + return self.write(cr, uid, [id], {'invoiced_forecast': round(float(value))}, context=context) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index c9ffb94b985..9a6ef2a2e32 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -202,6 +202,7 @@ + @@ -255,12 +256,14 @@ + + @@ -518,5 +521,239 @@ + + + + Account Invoice + account.invoice + + + + + + + + + + + + + account.invoice.groupby + account.invoice + + + + + + + + + + + + + + Account Invoice + account.invoice + + + + + + + + + + + + + + + Sales Orders + ir.actions.act_window + sale.order + form + tree,form,calendar,graph + + [('state','not in',('draft','sent','cancel'))] + { + 'search_default_section_id': [active_id], + 'default_section_id': active_id, + } + + +

+ Click to create a quotation that can be converted into a sales + order. +

+ OpenERP will help you efficiently handle the complete sales flow: + quotation, sales order, delivery, invoicing and payment. +

+
+
+ + + Quotations + ir.actions.act_window + sale.order + form + + tree,form,calendar,graph + { + 'search_default_section_id': [active_id], + 'default_section_id': active_id, + 'show_address': 1, + } + + [('state','in',('draft','sent','cancel'))] + + +

+ Click to create a quotation, the first step of a new sale. +

+ OpenERP will help you handle efficiently the complete sale flow: + from the quotation to the sales order, the + delivery, the invoicing and the payment collection. +

+ The social feature helps you organize discussions on each sales + order, and allow your customers to keep track of the evolution + of the sales order. +

+
+
+ + + Invoices + account.invoice + form + tree,form,calendar,graph + + [ + ('state', 'not in', ['draft', 'cancel']), + ('type', '=', 'out_invoice')] + { + 'search_default_section_id': [active_id], + 'default_section_id': active_id, + 'default_type':'out_invoice', + 'type':'out_invoice', + 'journal_type': 'sale', + } + + + + + + 1 + tree + + + + + 2 + form + + + + + + Quotations Analysis + sale.report + graph + [('state','=','draft'),('section_id', '=', active_id)] + {'search_default_order_month':1} + This report performs analysis on your quotations. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application. + + + + Sales Analysis + sale.report + graph + [('state','not in',('draft','sent','cancel')),('section_id', '=', active_id)] + {'search_default_order_month':1} + This report performs analysis on your sales orders. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application. + + + + Invoices Analysis + account.invoice.report + graph + [('section_id', '=', active_id),('state', 'not in', ['draft', 'cancel'])] + {'search_default_month':1} + From this report, you can have an overview of the amount invoiced to your customer. The tool search can also be used to personalise your Invoices reports and so, match this analysis to your needs. + + + + crm.case.section.form + crm.case.section + + + + + + + + + + + + + crm.case.section.kanban + crm.case.section + + + + + + + + + + + + + + + + +
+ Invoiced + Forecast +
+
+
Define an invoicing target in the sales team settings to see the period's achievement and forecast at a glance. +
+
+
+
+
diff --git a/addons/sale_crm/report/__init__.py b/addons/sale_crm/report/__init__.py index d86b3e66de9..3fd45ac3f8f 100644 --- a/addons/sale_crm/report/__init__.py +++ b/addons/sale_crm/report/__init__.py @@ -19,8 +19,8 @@ # ############################################################################## -import sales_crm_account_invoice_report -import sale_report + + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 9bcb5adf6ae..510daf30c3b 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -26,117 +26,11 @@ from dateutil import relativedelta from openerp import tools from openerp.osv import osv, fields -class res_users(osv.Model): - _inherit = 'res.users' - _columns = { - 'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'), - } - - def __init__(self, pool, cr): - init_res = super(res_users, self).__init__(pool, cr) - # duplicate list to avoid modifying the original reference - self.SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS) - self.SELF_WRITEABLE_FIELDS.extend(['default_section_id']) - return init_res - class sale_order(osv.osv): _inherit = 'sale.order' _columns = { - 'section_id': fields.many2one('crm.case.section', 'Sales Team'), 'categ_ids': fields.many2many('crm.case.categ', 'sale_order_category_rel', 'order_id', 'category_id', 'Categories', \ domain="['|',('section_id','=',section_id),('section_id','=',False), ('object_id.model', '=', 'crm.lead')]", context="{'object_name': 'crm.lead'}") } - - def _get_default_section_id(self, cr, uid, context=None): - """ Gives default section by checking if present in the context """ - section_id = self.pool.get('crm.lead')._resolve_section_id_from_context(cr, uid, context=context) or False - if not section_id: - section_id = self.pool.get('res.users').browse(cr, uid, uid, context).default_section_id.id or False - return section_id - - _defaults = { - 'section_id': lambda s, cr, uid, c: s._get_default_section_id(cr, uid, c), - } - - def _prepare_invoice(self, cr, uid, order, lines, context=None): - invoice_vals = super(sale_order, self)._prepare_invoice(cr, uid, order, lines, context=context) - if order.section_id and order.section_id.id: - invoice_vals['section_id'] = order.section_id.id - return invoice_vals - - -class crm_case_section(osv.osv): - _inherit = 'crm.case.section' - - def _get_sale_orders_data(self, cr, uid, ids, field_name, arg, context=None): - obj = self.pool.get('sale.order') - res = dict.fromkeys(ids, False) - month_begin = date.today().replace(day=1) - date_begin = (month_begin - relativedelta.relativedelta(months=self._period_number - 1)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) - date_end = month_begin.replace(day=calendar.monthrange(month_begin.year, month_begin.month)[1]).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) - for id in ids: - res[id] = dict() - created_domain = [('section_id', '=', id), ('state', '=', ['draft']), ('date_order', '>=', date_begin), ('date_order', '<=', date_end)] - res[id]['monthly_quoted'] = self.__get_bar_values(cr, uid, obj, created_domain, ['amount_total', 'date_order'], 'amount_total', 'date_order', context=context) - validated_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'sent', 'cancel']), ('date_order', '>=', date_begin), ('date_order', '<=', date_end)] - res[id]['monthly_confirmed'] = self.__get_bar_values(cr, uid, obj, validated_domain, ['amount_total', 'date_order'], 'amount_total', 'date_order', context=context) - return res - - def _get_invoices_data(self, cr, uid, ids, field_name, arg, context=None): - obj = self.pool.get('account.invoice.report') - res = dict.fromkeys(ids, False) - month_begin = date.today().replace(day=1) - date_begin = (month_begin - relativedelta.relativedelta(months=self._period_number - 1)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) - date_end = month_begin.replace(day=calendar.monthrange(month_begin.year, month_begin.month)[1]).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) - for id in ids: - created_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'cancel']), ('date', '>=', date_begin), ('date', '<=', date_end)] - res[id] = self.__get_bar_values(cr, uid, obj, created_domain, ['price_total', 'date'], 'price_total', 'date', context=context) - return res - - _columns = { - 'invoiced_forecast': fields.integer(string='Invoice Forecast', - help="Forecast of the invoice revenue for the current month. This is the amount the sales \n" - "team should invoice this month. It is used to compute the progression ratio \n" - " of the current and forecast revenue on the kanban view."), - 'invoiced_target': fields.integer(string='Invoice Target', - help="Target of invoice revenue for the current month. This is the amount the sales \n" - "team estimates to be able to invoice this month."), - 'monthly_quoted': fields.function(_get_sale_orders_data, - type='string', readonly=True, multi='_get_sale_orders_data', - string='Rate of created quotation per duration'), - 'monthly_confirmed': fields.function(_get_sale_orders_data, - type='string', readonly=True, multi='_get_sale_orders_data', - string='Rate of validate sales orders per duration'), - 'monthly_invoiced': fields.function(_get_invoices_data, - type='string', readonly=True, - string='Rate of sent invoices per duration'), - } - - def action_forecast(self, cr, uid, id, value, context=None): - return self.write(cr, uid, [id], {'invoiced_forecast': round(float(value))}, context=context) - -class sale_crm_lead(osv.Model): - _inherit = 'crm.lead' - - def on_change_user(self, cr, uid, ids, user_id, context=None): - """ Override of on change user_id on lead/opportunity; when having sale - the new logic is : - - use user.default_section_id - - or fallback on previous behavior """ - if user_id: - user = self.pool.get('res.users').browse(cr, uid, user_id, context=context) - if user.default_section_id and user.default_section_id.id: - return {'value': {'section_id': user.default_section_id.id}} - return super(sale_crm_lead, self).on_change_user(cr, uid, ids, user_id, context=context) - - -class account_invoice(osv.osv): - _inherit = 'account.invoice' - _columns = { - 'section_id': fields.many2one('crm.case.section', 'Sales Team'), - } - _defaults = { - 'section_id': lambda self, cr, uid, c=None: self.pool.get('res.users').browse(cr, uid, uid, c).default_section_id.id or False, - } - + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml index 88d7fe8be6c..102eb9462fa 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -27,285 +27,9 @@ - - - - sale.order.list.select - sale.order - - - - - - - - - - - - - - - Account Invoice - account.invoice - - - - - - - - - - - - - account.invoice.groupby - account.invoice - - - - - - - - - - - - - - Account Invoice - account.invoice - - - - - - - - - - - - - Users Preferences - res.users - - - - - - - - - - - - - res.users.preferences.form - res.users - - - - - - - - - - - - - - Sales Orders - ir.actions.act_window - sale.order - form - tree,form,calendar,graph - - [('state','not in',('draft','sent','cancel'))] - { - 'search_default_section_id': [active_id], - 'default_section_id': active_id, - } - - -

- Click to create a quotation that can be converted into a sales - order. -

- OpenERP will help you efficiently handle the complete sales flow: - quotation, sales order, delivery, invoicing and payment. -

-
-
- - - Quotations - ir.actions.act_window - sale.order - form - - tree,form,calendar,graph - { - 'search_default_section_id': [active_id], - 'default_section_id': active_id, - 'show_address': 1, - } - - [('state','in',('draft','sent','cancel'))] - - -

- Click to create a quotation, the first step of a new sale. -

- OpenERP will help you handle efficiently the complete sale flow: - from the quotation to the sales order, the - delivery, the invoicing and the payment collection. -

- The social feature helps you organize discussions on each sales - order, and allow your customers to keep track of the evolution - of the sales order. -

-
-
- - - Invoices - account.invoice - form - tree,form,calendar,graph - - [ - ('state', 'not in', ['draft', 'cancel']), - ('type', '=', 'out_invoice')] - { - 'search_default_section_id': [active_id], - 'default_section_id': active_id, - 'default_type':'out_invoice', - 'type':'out_invoice', - 'journal_type': 'sale', - } - - - - - - 1 - tree - - - - - 2 - form - - - - - - Quotations Analysis - sale.report - graph - [('state','=','draft'),('section_id', '=', active_id)] - {'search_default_order_month':1} - This report performs analysis on your quotations. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application. - - - - Sales Analysis - sale.report - graph - [('state','not in',('draft','sent','cancel')),('section_id', '=', active_id)] - {'search_default_order_month':1} - This report performs analysis on your sales orders. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application. - - - - Invoices Analysis - account.invoice.report - graph - [('section_id', '=', active_id),('state', 'not in', ['draft', 'cancel'])] - {'search_default_month':1} - From this report, you can have an overview of the amount invoiced to your customer. The tool search can also be used to personalise your Invoices reports and so, match this analysis to your needs. - - - - crm.case.section.form - crm.case.section - - - - - - - - - - - - - crm.case.section.kanban - crm.case.section - - - - - - - - - - - - - - - - - - -
- Invoiced - Forecast -
-
-
Define an invoicing target in the sales team settings to see the period's achievement and forecast at a glance. -
-
-
-
-
- + diff --git a/addons/sale_team/__init__.py b/addons/sale_team/__init__.py new file mode 100644 index 00000000000..6bac200f0db --- /dev/null +++ b/addons/sale_team/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import sale_team +import sale_team_config + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/sale_team/__openerp__.py b/addons/sale_team/__openerp__.py new file mode 100644 index 00000000000..9c303ae3ae3 --- /dev/null +++ b/addons/sale_team/__openerp__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name' : 'Sale Team', + 'version' : '1.0', + 'author' : 'OpenERP SA', + 'category': 'hidden', + 'sequence': 10, + 'summary': 'Sales Team', + 'description': """ """, + 'website': 'http://www.openerp.com', + 'depends' : ['base','web_kanban','calendar'], + 'data': ['sale_team.xml','sale_team_security.xml','res_config_view.xml','ir.model.access.csv'], + 'demo': [], + 'installable': True, + 'auto_install': True, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale_team/ir.model.access.csv b/addons/sale_team/ir.model.access.csv new file mode 100644 index 00000000000..9817ad834f6 --- /dev/null +++ b/addons/sale_team/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_crm_case_section,crm.case.section,model_crm_case_section,base.group_user,1,0,0,0 +access_crm_case_section_user,crm.case.section.user,model_crm_case_section,base.group_sale_salesman,1,0,0,0 +access_crm_case_section_manager,crm.case.section.manager,model_crm_case_section,base.group_sale_manager,1,1,1,1 + diff --git a/addons/sale_team/res_config_view.xml b/addons/sale_team/res_config_view.xml new file mode 100644 index 00000000000..7723fda48fc --- /dev/null +++ b/addons/sale_team/res_config_view.xml @@ -0,0 +1,27 @@ + + + + + + crm settings + sale.team.config.settings + + + +
+ + + +
+
+
+
+
diff --git a/addons/sale_team/sale_team.py b/addons/sale_team/sale_team.py new file mode 100644 index 00000000000..3643a6dc26c --- /dev/null +++ b/addons/sale_team/sale_team.py @@ -0,0 +1,153 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-today OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +import calendar +from datetime import date, datetime +from dateutil import relativedelta + +from openerp import tools +from openerp.osv import fields +from openerp.osv import osv + + + +class crm_case_section(osv.osv): + _name = "crm.case.section" + _inherits = {'mail.alias': 'alias_id'} + _inherit = ['mail.thread', 'ir.needaction_mixin'] + _description = "Sales Teams" + _order = "complete_name" + # number of periods for lead/opportunities/... tracking in salesteam kanban dashboard/kanban view + _period_number = 5 + + def get_full_name(self, cr, uid, ids, field_name, arg, context=None): + return dict(self.name_get(cr, uid, ids, context=context)) + + def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, context=None): + + """ Generic method to generate data for bar chart values using SparklineBarWidget. + This method performs obj.read_group(cr, uid, domain, read_fields, groupby_field). + + :param obj: the target model (i.e. crm_lead) + :param domain: the domain applied to the read_group + :param list read_fields: the list of fields to read in the read_group + :param str value_field: the field used to compute the value of the bar slice + :param str groupby_field: the fields used to group + + :return list section_result: a list of dicts: [ + { 'value': (int) bar_column_value, + 'tootip': (str) bar_column_tooltip, + } + ] + """ + month_begin = date.today().replace(day=1) + section_result = [{ + 'value': 0, + 'tooltip': (month_begin + relativedelta.relativedelta(months=-i)).strftime('%B %Y'), + } for i in range(self._period_number - 1, -1, -1)] + group_obj = obj.read_group(cr, uid, domain, read_fields, groupby_field, context=context) + pattern = tools.DEFAULT_SERVER_DATE_FORMAT if obj.fields_get(cr, uid, groupby_field)[groupby_field]['type'] == 'date' else tools.DEFAULT_SERVER_DATETIME_FORMAT + for group in group_obj: + group_begin_date = datetime.strptime(group['__domain'][0][2], pattern) + month_delta = relativedelta.relativedelta(month_begin, group_begin_date) + section_result[self._period_number - (month_delta.months + 1)] = {'value': group.get(value_field, 0), 'tooltip': group.get(groupby_field, 0)} + return section_result + + _columns = { + 'name': fields.char('Sales Team', size=64, required=True, translate=True), + 'complete_name': fields.function(get_full_name, type='char', size=256, readonly=True, store=True), + 'code': fields.char('Code', size=8), + 'active': fields.boolean('Active', help="If the active field is set to "\ + "true, it will allow you to hide the sales team without removing it."), + 'change_responsible': fields.boolean('Reassign Escalated', help="When escalating to this team override the salesman with the team leader."), + 'user_id': fields.many2one('res.users', 'Team Leader'), + 'member_ids': fields.many2many('res.users', 'sale_member_rel', 'section_id', 'member_id', 'Team Members'), + 'reply_to': fields.char('Reply-To', size=64, help="The email address put in the 'Reply-To' of all emails sent by OpenERP about cases in this sales team"), + 'parent_id': fields.many2one('crm.case.section', 'Parent Team'), + 'child_ids': fields.one2many('crm.case.section', 'parent_id', 'Child Teams'), + 'resource_calendar_id': fields.many2one('resource.calendar', "Working Time", help="Used to compute open days"), + 'note': fields.text('Description'), + 'working_hours': fields.float('Working Hours', digits=(16, 2)), + 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, help="The email address associated with this team. New emails received will automatically ""create new leads assigned to the team."), + 'color': fields.integer('Color Index'), + } + + _defaults = { + 'active': 1, + } + + _sql_constraints = [ + ('code_uniq', 'unique (code)', 'The code of the sales team must be unique !') + ] + + _constraints = [ + (osv.osv._check_recursion, 'Error ! You cannot create recursive Sales team.', ['parent_id']) + ] + + def name_get(self, cr, uid, ids, context=None): + """Overrides orm name_get method""" + if not isinstance(ids, list): + ids = [ids] + res = [] + if not ids: + return res + reads = self.read(cr, uid, ids, ['name', 'parent_id'], context) + + for record in reads: + name = record['name'] + if record['parent_id']: + name = record['parent_id'][1] + ' / ' + name + res.append((record['id'], name)) + return res + + def create(self, cr, uid, vals, context=None): + if context is None: + context = {} + create_context = dict(context, alias_model_name=self._name, alias_parent_model_name=self._name) + section_id = super(crm_case_section, self).create(cr, uid, vals, context=create_context) + section = self.browse(cr, uid, section_id, context=context) + self.pool.get('mail.alias').write(cr, uid, [section.alias_id.id], {'alias_parent_thread_id': section_id, 'alias_defaults': {'section_id': section_id, 'type': 'lead'}}, context=context) + return section_id + + def unlink(self, cr, uid, ids, context=None): + # Cascade-delete mail aliases as well, as they should not exist without the sales team. + mail_alias = self.pool.get('mail.alias') + alias_ids = [team.alias_id.id for team in self.browse(cr, uid, ids, context=context) if team.alias_id] + res = super(crm_case_section, self).unlink(cr, uid, ids, context=context) + mail_alias.unlink(cr, uid, alias_ids, context=context) + return res + +class res_users(osv.Model): + _inherit = 'res.users' + _columns = { + 'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'), + } + + def __init__(self, pool, cr): + init_res = super(res_users, self).__init__(pool, cr) + # duplicate list to avoid modifying the original reference + self.SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS) + self.SELF_WRITEABLE_FIELDS.extend(['default_section_id']) + return init_res + + + \ No newline at end of file diff --git a/addons/sale_team/sale_team.xml b/addons/sale_team/sale_team.xml new file mode 100644 index 00000000000..687919ff66a --- /dev/null +++ b/addons/sale_team/sale_team.xml @@ -0,0 +1,232 @@ + + + + + + + Users Preferences + res.users + + + + + + + + + + + + + res.users.preferences.form + res.users + + + + + + + + + + + + + + crm.case.section.kanban + crm.case.section + + + + + + + + + + +
+
+ í +
+
+

+
+ %% +
+
+
+ + + +
+
+
+
+
+
+
+
+ + + + + + + Case Sections - Search + crm.case.section + + + + + + + + + + + + + + + + + + + + Sales Teams + crm.case.section + form + kanban,tree,form + {} + + +

+ Click here to define a new sales team. +

+ Use sales team to organize your different salespersons or + departments into separate teams. Each team will work in + its own list of opportunities. +

+
+
+ + + + + crm.case.section.form + crm.case.section + +
+ +
+
+ + + + + + + + + + + + + + + + + + +
+ X +
+
+ +
+
+
+
+
+
+
+
+ + + +
+
+
+ + +
+
+
+
+ + + + + crm.case.section.tree + crm.case.section + child_ids + + + + + + + + + + + + + + + Sales Teams + crm.case.section + form + + +

+ Click here to define a new sales team. +

+ Use sales team to organize your different salespersons or + departments into separate teams. Each team will work in + its own list of opportunities. +

+
+
+ + +
+
\ No newline at end of file diff --git a/addons/sale_team/sale_team_config.py b/addons/sale_team/sale_team_config.py new file mode 100644 index 00000000000..33a5e84b8de --- /dev/null +++ b/addons/sale_team/sale_team_config.py @@ -0,0 +1,45 @@ + +from openerp import SUPERUSER_ID +from openerp.osv import fields, osv + + +class sala_team_configuration(osv.TransientModel): + _name = 'sale.team.config.settings' + _inherit = ['sale.config.settings', 'fetchmail.config.settings'] + + def set_group_multi_salesteams(self, cr, uid, ids, context=None): + """ This method is automatically called by res_config as it begins + with set. It is used to implement the 'one group or another' + behavior. We have to perform some group manipulation by hand + because in res_config.execute(), set_* methods are called + after group_*; therefore writing on an hidden res_config file + could not work. + If group_multi_salesteams is checked: remove group_mono_salesteams + from group_user, remove the users. Otherwise, just add + group_mono_salesteams in group_user. + The inverse logic about group_multi_salesteams is managed by the + normal behavior of 'group_multi_salesteams' field. + """ + def ref(xml_id): + mod, xml = xml_id.split('.', 1) + return self.pool['ir.model.data'].get_object(cr, uid, mod, xml, context) + + for obj in self.browse(cr, uid, ids, context=context): + config_group = ref('base.group_mono_salesteams') + base_group = ref('base.group_user') + if obj.group_multi_salesteams: + base_group.write({'implied_ids': [(3, config_group.id)]}) + config_group.write({'users': [(3, u.id) for u in base_group.users]}) + else: + base_group.write({'implied_ids': [(4, config_group.id)]}) + return True + + _columns = { + + 'group_multi_salesteams': fields.boolean("Organize Sales activities into multiple Sales Teams", + implied_group='base.group_multi_salesteams', + help="""Allows you to use Sales Teams to manage your leads and opportunities."""), + } + + + diff --git a/addons/sale_team/sale_team_security.xml b/addons/sale_team/sale_team_security.xml new file mode 100644 index 00000000000..ff8eef01678 --- /dev/null +++ b/addons/sale_team/sale_team_security.xml @@ -0,0 +1,18 @@ + + + + + Do Not Use Sales Teams + + + + + + + + Manage Sales Teams + + + + +