[IMP]: Improved code: added functionality to the respected modules. Added get and set methods.

bzr revid: uco@tinyerp.com-20120229095021-ogpd1s4nyxa7wdns
This commit is contained in:
Ujjvala Collins (OpenERP) 2012-02-29 15:20:21 +05:30
parent 48e45f8eb8
commit adc65d5cfa
20 changed files with 599 additions and 288 deletions

View File

@ -37,4 +37,5 @@ import ir_sequence
import company
import res_currency
import edi
import res_config
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,47 @@
# -*- 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/>.
#
##############################################################################
from osv import fields, osv
class account_configuration(osv.osv_memory):
_inherit = 'res.config'
_columns = {
'tax_policy': fields.selection([
('no_tax', 'No Tax'),
('global_on_order', 'Global On Order'),
('on_order_line', 'On Order Lines'),
], 'Taxes', required=True),
'tax_value': fields.float('Value'),
}
_defaults = {
'tax_policy': 'global_on_order',
'tax_value': 15.0,
}
def get_tax_value(self, cr, uid, ids, context=None):
result = {}
chart_account_obj = self.pool.get('wizard.multi.charts.accounts')
chart_account_obj.execute(cr, uid, ids, context=context)
return result
account_configuration()

View File

@ -0,0 +1,8 @@
class account_configuration(osv.osv_memory):
_inherit = 'res.config'
_columns = {
'tax_value' : fields.many2one('account.tax', 'Value'),
}
account_configuration()

View File

@ -28,6 +28,7 @@ import crm_phonecall
import report
import wizard
import res_partner
import res_config
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -111,6 +111,8 @@ Creates a dashboard for CRM that includes:
'res_partner_view.xml',
'board_crm_statistical_view.xml',
'board_crm_view.xml',
'res_config_view.xml',
],
'demo_xml': [

96
addons/crm/res_config.py Normal file
View File

@ -0,0 +1,96 @@
# -*- 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/>.
#
##############################################################################
from osv import fields, osv
class crm_configuration(osv.osv_memory):
_inherit = 'res.config'
_columns = {
'crm_caldav' : fields.boolean("Use caldav to synchronize Meetings",
help="Install crm_caldav module: Caldav features in Meeting"),
'fetchmail_crm': fields.boolean("Lead/Opportunity mail gateway"),
'server' : fields.char('Server Name', size=256),
'port' : fields.integer('Port'),
'type': fields.selection([
('pop', 'POP Server'),
('imap', 'IMAP Server'),
('local', 'Local Server'),
], 'Server Type'),
'is_ssl': fields.boolean('SSL/TLS', help="Connections are encrypted with SSL/TLS through a dedicated port (default: IMAPS=993, POP=995)"),
'user' : fields.char('Username', size=256),
'password' : fields.char('Password', size=1024),
}
_defaults = {
'type': 'pop',
}
def get_default_email_configurations(self, cr, uid, ids, context=None):
ir_values_obj = self.pool.get('ir.values')
result = {}
installed_modules = self.get_default_installed_modules(cr, uid, ids, context=context)
if 'fetchmail_crm' in installed_modules.keys():
for val in ir_values_obj.get(cr, uid, 'default', False, ['fetchmail.server']):
result.update({val[1]: val[2]})
return result
def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False):
port = 0
values = {}
if server_type == 'pop':
port = ssl and 995 or 110
elif server_type == 'imap':
port = ssl and 993 or 143
else:
values['server'] = ''
values['port'] = port
return {'value': values}
def set_email_configurations(self, cr, uid, ids, vals, context=None):
model_obj = self.pool.get('ir.model')
fetchmail_obj = self.pool.get('fetchmail.server')
ir_values_obj = self.pool.get('ir.values')
if vals.get('fetchmail_crm'):
object_id = model_obj.search(cr, uid, [('model','=','crm.lead')])[0]
fetchmail_vals = {
'name': 'Incoming Leads',
'object_id': object_id,
'server': vals.get('server'),
'port': vals.get('port'),
'is_ssl': vals.get('is_ssl'),
'type': vals.get('type'),
'user': vals.get('user'),
'password': vals.get('password')
}
if not self.get_installed_modules(cr, uid, ['fetchmail_crm'], context):
fetchmail_obj.create(cr, uid, fetchmail_vals, context=context)
else:
fetchmail_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Leads')], context=context)
fetchmail_obj.write(cr, uid, fetchmail_ids, fetchmail_vals, context=context)
ir_values_obj.set(cr, uid, 'default', False, 'server', ['fetchmail.server'], fetchmail_vals.get('server'))
ir_values_obj.set(cr, uid, 'default', False, 'port', ['fetchmail.server'], fetchmail_vals.get('port'))
ir_values_obj.set(cr, uid, 'default', False, 'is_ssl', ['fetchmail.server'], fetchmail_vals.get('is_ssl'))
ir_values_obj.set(cr, uid, 'default', False, 'type', ['fetchmail.server'], fetchmail_vals.get('type'))
ir_values_obj.set(cr, uid, 'default', False, 'user', ['fetchmail.server'], fetchmail_vals.get('user'))
ir_values_obj.set(cr, uid, 'default', False, 'password', ['fetchmail.server'], fetchmail_vals.get('password'))
crm_configuration()

