[IMP] replace sale configuration wizard

bzr revid: aar@tinyerp.com-20110803101838-98m8etce4tkve7jg
This commit is contained in:
Amit Parmar (OpenERP) 2011-08-03 15:48:38 +05:30
parent 18a53f26c2
commit 02228cdf35
3 changed files with 136 additions and 45 deletions

View File

@ -22,7 +22,7 @@
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import time
import pooler
from osv import fields, osv
from tools.translate import _
import decimal_precision as dp
@ -205,7 +205,7 @@ class sale_order(osv.osv):
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
('cancel', 'Cancelled')
], 'Order State', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the date 'Ordered Date'.", select=True),
], 'Order State', readonly=True, help="Givwizard = self.browse(cr, uid, ids)[0]es the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the date 'Ordered Date'.", select=True),
'date_order': fields.date('Ordered Date', required=True, readonly=True, select=True, states={'draft': [('readonly', False)]}),
'create_date': fields.date('Creation Date', readonly=True, select=True, help="Date on which sales order is created."),
'date_confirm': fields.date('Confirmation Date', readonly=True, select=True, help="Date on which sales order is confirmed."),
@ -1175,43 +1175,110 @@ sale_order_line()
class sale_config_picking_policy(osv.osv_memory):
_name = 'sale.config.picking_policy'
_inherit = 'res.config'
'''def _get_options(cr, uid, ids, context=None):
product_obj = self.pool.get('product.uom')
uom_ids = product_obj.search(cr, uid, [])
res = []
for i in product_obj.browse(cr, uid, uom_ids):
if i.category_id.name == 'Working Time':
res.append(i.id)
return res'''
_columns = {
'name': fields.char('Name', size=64),
'order_policy': fields.selection([
('manual', 'Invoice Based on Sales Orders'),
('picking', 'Invoice Based on Deliveries'),
], 'Invoicing Method', required=True,
help="You can generate invoices based on sales orders or based on shippings."),
'step': fields.selection([
('one', 'Delivery Order Only'),
('two', 'Picking List & Delivery Order')
], 'Steps To Deliver a Sales Order', required=True,
help="By default, OpenERP is able to manage complex routing and paths "\
"of products in your warehouse and partner locations. This will configure "\
"the most common and simple methods to deliver products to the customer "\
"in one or two operations by the worker.")
], 'Main Method Based On', required=True, help="You can generate invoices based on sales orders or based on shippings.", readonly=True),
'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'),
'charge_delivery': fields.boolean('Do you charge the delivery', readonly=True),
'time_unit': fields.many2one('product.uom','Main Working Time Unit', readonly=True)
}
_defaults = {
'order_policy': 'manual',
'step': 'one'
}
def onchange_order(self, cr, uid, ids, sale, deli, context=None):
res = {}
if sale or deli:
res.update({'order_policy': 'manual'})
elif not sale and not deli:
res.update({'order_policy': 'manual'})
else:
return {}
return {'value':res}
def execute(self, cr, uid, ids, context=None):
ir_values_obj = self.pool.get('ir.values')
ir_model_data_obj = self.pool.get('ir.model.data')
stock_location_obj = self.pool.get('stock.location')
location_id = ir_model_data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_output')
location_id = location_id and location_id[1] or False
chaining_type = False
for o in self.browse(cr, uid, ids, context=context):
ir_values_obj.set(cr, uid, 'default', False, 'order_policy', ['sale.order'], o.order_policy)
if o.step == 'one':
chaining_type = 'transparent'
else:
chaining_type = 'manual'
stock_location_obj.write(cr, uid, [location_id], {'chained_auto_packing': chaining_type})
data_obj = self.pool.get('ir.model.data')
menu_obj = self.pool.get('ir.ui.menu')
module_obj = self.pool.get('ir.module.module')
module_upgrade_obj = self.pool.get('base.module.upgrade')
module_name = []
group_ids=[]
group_name = ['group_sale_salesman','group_sale_manager']
print cr, uid, ids
print self.read(cr,uid,ids)
for name in group_name:
data_id = data_obj.name_search(cr, uid, name)
group_ids.append(data_obj.browse(cr,uid,data_id[0][0]).res_id)
wizard = self.browse(cr, uid, ids)[0]
if wizard.sale_orders:
menu_name = 'menu_invoicing_sales_order_lines'
data_id = data_obj.name_search(cr, uid, menu_name)
print data_id
menu_id = data_obj.browse(cr,uid,data_id[0][0]).res_id
menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_ids[0]),(4,group_ids[1])]})
if wizard.deli_orders:
menu_name = 'menu_action_picking_list_to_invoice'
data_id = data_obj.name_search(cr, uid, menu_name)
print data_id
menu_id = data_obj.browse(cr,uid,data_id[0][0]).res_id
menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_ids[0]),(4,group_ids[1])]})
if wizard.task_work:
module_name.append('project_timesheet')
module_name.append('account_analytic_analysis')
if wizard.timesheet:
module_name.append('account_analytic_analysis')
if wizard.charge_delivery:
module_name.append('delivery')
if wizard.time_unit:
print "xyz"
if len(module_name):
module_ids = []
need_install = False
module_ids = []
for module in module_name:
data_id = module_obj.name_search(cr,uid,module)
module_ids.append(data_id[0][0])
for module in module_obj.browse(cr, uid, module_ids):
if module.state == 'uninstalled':
module_obj.state_update(cr, uid, [module.id], 'to install', ['uninstalled'], context)
need_install = True
cr.commit()
if need_install:
pooler.restart_pool(cr.dbname, update_module=True)[1]
ir_values_obj.set(cr, uid, 'default', False, 'order_policy', ['sale.order'], wizard.order_policy)
sale_config_picking_policy()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -527,9 +527,9 @@
<menuitem id="menu_invoiced" name="Invoicing" parent="base.menu_base_partner" sequence="5"
groups="-base.group_extended"/>
<menuitem action="action_order_line_tree2" id="menu_invoicing_sales_order_lines" parent="menu_invoiced" sequence="2" groups="base.group_sale_salesman,base.group_sale_manager"/>
<menuitem action="action_order_line_tree2" id="menu_invoicing_sales_order_lines" parent="menu_invoiced" sequence="2" groups="base.group_no_one"/>
<!-- configartion view -->
<record id="view_config_picking_policy" model="ir.ui.view">
<field name="name">Set Up Your Invoicing Method</field>
<field name="model">sale.config.picking_policy</field>
@ -540,25 +540,49 @@
<form position="attributes">
<attribute name="string">Sales Application Configuration</attribute>
</form>
<separator string="title" position="attributes">
<attribute name="string">Configure Sales Order Logistics</attribute>
</separator>
<xpath expr="//label[@string='description']" position="attributes">
<attribute name="string">Define your invoice method. A services company usually invoices based on sale orders while a retailer usually invoices based on deliveries.</attribute>
</xpath>
<xpath expr='//separator[@string="vsep"]' position='attributes'>
<attribute name='rowspan'>15</attribute>
<attribute name='string'></attribute>
</xpath>
<group string="res_config_contents" position="replace">
<field name="order_policy"/>
<newline/>
<field name="step" groups="base.group_extended"/>
<group colspan="4" col="8" position="replace">
<group col="4">
<separator string="How do you generate your costumer invoice ?"/>
</group>
<group col="4">
<separator string="Options"/>
</group>
<newline/>
<group col="2">
<label align="0.0" string="Based on Sales Orders" width="200" colspan="1"/>
<field name="sale_orders" on_change="onchange_order(sale_orders,deli_orders)" nolabel="1"/>
<label align="0.0" string="Based on Delivery Orders" width="200" colspan="1"/>
<field name="deli_orders" on_change="onchange_order(sale_orders,deli_orders)" nolabel="1"/>
<label align="0.0" string="Based on Task's Work" width="200" colspan="1"/>
<field name="task_work" nolabel="1"/>
<label align="0.0" string="Based on Timesheet" width="200" colspan="1"/>
<field name="timesheet" nolabel="1"/>
</group>
<group col="3">
<label align="0.0" string="Main Method Based On" width="200" colspan="1"/>
<field name="order_policy" attrs="{'readonly':['|',('sale_orders','!=',True),('deli_orders','!=',True)]}" nolabel="1"/>
<newline/>
<label align="0.0" string="Do you charge the delivery" width="200" colspan="1"/>
<field name="charge_delivery" attrs="{'readonly':[('sale_orders','!=',True), ('deli_orders','!=',True)]}" nolabel="1"/>
<newline/>
<label align="0.0" string="Main Working Time Unit" width="200" colspan="1"/>
<field name="time_unit" attrs="{'readonly':[('task_work','=',False),('timesheet','=',False)]}" widget="selection" domain="[('category_id','=',3)]" nolabel="1"/>
</group>
</group>
<xpath expr='//button[@name="action_skip"]' position='replace'/>
</data>
</field>
</record>
<record id="action_config_picking_policy" model="ir.actions.act_window">
<field name="name">Set up your Invoicing Method</field>

View File

@ -74,7 +74,7 @@
<field name="context">{'contact_display': 'partner_address', 'search_default_to_invoice': 1, 'search_default_done': 1}</field>
<field name="search_view_id" ref="stock.view_picking_out_search"/>
</record>
<menuitem action="outgoing_picking_list_to_invoice" id="menu_action_picking_list_to_invoice" parent="sale.menu_invoiced" sequence="20"/>
<menuitem action="outgoing_picking_list_to_invoice" id="menu_action_picking_list_to_invoice" parent="sale.menu_invoiced" groups="base.group_no_one" sequence="20"/>
</data>
</openerp>