[IMP] sale_crm: Code Cleaning & minor improvements

bzr revid: mra@mra-laptop-20100809051449-un1ebkacst8wmvrx
This commit is contained in:
Mustufa Rangwala 2010-08-09 10:44:49 +05:30
parent 327eb96381
commit 30e462ff8f
6 changed files with 41 additions and 46 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
@ -15,11 +15,11 @@
# 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/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import sale_crm
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -19,7 +19,6 @@
#
##############################################################################
{
'name': 'Creates Sale orders from Opportunity',
'version': '1.0',
@ -49,4 +48,4 @@ crm modules.
'active': False,
'certificate': '0064360130141',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -28,7 +28,7 @@ class sale_order(osv.osv):
}
def _get_section(self, cr, uid, context=None):
return context.get('context_section_id',False)
return context.get('context_section_id', False)
_defaults = {
'section_id': _get_section
@ -36,4 +36,4 @@ class sale_order(osv.osv):
sale_order()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -25,7 +25,7 @@
</field>
</field>
</record>
<record id="view_sales_order_filter_inherit" model="ir.ui.view">
<field name="name">sale.order.list.select</field>
<field name="model">sale.order</field>
@ -42,7 +42,6 @@
</field>
</field>
</record>
</data>
</openerp>
</data>
</openerp>

View File

@ -19,9 +19,10 @@
#
##############################################################################
import time
from osv import fields, osv
from tools.translate import _
import time
import decimal_precision as dp
class crm_make_sale(osv.osv_memory):
@ -29,7 +30,7 @@ class crm_make_sale(osv.osv_memory):
_name = "crm.make.sale"
_description = "Make sale"
def _selectPartner(self, cr, uid, context=None):
"""
This function gets default value for partner_id field.
@ -38,17 +39,16 @@ class crm_make_sale(osv.osv_memory):
@param uid: the current users ID for security checks,
@param context: A standard dictionary for contextual values
@return : default value of partner_id field.
"""
"""
if not context:
context = {}
lead_obj = self.pool.get('crm.lead')
active_id = context and context.get('active_id', False) or False
if not active_id:
return False
lead_obj = self.pool.get('crm.lead')
lead = lead_obj.read(cr, uid, active_id, ['partner_id'])
return lead['partner_id']
return lead['partner_id']
def makeOrder(self, cr, uid, ids, context=None):
"""
This function create Quotation on given case.
@ -61,26 +61,26 @@ class crm_make_sale(osv.osv_memory):
"""
if not context:
context = {}
mod_obj = self.pool.get('ir.model.data')
case_obj = self.pool.get('crm.lead')
sale_obj = self.pool.get('sale.order')
partner_obj = self.pool.get('res.partner')
sale_line_obj = self.pool.get('sale.order.line')
result = mod_obj._get_id(cr, uid, 'sale', 'view_sales_order_filter')
id = mod_obj.read(cr, uid, result, ['res_id'])
data = context and context.get('active_ids', []) or []
for make in self.browse(cr, uid, ids):
for make in self.browse(cr, uid, ids):
default_partner_addr = partner_obj.address_get(cr, uid, [make.partner_id.id],
['invoice', 'delivery', 'contact'])
default_pricelist = partner_obj.browse(cr, uid, make.partner_id.id,
context).property_product_pricelist.id
fpos_data = partner_obj.browse(cr, uid, make.partner_id.id, context).property_account_position
new_ids = []
for case in case_obj.browse(cr, uid, data):
if case.partner_id and case.partner_id.id:
partner_id = case.partner_id.id
@ -94,10 +94,10 @@ class crm_make_sale(osv.osv_memory):
fpos = fpos_data and fpos_data.id or False
partner_addr = default_partner_addr
pricelist = default_pricelist
if False in partner_addr.values():
raise osv.except_osv(_('Data Insufficient!'),_('Customer has no addresses defined!'))
vals = {
'origin': 'Opportunity: %s' % str(case.id),
'section_id': case.section_id and case.section_id.id or False,
@ -110,11 +110,11 @@ class crm_make_sale(osv.osv_memory):
'date_order': time.strftime('%Y-%m-%d'),
'fiscal_position': fpos,
}
if partner_id:
partner = partner_obj.browse(cr, uid, partner_id, context=context)
vals['user_id'] = partner.user_id and partner.user_id.id or uid
if make.analytic_account.id:
vals['project_id'] = make.analytic_account.id
new_id = sale_obj.create(cr, uid, vals)
@ -139,10 +139,10 @@ class crm_make_sale(osv.osv_memory):
new_ids.append(new_id)
message = _('Opportunity ') + " '" + case.name + "' "+ _("is converted to Sales Quotation.")
self.log(cr, uid, case.id, message)
if make.close:
case_obj.case_close(cr, uid, data)
if not new_ids:
return {}
if len(new_ids)<=1:
@ -171,30 +171,29 @@ class crm_make_sale(osv.osv_memory):
'shop_id': fields.many2one('sale.shop', 'Shop', required=True),
'partner_id': fields.many2one('res.partner', 'Customer', required=True),
'sale_order_line': fields.one2many('sale.order.make.line', 'opportunity_order_id', 'Product Line'),
'analytic_account': fields.many2one('account.analytic.account', 'Analytic Account'),
'close': fields.boolean('Close Case', help='Check this to close the case after having created the sale order.'),
'analytic_account': fields.many2one('account.analytic.account', 'Analytic Account'),
'close': fields.boolean('Close Case', help='Check this to close the case after having created the sale order.'),
}
_defaults = {
'partner_id': _selectPartner,
'close': 1
}
crm_make_sale()
class sale_order_make_line(osv.osv_memory):
def product_id_change(self, cr, uid, ids, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, packaging=False, flag=False):
if not partner_id:
raise osv.except_osv(_('No Customer Defined !'), _('You have to select a customer in the sale form !\nPlease set one customer before choosing a product.'))
date_order = time.strftime('%Y-%m-%d')
date_order = time.strftime('%Y-%m-%d')
part = self.pool.get('res.partner').browse(cr, uid, partner_id)
pricelist = part.property_product_pricelist and part.property_product_pricelist.id or False
fiscal_position = part.property_account_position and part.property_account_position.id or False
return self.pool.get('sale.order.line').product_id_change(cr, uid, ids, pricelist, product, qty, uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag)
_name = 'sale.order.make.line'
_description = 'Opportunity Sale Order Line'
_columns = {
@ -223,8 +222,6 @@ class sale_order_make_line(osv.osv_memory):
'product_packaging': False
}
sale_order_make_line()
sale_order_make_line()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -58,20 +58,20 @@
</field>
<newline/>
<separator colspan="4"/>
<group col="4" colspan="4">
<label string="" colspan="2"/>
<button special="cancel" string="_Close" icon="gtk-cancel"/>
<button name="makeOrder" string="_Ok" type="object" icon='gtk-ok'/>
<button name="makeOrder" string="_Create" type="object" icon='gtk-ok'/>
</group>
</group>
</form>
</field>
</record>
<!-- crm make sale's action -->
<record id="action_crm_make_sale" model="ir.actions.act_window">
<field name="name">Make Quotation</field>
<field name="type">ir.actions.act_window</field>
@ -80,6 +80,6 @@
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>