View File

@ -0,0 +1,36 @@
<openerp>
<data>
<record id="view_sales_config_crm" model="ir.ui.view">
<field name="name">Sales Application</field>
<field name="model">res.config</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.res_config_view_base"/>
<field name="arch" type="xml">
<xpath expr="//form/group[@name='emails']" position="inside">
<group col="2" colspan="2">
<separator string="Emails" colspan="4"/>
<field name="fetchmail_crm" colspan="2"/>
<newline/>
<group col="4" colspan="4"
attrs="{'invisible': [('fetchmail_crm','=',False)]}">
<field name="server" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="type" nolabel="1" on_change="onchange_server_type(type, is_ssl)" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="port" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="is_ssl" on_change="onchange_server_type(type, is_ssl)"/>
<newline/>
<field name="user" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="password" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
</group>
</group>
</xpath>
<xpath expr="//form/group[@name='synchronization']" position="inside">
<group colspan="2" col="2">
<field name="crm_caldav"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@ -48,9 +48,9 @@
<field name="target">new</field>
</record>
<record id="view_config_outlook_installer" model="ir.ui.view">
<!--record id="view_config_outlook_installer" model="ir.ui.view">
<field name="name">Sales Application</field>
<field name="model">sale.configuration</field>
<field name="model">res.config</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_config_picking_policy"/>
<field name="arch" type="xml">
@ -58,7 +58,7 @@
<button name="%(action_outlook_installer)d" type="action" string="Configure Outlook Plug-In" icon="gtk-execute" colspan="2"/>
</field>
</field>
</record>
</record-->
<record id="action_outlook_wizard" model="ir.actions.act_window">
<field name="name">Install Outlook Plug-In</field>

View File

@ -55,9 +55,9 @@
<field name="target">new</field>
</record>
<record id="view_config_thunderbird_installer" model="ir.ui.view">
<!--record id="view_config_thunderbird_installer" model="ir.ui.view">
<field name="name">Sales Application</field>
<field name="model">sale.configuration</field>
<field name="model">res.config</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_config_picking_policy"/>
<field name="arch" type="xml">
@ -65,7 +65,7 @@
<button name="%(action_thunderbird_installer)d" type="action" string="Configure Thunderbird Plug-In" icon="gtk-execute" colspan="2"/>
</field>
</field>
</record>
</record-->
<menuitem id="base.menu_base_config_plugins" name="Plugins" parent="base.menu_base_config" sequence="10"/>
<menuitem id="menu_base_config_plugins_thunderbird" action="action_thunderbird_installer" parent="base.menu_base_config_plugins" sequence="10"/>

View File

@ -23,5 +23,6 @@ import pricelist
import report
import partner
import wizard
import res_config
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,32 @@
# -*- 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/>.
#
##############################################################################
from osv import fields, osv
class product_groups_configuration(osv.osv_memory):
_inherit = 'res.config'
_columns = {
'group_sale_pricelist_per_customer':fields.boolean("Pricelist per customer ",help="Group to Activate pricelist to manage prices per customer"),
'group_sale_uom_per_product':fields.boolean("UOM per product",help="Group to Allow different unit of measure per product"),
}
product_groups_configuration()

View File

@ -18,6 +18,21 @@
<field name="name">Product Variant</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_sale_pricelist_per_customer" model="res.groups">
<field name="name">Sales Pricelists</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_sale_uom_per_product" model="res.groups">
<field name="name">Product UOM</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_user" model="res.groups">
<field name="implied_ids" eval="[(6,0,[ref('base.group_sale_pricelist_per_customer'),
ref('base.group_sale_uom_per_product')])]"/>
</record>
<record model="ir.rule" id="product_pricelist_comp_rule">
<field name="name">product pricelist company rule</field>

View File

