[CLEAN] sale, sale_crm: cleaning before merging. Cleaned calculation

of default section id + removed duplicated code.
This commit is contained in:
Thibault Delavallée 2014-05-12 14:56:01 +02:00
parent 9199587ec9
commit 3406b6db39
9 changed files with 56 additions and 52 deletions

View File

@ -91,7 +91,7 @@ Dashboard for CRM will include:
'res_config_view.xml', 'res_config_view.xml',
'base_partner_merge_view.xml', 'base_partner_merge_view.xml',
'crm_case_section_view.xml', 'sales_team_view.xml',
'views/crm.xml', 'views/crm.xml',
], ],
'demo': [ 'demo': [

View File

@ -6,6 +6,6 @@
<record model="gamification.challenge" id="challenge_crm_sale"> <record model="gamification.challenge" id="challenge_crm_sale">
<field name="state">inprogress</field> <field name="state">inprogress</field>
</record> </record>
</data> </data>
</openerp> </openerp>

View File

@ -19,16 +19,10 @@
# #
############################################################################## ##############################################################################
#----------------------------------------------------------
# Init Sales
#----------------------------------------------------------
import sale import sale
import crm_case_section import sales_team
import res_partner import res_partner
import wizard import wizard
import report import report
import edi import edi
import res_config import res_config
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -71,7 +71,7 @@ The Dashboard for the Sales Manager will include
'sale_report.xml', 'sale_report.xml',
'sale_data.xml', 'sale_data.xml',
'sale_view.xml', 'sale_view.xml',
'crm_case_section_view.xml', 'sales_team_view.xml',
'res_partner_view.xml', 'res_partner_view.xml',
'report/sale_report_view.xml', 'report/sale_report_view.xml',
'edi/sale_order_action_data.xml', 'edi/sale_order_action_data.xml',

View File

@ -19,11 +19,7 @@
# #
############################################################################## ##############################################################################
import calendar from datetime import datetime, timedelta
from openerp import tools
from datetime import date, datetime, timedelta
from dateutil.relativedelta import relativedelta
from dateutil import relativedelta
import time import time
from openerp.osv import fields, osv from openerp.osv import fields, osv
from openerp.tools.translate import _ from openerp.tools.translate import _
@ -166,12 +162,29 @@ class sale_order(osv.osv):
if not company_id: if not company_id:
raise osv.except_osv(_('Error!'), _('There is no default company for the current user!')) raise osv.except_osv(_('Error!'), _('There is no default company for the current user!'))
return company_id return company_id
def _get_default_section_id(self, cr, uid, context=None): def _get_default_section_id(self, cr, uid, context=None):
""" Gives default section by checking if present in the context """ """ 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 section_id = self._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 return section_id
def _resolve_section_id_from_context(self, cr, uid, context=None):
""" Returns ID of section based on the value of 'section_id'
context key, or None if it cannot be resolved to a single
Sales Team.
"""
if context is None:
context = {}
if type(context.get('default_section_id')) in (int, long):
return context.get('default_section_id')
if isinstance(context.get('default_section_id'), basestring):
section_ids = self.pool.get('crm.case.section').name_search(cr, uid, name=context['default_section_id'], context=context)
if len(section_ids) == 1:
return int(section_ids[0][0])
return None
_columns = { _columns = {
'name': fields.char('Order Reference', size=64, required=True, 'name': fields.char('Order Reference', size=64, required=True,
readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, select=True), readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, select=True),
@ -252,7 +265,6 @@ class sale_order(osv.osv):
'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'], '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), 'section_id': lambda s, cr, uid, c: s._get_default_section_id(cr, uid, c),
} }
_sql_constraints = [ _sql_constraints = [
('name_uniq', 'unique(name, company_id)', 'Order Reference must be unique per Company!'), ('name_uniq', 'unique(name, company_id)', 'Order Reference must be unique per Company!'),
@ -1199,13 +1211,40 @@ class mail_compose_message(osv.Model):
self.pool.get('sale.order').signal_quotation_sent(cr, uid, [context['default_res_id']]) 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) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
class account_invoice(osv.Model): class account_invoice(osv.Model):
_inherit = 'account.invoice' _inherit = 'account.invoice'
def _get_default_section_id(self, cr, uid, context=None):
""" Gives default section by checking if present in the context """
section_id = self._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
def _resolve_section_id_from_context(self, cr, uid, context=None):
""" Returns ID of section based on the value of 'section_id'
context key, or None if it cannot be resolved to a single
Sales Team.
"""
if context is None:
context = {}
if type(context.get('default_section_id')) in (int, long):
return context.get('default_section_id')
if isinstance(context.get('default_section_id'), basestring):
section_ids = self.pool.get('crm.case.section').name_search(cr, uid, name=context['default_section_id'], context=context)
if len(section_ids) == 1:
return int(section_ids[0][0])
return None
_columns = { _columns = {
'section_id': fields.many2one('crm.case.section', 'Sales Team'), 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
} }
_defaults = {
'section_id': lambda self, cr, uid, c=None: self._get_default_section_id(cr, uid, context=c)
}
def confirm_paid(self, cr, uid, ids, context=None): def confirm_paid(self, cr, uid, ids, context=None):
sale_order_obj = self.pool.get('sale.order') sale_order_obj = self.pool.get('sale.order')
res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context) res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context)
@ -1224,10 +1263,6 @@ class account_invoice(osv.Model):
for id in ids: for id in ids:
workflow.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr) workflow.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
return super(account_invoice, self).unlink(cr, uid, ids, context=context) 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 procurement_order(osv.osv): class procurement_order(osv.osv):

View File

@ -1,35 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import calendar import calendar
from openerp import tools from datetime import date
from datetime import date, datetime, timedelta
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from dateutil import relativedelta
import time from openerp import tools
from openerp.osv import fields, osv from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
import openerp.addons.decimal_precision as dp
from openerp import workflow
class crm_case_section(osv.osv): class crm_case_section(osv.osv):

View File

@ -29,7 +29,6 @@ from openerp.osv import osv, fields
class sale_order(osv.osv): class sale_order(osv.osv):
_inherit = 'sale.order' _inherit = 'sale.order'
_columns = { _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', 'Tags', \ 'categ_ids': fields.many2many('crm.case.categ', 'sale_order_category_rel', 'order_id', 'category_id', 'Tags', \
domain="['|', ('section_id', '=', section_id), ('section_id', '=', False), ('object_id.model', '=', 'crm.lead')]", context="{'object_name': 'crm.lead'}") domain="['|', ('section_id', '=', section_id), ('section_id', '=', False), ('object_id.model', '=', 'crm.lead')]", context="{'object_name': 'crm.lead'}")
} }