@ -29,5 +29,6 @@ import wizard
import report
import company
import edi
import res_config
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -85,6 +85,7 @@ Dashboard for Sales Manager that includes:
'process/sale_process.xml',
'board_sale_view.xml',
'edi/sale_order_action_data.xml',
'res_config_view.xml',
],
'demo_xml': ['sale_demo.xml'],
'test': [

218
addons/sale/res_config.py Normal file
View File

@ -0,0 +1,218 @@
# -*- 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/>.
#
##############################################################################
from osv import fields, osv
import pooler
from tools.translate import _
MODULE_LIST = [
'analytic_user_function', 'analytic_journal_billing_rate', 'import_sugarcrm',
'import_google', 'crm_caldav', 'wiki_sale_faq', 'base_contact','sale_layout','warning',
'google_map', 'fetchmail_crm', 'plugin_thunderbird', 'plugin_outlook','account_analytic_analysis',
'project_timesheet', 'account_analytic_analysis', 'project_mrp', 'delivery',
'sale_margin', 'sale_journal'
]
class sale_configuration(osv.osv_memory):
_inherit = 'res.config'
_columns = {
'sale_orders': fields.boolean('Based on Sales Orders',),
'deli_orders': fields.boolean('Based on Delivery Orders'),
'task_work': fields.boolean('Based on Tasks\' Work'),
'timesheet': fields.boolean('Based on Timesheet'),
'order_policy': fields.selection([
('manual', 'Invoice Based on Sales Orders'),
('picking', 'Invoice Based on Deliveries'),
], 'Main Method Based On', required=True, help="You can generate invoices based on sales orders or based on shippings."),
'charge_delivery': fields.boolean('Do you charge the delivery?'),
'time_unit': fields.many2one('product.uom','Working Time Unit'),
'picking_policy' : fields.boolean("Deliver all products at once?"),
'group_sale_delivery_address':fields.boolean("Multiple Address",help="Group To Allow delivery address different from invoice address"),
'group_sale_disc_per_sale_order_line':fields.boolean("Discounts per sale order lines ",help="Group to apply discounts per sale order lines"),
'sale_layout':fields.boolean("Notes & subtotals per line",help="Install sale_layout module: This module provides features to improve the layout of the Sales Order.."),
'warning': fields.boolean("Alerts by products or customers",
help="Install warning module: Module to trigger warnings in OpenERP objects."),
'sale_margin': fields.boolean("Display Margin For Users",
help="Install sale_margin module: This module adds the 'Margin' on sales order."),
'sale_journal': fields.boolean("Invoice journal?",
help="Install sale_journal module: The sales journal modules allows you to categorise your sales and deliveries (picking lists) between different journals."),
'analytic_user_function' : fields.boolean("User function by contracts",
help="Install analytic_user_function module:This module allows you to define what is the default function of a specific user on a given account"),
'analytic_journal_billing_rate' : fields.boolean("Billing rates by contracts",
help="Install analytic_journal_billing_rate module: This module allows you to define what is the default invoicing rate for a specific journal on a given account."),
'import_sugarcrm' : fields.boolean("Import data from sugarCRM?",
help="Install import_sugarcrm module: This Module Import SugarCRM Leads, Opportunities, Users, Accounts, Contacts, Employees, Meetings, Phonecalls, Emails, and Project, Project Tasks Data into OpenERP Module."),
'import_google' : fields.boolean("Import Contacts & Meetings from Google",
help="Install import_google module: The module adds google contact in partner address and add google calendar events details in Meeting"),
'wiki_sale_faq' : fields.boolean("Install a sales FAQ?",
help="Install wiki_sale_faq module: This module provides a Wiki Sales FAQ Template."),
'base_contact' : fields.boolean("Manage a several address per customer",
help="Install crm_partner_assign module: This is the module used by OpenERP SA to redirect customers to its partners, based on geolocalization."),
'google_map' : fields.boolean("Google maps on customer",
help="Install google_map module: The module adds Google Map field in partner address."),
'plugin_thunderbird': fields.boolean('Thunderbird plugin',
help="Install plugin_thunderbird module: This module is required for the Thuderbird Plug-in to work properly."),
'plugin_outlook': fields.boolean('Outlook plugin',
help="Install plugin_outlook module: This module provides the Outlook Plug-in."),
'account_analytic_analysis': fields.boolean('Contracts',
help="Install account_analytic_analysis module: This module is for modifying account analytic view to show important data to project manager of services companies."),
}
def get_default_applied_groups(self, cr, uid, ids, context=None):
applied_groups = {}
user_obj = self.pool.get('res.users')
dataobj = self.pool.get('ir.model.data')
groups = []
user_group_ids = user_obj.browse(cr, uid, uid, context=context).groups_id
for group_id in user_group_ids:
groups.append(group_id.id)
for id in groups:
key_id = dataobj.search(cr, uid,[('res_id','=',id),('model','=','res.groups')],context=context)
key = dataobj.browse(cr, uid, key_id[0], context=context).name
applied_groups[key] = True
return applied_groups
def get_default_installed_modules(self, cr, uid, ids, context=None):
module_obj = self.pool.get('ir.module.module')
module_ids = module_obj.search(cr, uid,
[('name','in',MODULE_LIST),
('state','in',['to install', 'installed', 'to upgrade'])],
context=context)
installed_modules = dict([(mod.name,True) for mod in module_obj.browse(cr, uid, module_ids, context=context)])
return installed_modules
def get_default_sale_configs(self, cr, uid, ids, context=None):
ir_values_obj = self.pool.get('ir.values')
result = {}
defaults = ir_values_obj.get(cr, uid, 'default', False, ['sale.order'])
return result
def get_default_groups(self, cr, uid, ids, context=None):
ir_values_obj = self.pool.get('ir.values')
result = {}
defaults = ir_values_obj.get(cr, uid, 'default', False, ['res.users'])
return result
def default_get(self, cr, uid, fields_list, context=None):
result = super(sale_configuration, self).default_get(
cr, uid, fields_list, context=context)
for method in dir(self):
if method.startswith('get_default_'):
result.update(getattr(self, method)(cr, uid, [], context))
return result
_defaults = {
'order_policy': 'manual',
'time_unit': lambda self, cr, uid, c: self.pool.get('product.uom').search(cr, uid, [('name', '=', _('Hour'))], context=c) and self.pool.get('product.uom').search(cr, uid, [('name', '=', _('Hour'))], context=c)[0] or False,
}
def create(self, cr, uid, vals, context=None):
ids = super(sale_configuration, self).create(cr, uid, vals, context=context)
self.execute(cr, uid, [ids], vals, context=context)
return ids
def write(self, cr, uid, ids, vals, context=None):
self.execute(cr, uid, ids, vals, context=context)
return super(sale_configuration, self).write(cr, uid, ids, vals, context=context)
def execute(self, cr, uid, ids, vals, context=None):
#TODO: TO BE IMPLEMENTED
for method in dir(self):
if method.startswith('set_'):
getattr(self, method)(cr, uid, ids, vals, context)
return True
def set_modules(self, cr, uid, ids, vals, context=None):
module_obj = self.pool.get('ir.module.module')
for k, v in vals.items():
if k in MODULE_LIST:
installed = self.get_default_installed_modules(cr, uid, [k], context)
if v == True and not installed:
module_id = module_obj.search(cr, uid, [('name','=',k)])[0]
module_obj.state_update(cr, uid, [module_id], 'to install', ['uninstalled'], context)
cr.commit()
pooler.restart_pool(cr.dbname, update_module=True)[1]
elif v == False and installed.get(k):
module_id = module_obj.search(cr, uid, [('name','=',k)])[0]
module_obj.state_update(cr, uid, [module_id], 'to remove', ['installed'], context)
cr.commit()
pooler.restart_pool(cr.dbname, update_module=True)[1]
def set_sale_defaults(self, cr, uid, ids, vals, context=None):
ir_values_obj = self.pool.get('ir.values')
data_obj = self.pool.get('ir.model.data')
menu_obj = self.pool.get('ir.ui.menu')
res = {}
wizard = self.browse(cr, uid, ids)[0]
if wizard.sale_orders:
menu_id = data_obj.get_object(cr, uid, 'sale', 'menu_invoicing_sales_order_lines').id
menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_id)]})
ir_values_obj.set(cr, uid, 'default', False, 'groups_id', ['ir.ui.menu'], [(4,group_id)])
if wizard.deli_orders:
menu_id = data_obj.get_object(cr, uid, 'sale', 'menu_action_picking_list_to_invoice').id
menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_id)]})
ir_values_obj.set(cr, uid, 'default', False, 'groups_id', ['ir.ui.menu'], [(4,group_id)])
if wizard.picking_policy:
ir_values_obj.set(cr, uid, 'default', False, 'picking_policy', ['sale.order'], 'one')
if wizard.time_unit:
prod_id = data_obj.get_object(cr, uid, 'product', 'product_consultant').id
product_obj = self.pool.get('product.product')
product_obj.write(cr, uid, prod_id, {'uom_id': wizard.time_unit.id, 'uom_po_id': wizard.time_unit.id})
ir_values_obj.set(cr, uid, 'default', False, 'order_policy', ['sale.order'], wizard.order_policy)
if wizard.task_work and wizard.time_unit:
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
self.pool.get('res.company').write(cr, uid, [company_id], {
'project_time_mode_id': wizard.time_unit.id
}, context=context)
return res
def set_groups(self, cr, uid, ids, vals, context=None):
data_obj = self.pool.get('ir.model.data')
users_obj = self.pool.get('res.users')
groups_obj = self.pool.get('res.groups')
ir_values_obj = self.pool.get('ir.values')
dummy,user_group_id = data_obj.get_object_reference(cr, uid, 'base', 'group_user')
for group in vals.keys():
if group.startswith('group_'):
dummy,group_id = data_obj.get_object_reference(cr, uid, 'base', group)
if vals[group]:
groups_obj.write(cr, uid, [user_group_id], {'implied_ids': [(4,group_id)]})
users_obj.write(cr, uid, [uid], {'groups_id': [(4,group_id)]})
ir_values_obj.set(cr, uid, 'default', False, 'groups_id', ['res.users'], [(4,group_id)])
else:
groups_obj.write(cr, uid, [user_group_id], {'implied_ids': [(3,group_id)]})
users_obj.write(cr, uid, [uid], {'groups_id': [(3,group_id)]})
ir_values_obj.set(cr, uid, 'default', False, 'groups_id', ['res.users'], [(3,group_id)])
sale_configuration()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,121 @@
<openerp>
<data>
<record id="view_sales_config" model="ir.ui.view">
<field name="name">Sales Application</field>
<field name="model">res.config</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.res_config_view_base"/>
<field name="arch" type="xml">
<form position="replace">
<form string="Sale Configuration">
<separator string="Picking and Invoice Policy" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<field name="sale_orders"/>
<newline/>
<field name="deli_orders"/>
<newline/>
<field name="task_work"/>
<newline/>
<field name="timesheet"/>
<newline/>
</group>
<group colspan="4" col="4">
<field name="order_policy" attrs="{'invisible':['|',('sale_orders','=',False),('deli_orders','=',False)]}"/>
<newline/>
<field name="charge_delivery" attrs="{'invisible':[('sale_orders','=',False), ('deli_orders','=',False)]}"/>
<newline/>
<field name="picking_policy" attrs="{'invisible':[('deli_orders','=',False)]}"/>
<newline/>
<field name="time_unit" domain="[('category_id.name','=','Working Time')]" attrs="{'invisible':[('task_work','=',False),('timesheet','=',False)],'required': [('timesheet','=',True)]}"/>
</group>
</group>
<separator string="Sale Order" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<field name="group_sale_pricelist_per_customer"/>
<newline/>
<group colspan="4" col="4">
<field name="tax_policy" />
<field name="tax_value" nolabel="1"/>
</group>
<newline/>
<field name="sale_margin"/>
<newline/>
<field name="warning"/>
<newline/>
</group>
<group colspan="4" col="4">
<newline/>
<field name="group_sale_uom_per_product"/>
<newline/>
<field name="group_sale_delivery_address"/>
<newline/>
<field name="group_sale_disc_per_sale_order_line"/>
<newline/>
<field name="sale_layout"/>
<newline/>
<field name="sale_journal"/>
<newline/>
</group>
</group>
<separator string="Contracts" colspan="4"/>
<group colspan="4" col="4">
<group colspan="4" col="4">
<field name="account_analytic_analysis"/>
<newline/>
</group>
</group>
<group col="4" colspan="4" name="emails">
<group col="2" colspan="2">
<separator string="Plugins" colspan="2"/>
<field name="plugin_thunderbird" colspan="2"/>
<newline/>
<field name="plugin_outlook" colspan="2"/>
</group>
</group>
<group colspan="4" col="4" name="synchronization">
<separator string="Import and Synchronize data from an other application" colspan="4"/>
<group colspan="2" col="2">
<field name="import_sugarcrm"/>
<newline/>
<field name="import_google"/>
</group>
</group>
<group colspan="4" col="4">
<group colspan="2" col="2">
<separator string="Documents and Wiki" colspan="2"/>
<field name="wiki_sale_faq" />
</group>
<group colspan="2" col="2">
<separator string="Customer Form" colspan="2"/>
<field name="base_contact"/>
<newline/>
<field name="google_map"/>
</group>
</group>
</form>
</form>
</field>
</record>
<record id="action_sale_config" model="ir.actions.act_window">
<field name="name">Configure Sales Application</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.config</field>
<field name="view_id" ref="view_sales_config"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>
<menuitem id="menu_sale_config" name="Sales" parent="base.menu_config" sequence="1" action="action_sale_config"/>
</data>
</openerp>

View File

@ -28,7 +28,7 @@ from tools.translate import _
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, float_compare
import decimal_precision as dp
import netsvc
from openerp.addons.base.res import res_config_sale as sale_config
#from openerp.addons.base.res import res_config_sale as sale_config
class sale_shop(osv.osv):
_name = "sale.shop"
@ -1331,202 +1331,4 @@ class sale_order_line(osv.osv):
sale_order_line()
sale_config.MODULE_LIST += [
'project_timesheet', 'account_analytic_analysis', 'project_mrp', 'delivery',
'sale_margin', 'sale_journal'
]
class sale_configuration(osv.osv_memory):
_inherit = 'sale.configuration'
_columns = {
'sale_orders': fields.boolean('Based on Sales Orders',),
'deli_orders': fields.boolean('Based on Delivery Orders'),
'task_work': fields.boolean('Based on Tasks\' Work'),
'timesheet': fields.boolean('Based on Timesheet'),
'order_policy': fields.selection([
('manual', 'Invoice Based on Sales Orders'),
('picking', 'Invoice Based on Deliveries'),
], 'Main Method Based On', required=True, help="You can generate invoices based on sales orders or based on shippings."),
'charge_delivery': fields.boolean('Do you charge the delivery?'),
'time_unit': fields.many2one('product.uom','Working Time Unit'),
'picking_policy' : fields.boolean("Deliver all products at once?"),
'group_sale_pricelist_per_customer':fields.boolean("Pricelist per customer ",help="Group to Activate pricelist to manage prices per customer"),
'group_sale_uom_per_product':fields.boolean("UOM per product",help="Group to Allow different unit of measure per product"),
'group_sale_delivery_address':fields.boolean("Multiple Address",help="Group To Allow delivery address different from invoice address"),
'group_sale_disc_per_sale_order_line':fields.boolean("Discounts per sale order lines ",help="Group to apply discounts per sale order lines"),
'sale_layout':fields.boolean("Notes & subtotals per line",help="Install sale_layout module: This module provides features to improve the layout of the Sales Order.."),
'warning': fields.boolean("Alerts by products or customers",
help="Install warning module: Module to trigger warnings in OpenERP objects."),
'tax_value' : fields.float('Value'),
'tax_value_id': fields.many2one('account.tax.template'),
'tax_policy': fields.selection([
('no_tax', 'No Tax'),
('global_on_order', 'Global On Order'),
('on_order_line', 'On Order Lines'),
], 'Taxes', required=True),
'sale_margin': fields.boolean("Display Margin For Users",
help="Install sale_margin module: This module adds the 'Margin' on sales order."),
'sale_journal': fields.boolean("Invoice journal?",
help="Install sale_journal module: The sales journal modules allows you to categorise your sales and deliveries (picking lists) between different journals."),
}
def default_get(self, cr, uid, fields_list, context=None):
ir_values_obj = self.pool.get('ir.values')
data_obj = self.pool.get('ir.model.data')
obj_tax_temp = self.pool.get('account.tax.template')
res = super(sale_configuration, self).default_get(
cr, uid, fields_list, context=context)
defaults = {}
module_list = sale_config.MODULE_LIST
defaults.update(self.get_installed_modules(cr, uid, module_list, context=context))
defaults.update(self.get_applied_groups(cr, uid, context=context))
for val in ir_values_obj.get(cr, uid, 'default', False, ['sale.order']):
defaults.update({val[1]: val[2]})
for k in defaults.keys():
if k in ['project_timesheet','project_mrp']:
defaults.update({'task_work': True})
prod_id = data_obj.get_object(cr, uid, 'product', 'product_consultant').id
uom_id = self.pool.get('product.product').browse(cr, uid, prod_id).uom_id.id
defaults.update({'time_unit': uom_id})
if k in ['account_analytic_analysis']:
defaults.update({'timesheet': True})
prod_id = data_obj.get_object(cr, uid, 'product', 'product_consultant').id
uom_id = self.pool.get('product.product').browse(cr, uid, prod_id).uom_id.id
defaults.update({'time_unit': uom_id})
if k == 'delivery':
defaults.update({'sale_orders': True, 'deli_orders': True, 'charge_delivery': True})
if k == 'picking_policy' and defaults[k]=='one':
defaults.update({'picking_policy': True})
if k == 'order_policy':
defaults.update({'order_policy': defaults.get('order_policy')})
if k == 'tax_policy' and defaults[k] == ['global_on_order','on_order_line']:
ref_tax_ids = obj_tax_temp.search(cr, uid, [('type_tax_use','in', ('sale','all'))], context=context, order="sequence, id desc", limit=1)
res.update({'tax_value_id': ref_tax_ids and ref_tax_ids[0] or False})
else:
res.update({k: False})
res.update(defaults)
return res
_defaults = {
'order_policy': 'manual',
'tax_policy': 'global_on_order',
'time_unit': lambda self, cr, uid, c: self.pool.get('product.uom').search(cr, uid, [('name', '=', _('Hour'))], context=c) and self.pool.get('product.uom').search(cr, uid, [('name', '=', _('Hour'))], context=c)[0] or False,
}
#TODO: Need to check
# def onchange_order(self, cr, uid, ids, sale, deli, context=None):
# res = {}
# if sale:
# res.update({'order_policy': 'manual'})
# elif deli:
# res.update({'order_policy': 'picking'})
# return {'value':res}
def apply_groups(self, cr, uid, ids, group_name, apply=True, context=None):
data_obj = self.pool.get('ir.model.data')
users_obj = self.pool.get('res.users')
groups_obj = self.pool.get('res.groups')
dummy,group_id = data_obj.get_object_reference(cr, uid, 'base', group_name)
dummy,user_group_id = data_obj.get_object_reference(cr, uid, 'base', 'group_user')
if apply:
groups_obj.write(cr, uid, [user_group_id], {'implied_ids': [(4,group_id)]})
users_obj.write(cr, uid, [uid], {'groups_id': [(4,group_id)]})
else:
groups_obj.write(cr, uid, [user_group_id], {'implied_ids': [(3,group_id)]})
users_obj.write(cr, uid, [uid], {'groups_id': [(3,group_id)]})
def execute(self, cr, uid, ids, vals, context=None):
#TODO: TO BE IMPLEMENTED
ir_values_obj = self.pool.get('ir.values')
data_obj = self.pool.get('ir.model.data')
menu_obj = self.pool.get('ir.ui.menu')
module_obj = self.pool.get('ir.module.module')
users_obj = self.pool.get('res.users')
groups_obj = self.pool.get('res.groups')
module_name = []
group_id = data_obj.get_object(cr, uid, 'base', 'group_sale_salesman').id
wizard = self.browse(cr, uid, ids)[0]
if wizard.sale_orders:
menu_id = data_obj.get_object(cr, uid, 'sale', 'menu_invoicing_sales_order_lines').id
menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_id)]})
if wizard.deli_orders:
menu_id = data_obj.get_object(cr, uid, 'sale', 'menu_action_picking_list_to_invoice').id
menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_id)]})
if wizard.group_sale_pricelist_per_customer:
self.apply_groups(cr, uid, ids, 'group_sale_pricelist_per_customer', context=context)
else:
self.apply_groups(cr, uid, ids, 'group_sale_pricelist_per_customer', False, context=context)
if wizard.group_sale_uom_per_product:
self.apply_groups(cr, uid, ids, 'group_sale_uom_per_product', context=context)
else:
self.apply_groups(cr, uid, ids, 'group_sale_uom_per_product', False, context=context)
if wizard.group_sale_delivery_address:
self.apply_groups(cr, uid, ids, 'group_sale_delivery_address', context=context)
else:
self.apply_groups(cr, uid, ids, 'group_sale_delivery_address', False, context=context)
if wizard.group_sale_disc_per_sale_order_line:
self.apply_groups(cr, uid, ids, 'group_sale_disc_per_sale_order_line', context=context)
else:
self.apply_groups(cr, uid, ids, 'group_sale_disc_per_sale_order_line', False, context=context)
if wizard.task_work:
vals['project_timesheet'] = True
vals['project_mrp'] = True
vals['account_analytic_analysis'] = True
else:
vals['project_timesheet'] = False
vals['project_mrp'] = False
vals['account_analytic_analysis'] = False
if wizard.timesheet:
vals['account_analytic_analysis'] = True
else:
vals['account_analytic_analysis'] = False
if wizard.charge_delivery:
vals['delivery'] = True
else:
vals['delivery'] = False
if wizard.warning:
vals['warning'] = True
else:
vals['warning'] = False
if wizard.sale_layout:
vals['sale_layout'] = True
else:
vals['sale_layout'] = False
if wizard.picking_policy:
ir_values_obj.set(cr, uid, 'default', False, 'picking_policy', ['sale.order'], 'one')
if wizard.time_unit:
prod_id = data_obj.get_object(cr, uid, 'product', 'product_consultant').id
product_obj = self.pool.get('product.product')
product_obj.write(cr, uid, prod_id, {'uom_id': wizard.time_unit.id, 'uom_po_id': wizard.time_unit.id})
ir_values_obj.set(cr, uid, 'default', False, 'order_policy', ['sale.order'], wizard.order_policy)
if wizard.task_work and wizard.time_unit:
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
self.pool.get('res.company').write(cr, uid, [company_id], {
'project_time_mode_id': wizard.time_unit.id
}, context=context)
super(sale_configuration, self).execute(cr, uid, ids, vals, context=context)
sale_configuration()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -503,71 +503,5 @@
<menuitem id="base.menu_invoiced" name="Invoicing" parent="base.menu_base_partner" sequence="5" groups="base.group_extended"/>
<menuitem id="menu_invoicing_sales_order_lines" parent="base.menu_invoiced" action="action_order_line_tree2" sequence="2" groups="base.group_no_one"/>
<!-- Configartion View -->
<record id="view_config_picking_policy_sales" model="ir.ui.view">
<field name="name">Configure Sales Application</field>
<field name="model">sale.configuration</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_config_picking_policy"/>
<field name="arch" type="xml">
<xpath expr="//form/separator[@string='Contracts']" position="before">
<separator string="Picking and Invoice Policy" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<field name="sale_orders"/>
<newline/>
<field name="deli_orders"/>
<newline/>
<field name="task_work"/>
<newline/>
<field name="timesheet"/>
<newline/>
</group>
<group colspan="4" col="4">
<field name="order_policy" attrs="{'invisible':['|',('sale_orders','=',False),('deli_orders','=',False)]}"/>
<newline/>
<field name="charge_delivery" attrs="{'invisible':[('sale_orders','=',False), ('deli_orders','=',False)]}"/>
<newline/>
<field name="picking_policy" attrs="{'invisible':[('deli_orders','=',False)]}"/>
<newline/>
<field name="time_unit" domain="[('category_id.name','=','Working Time')]" attrs="{'invisible':[('task_work','=',False),('timesheet','=',False)],'required': [('timesheet','=',True)]}"/>
</group>
</group>
<separator string="Sale Order" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<field name="group_sale_pricelist_per_customer"/>
<newline/>
<group colspan="4" col="4">
<field name="tax_policy" />
<field name="tax_value" nolabel="1" attrs="{'invisible': [('tax_policy','in',['no_tax','global_on_order'])]}"/>
<field name="tax_value_id" nolabel="1" attrs="{'invisible': [('tax_policy','in',['no_tax','on_order_line'])]}"/>
</group>
<newline/>
<field name="sale_margin"/>
<newline/>
<field name="warning"/>
<newline/>
</group>
<group colspan="4" col="4">
<newline/>
<field name="group_sale_uom_per_product"/>
<newline/>
<field name="group_sale_delivery_address"/>
<newline/>
<field name="group_sale_disc_per_sale_order_line"/>
<newline/>
<field name="sale_layout"/>
<newline/>
<field name="sale_journal"/>
<newline/>
</group>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@ -20,16 +20,6 @@
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record id="base.group_sale_pricelist_per_customer" model="res.groups">
<field name="name">Sales Pricelists</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_sale_uom_per_product" model="res.groups">
<field name="name">Product UOM</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_sale_delivery_address" model="res.groups">
<field name="name">Addresses in Sale Orders</field>
<field name="category_id" ref="base.module_category_usability"/>
@ -40,17 +30,22 @@
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_sale_taxes_global_or_online" model="res.groups">
<field name="name">Sales Taxes Global/on line</field>
<record id="base.group_sale_taxes_global_on_order" model="res.groups">
<field name="name">Sales Taxes Global on Order</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_sale_taxes_on_order_line" model="res.groups">
<field name="name">Sales Taxes on Order Lines</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="base.group_user" model="res.groups">
<field name="implied_ids" eval="[(6,0,[ref('base.group_sale_pricelist_per_customer'),
ref('base.group_sale_uom_per_product'),
<field name="implied_ids" eval="[(6,0,[
ref('base.group_sale_delivery_address'),
ref('base.group_sale_disc_per_sale_order_line'),
ref('base.group_sale_taxes_global_or_online'),
ref('base.group_sale_taxes_global_on_order'),
ref('base.group_sale_taxes_on_order_line'),
])]"/>
</record>

View File

@ -82,8 +82,8 @@
-
I set order policy "Deliver & invoice on demand" as default policy.
-
!record {model: sale.configuration, id: sale_configuration_0}:
!record {model: res.config, id: sale_configuration_0}:
order_policy: 'manual'
-
!python {model: sale.configuration}: |
!python {model: res.config}: |
self.execute(cr, uid, [ref("sale_configuration_0")], {})