diff --git a/addons/account/account.py b/addons/account/account.py index a771bed6144..1ced6bd88e8 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1563,65 +1563,64 @@ class account_config_fiscalyear(osv.osv_memory): account_config_fiscalyear() - -class account_config_journal_bank_accounts(osv.osv_memory): - _name='account.config.journal.bank.account' - _columns = { - 'name':fields.char('Journal Name', size=64), - 'lines_id': fields.one2many('account.config.journal.bank.account.line', 'journal_id', 'Journal Lines'), - } - - def action_cancel(self,cr,uid,ids,conect=None): - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'ir.module.module.configuration.wizard', - 'type': 'ir.actions.act_window', - 'target':'new', - } - - def action_create(self, cr, uid, ids, context=None): - config_res=self.read(cr,uid,ids)[0] - res_obj = self.pool.get('account.journal') - line_obj=self.pool.get('account.config.journal.bank.account.line') - if 'lines_id' in config_res and config_res['lines_id']: - lines=line_obj.read(cr,uid,config_res['lines_id']) - for res in lines: - sequence_ids=self.pool.get('ir.sequence').search(cr,uid,[('name','=','Account Journal')]) - if 'name' in res and 'bank_account_id' in res and 'view_id' in res and sequence_ids and len(sequence_ids): - vals={ - 'name':res['name'], - 'type':'cash', - 'view_id':res['view_id'], - 'default_credit_account_id':res['bank_account_id'], - 'default_debit_account_id':res['bank_account_id'], - 'sequence_id':sequence_ids[0] - } - res_obj.create(cr, uid, vals, context=context) - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'ir.module.module.configuration.wizard', - 'type': 'ir.actions.act_window', - 'target':'new', - } - -account_config_journal_bank_accounts() - -class account_config_journal_bank_accounts_line(osv.osv_memory): - _name='account.config.journal.bank.account.line' - def _journal_view_get(self, cr, uid, context={}): - journal_obj = self.pool.get('account.journal.view') - ids = journal_obj.search(cr, uid, []) - res = journal_obj.read(cr, uid, ids, ['id', 'name'], context) - return [(r['id'], r['name']) for r in res] - _columns = { - 'name':fields.char('Journal Name', size=64,required=True), - 'bank_account_id':fields.many2one('account.account', 'Bank Account', required=True, domain=[('type','=','cash')]), - 'view_id':fields.selection(_journal_view_get, 'Journal View', required=True), - 'journal_id':fields.many2one('account.config.journal.bank.account', 'Journal', required=True), - } -account_config_journal_bank_accounts_line() +#class account_config_journal_bank_accounts(osv.osv_memory): +# _name='account.config.journal.bank.account' +# _columns = { +# 'name':fields.char('Journal Name', size=64), +# 'lines_id': fields.one2many('account.config.journal.bank.account.line', 'journal_id', 'Journal Lines'), +# } +# +# def action_cancel(self,cr,uid,ids,conect=None): +# return { +# 'view_type': 'form', +# "view_mode": 'form', +# 'res_model': 'ir.module.module.configuration.wizard', +# 'type': 'ir.actions.act_window', +# 'target':'new', +# } +# +# def action_create(self, cr, uid, ids, context=None): +# config_res=self.read(cr,uid,ids)[0] +# res_obj = self.pool.get('account.journal') +# line_obj=self.pool.get('account.config.journal.bank.account.line') +# if 'lines_id' in config_res and config_res['lines_id']: +# lines=line_obj.read(cr,uid,config_res['lines_id']) +# for res in lines: +# sequence_ids=self.pool.get('ir.sequence').search(cr,uid,[('name','=','Account Journal')]) +# if 'name' in res and 'bank_account_id' in res and 'view_id' in res and sequence_ids and len(sequence_ids): +# vals={ +# 'name':res['name'], +# 'type':'cash', +# 'view_id':res['view_id'], +# 'default_credit_account_id':res['bank_account_id'], +# 'default_debit_account_id':res['bank_account_id'], +# 'sequence_id':sequence_ids[0] +# } +# res_obj.create(cr, uid, vals, context=context) +# return { +# 'view_type': 'form', +# "view_mode": 'form', +# 'res_model': 'ir.module.module.configuration.wizard', +# 'type': 'ir.actions.act_window', +# 'target':'new', +# } +# +#account_config_journal_bank_accounts() +# +#class account_config_journal_bank_accounts_line(osv.osv_memory): +# _name='account.config.journal.bank.account.line' +# def _journal_view_get(self, cr, uid, context={}): +# journal_obj = self.pool.get('account.journal.view') +# ids = journal_obj.search(cr, uid, []) +# res = journal_obj.read(cr, uid, ids, ['id', 'name'], context) +# return [(r['id'], r['name']) for r in res] +# _columns = { +# 'name':fields.char('Journal Name', size=64,required=True), +# 'bank_account_id':fields.many2one('account.account', 'Bank Account', required=True, domain=[('type','=','cash')]), +# 'view_id':fields.selection(_journal_view_get, 'Journal View', required=True), +# 'journal_id':fields.many2one('account.config.journal.bank.account', 'Journal', required=True), +# } +#account_config_journal_bank_accounts_line() # ---------------------------------------------- # Account Templates : Account, Tax and charts. @@ -1867,6 +1866,9 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_journal = self.pool.get('account.journal') obj_acc_template = self.pool.get('account.account.template') + if obj_multi.code_digits<=5: + raise osv.except_osv(_('User Error'), _('Account code should be of more than 5 digits.')) + # Creating Account obj_acc_root = obj_multi.chart_template_id.account_root_id tax_code_root_id = obj_multi.chart_template_id.tax_code_root_id.id @@ -1889,7 +1891,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'name': (tax_code_root_id == tax_code_template.id) and obj_multi.company_id.name or tax_code_template.name, 'code': tax_code_template.code, 'info': tax_code_template.info, - 'parent_id': tax_code_template.parent_id and tax_code_template_ref[tax_code_template.parent_id.id] or False, + 'parent_id': tax_code_template.parent_id and ((tax_code_template.parent_id.id in tax_code_template_ref) and tax_code_template_ref[tax_code_template.parent_id.id]) or False, 'company_id': company_id, 'sign': tax_code_template.sign, } @@ -1907,7 +1909,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'type':tax.type, 'applicable_type': tax.applicable_type, 'domain':tax.domain, - 'parent_id': tax.parent_id and tax_template_ref[tax.parent_id.id] or False, + 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False, 'child_depend': tax.child_depend, 'python_compute': tax.python_compute, 'python_compute_inv': tax.python_compute_inv, @@ -1933,7 +1935,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): } tax_template_ref[tax.id] = new_tax - #deactivate the parent_store functionnality on account_account for rapidity purpose self.pool._init = True children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id])]) @@ -1942,17 +1943,22 @@ class wizard_multi_charts_accounts(osv.osv_memory): for tax in account_template.tax_ids: tax_ids.append(tax_template_ref[tax.id]) #create the account_account + dig=obj_multi.code_digits + code_main=len(account_template.code) + code_acc=account_template.code + if code_main<=dig: + code_acc=str(code_acc) + (str('0'*(dig-code_main))) vals={ 'name': (obj_acc_root.id == account_template.id) and obj_multi.company_id.name or account_template.name, #'sign': account_template.sign, 'currency_id': account_template.currency_id and account_template.currency_id.id or False, - 'code': account_template.code, + 'code': code_acc[:dig], 'type': account_template.type, 'user_type': account_template.user_type or False, 'reconcile': account_template.reconcile, 'shortcut': account_template.shortcut, 'note': account_template.note, - 'parent_id': account_template.parent_id and acc_template_ref[account_template.parent_id.id] or False, + 'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False, 'tax_ids': [(6,0,tax_ids)], 'company_id': company_id, } @@ -2015,7 +2021,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): #'sign': ref_acc_bank.sign, 'currency_id': line.currency_id and line.currency_id.id or False, 'code': ref_acc_bank.code+str(current_num), - 'type': 'cash', + 'type': 'other', 'user_type': account_template.user_type or False, 'reconcile': True, 'parent_id': acc_template_ref[ref_acc_bank.id] or False, diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 3634535b2d0..36b0f97f31b 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -17,6 +17,17 @@ + + account.invoice.graph + account.invoice + graph + + + + + + + account.invoice.line.tree account.invoice.line @@ -274,7 +285,7 @@ Invoices account.invoice form - tree,form,calendar + tree,form,calendar,graph {'type':'out_invoice'} @@ -295,7 +306,7 @@ Customer Invoices account.invoice form - tree,form,calendar + tree,form,calendar,graph [('type','=','out_invoice')] {'type':'out_invoice'} @@ -305,7 +316,7 @@ New Customer Invoice account.invoice form - form,tree,calendar + form,tree,calendar,graph [('type','=','out_invoice')] {'type':'out_invoice'} @@ -316,7 +327,7 @@ Supplier Invoices account.invoice form - tree,form,calendar + tree,form,calendar,graph [('type','=','in_invoice')] {'type':'in_invoice'} @@ -326,7 +337,7 @@ New Supplier Invoice account.invoice form - form,tree,calendar + form,tree,calendar,graph [('type','=','in_invoice')] {'type':'in_invoice'} @@ -337,7 +348,7 @@ Customer Refunds account.invoice form - tree,form,calendar + tree,form,calendar,graph [('type','=','out_refund')] {'type':'out_refund'} @@ -348,7 +359,7 @@ New Customer Refund account.invoice form - form,tree,calendar + form,tree,calendar,graph [('type','=','out_refund')] {'type':'out_refund'} @@ -359,7 +370,7 @@ Supplier Refunds account.invoice form - tree,form,calendar + tree,form,calendar,graph [('type','=','in_refund')] {'type':'in_refund'} @@ -370,7 +381,7 @@ New Supplier Refund account.invoice form - form,tree,calendar + form,tree,calendar,graph [('type','=','in_refund')] {'type':'in_refund'} diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 2fb7c30d4a5..7a44e823b79 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -1415,9 +1415,7 @@ new - - - + @@ -1463,12 +1461,12 @@ open - + diff --git a/addons/account/account_wizard.xml b/addons/account/account_wizard.xml index dd89db53a7c..c5f6c267574 100644 --- a/addons/account/account_wizard.xml +++ b/addons/account/account_wizard.xml @@ -22,7 +22,23 @@ - + + + Entries by Statements + account.move.line + form + tree,form + new + + + diff --git a/addons/account/partner_view.xml b/addons/account/partner_view.xml index 8e523c5bc4d..4a05314daca 100644 --- a/addons/account/partner_view.xml +++ b/addons/account/partner_view.xml @@ -13,54 +13,54 @@ - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/addons/account/security/ir.model.access.csv b/addons/account/security/ir.model.access.csv index 68fa798ad38..3f65271a2ae 100644 --- a/addons/account/security/ir.model.access.csv +++ b/addons/account/security/ir.model.access.csv @@ -20,8 +20,6 @@ access_account_model_line,account.model.line,model_account_model_line,account.gr access_account_subscription,account.subscription,model_account_subscription,account.group_account_user,1,1,1,1 access_account_subscription_line,account.subscription.line,model_account_subscription_line,account.group_account_user,1,1,1,1 access_account_config_fiscalyear,account.config.fiscalyear,model_account_config_fiscalyear,account.group_account_manager,1,1,1,1 -access_account_config_journal_bank_account,account.config.journal.bank.account,model_account_config_journal_bank_account,account.group_account_manager,1,1,1,1 -access_account_config_journal_bank_account_line,account.config.journal.bank.account.line,model_account_config_journal_bank_account_line,account.group_account_manager,1,1,1,1 access_account_tax_template,account.tax.template,model_account_tax_template,account.group_account_manager,1,1,1,1 access_account_account_template,account.account.template,model_account_account_template,account.group_account_manager,1,1,1,1 access_account_tax_code_template,account.tax.code.template,model_account_tax_code_template,account.group_account_manager,1,1,1,1 diff --git a/addons/base_module_record/base_module_record.py b/addons/base_module_record/base_module_record.py index 6c130549f64..1a623b2dbb5 100644 --- a/addons/base_module_record/base_module_record.py +++ b/addons/base_module_record/base_module_record.py @@ -209,7 +209,7 @@ def fnct_call(fnct): pool = pooler.get_pool(args[0]) mod = pool.get('ir.module.record') if mod and mod.recording: - if args[4] not in ('default_get','read','fields_view_get','fields_get','search','name_search','name_get','get','request_get', 'get_sc'): + if args[4] not in ('default_get','read','fields_view_get','fields_get','search','search_count','name_search','name_get','get','request_get', 'get_sc'): mod.recording_data.append(('query', args, argv,res)) return res return execute diff --git a/addons/base_module_record/wizard/base_module_save.py b/addons/base_module_record/wizard/base_module_save.py index 1b26c34ea65..458e57404cc 100644 --- a/addons/base_module_record/wizard/base_module_save.py +++ b/addons/base_module_record/wizard/base_module_save.py @@ -74,7 +74,7 @@ intro_save_form = ''' - + + + + mrp.production.graph + mrp.production + graph + + + + + + + @@ -446,7 +458,7 @@ ir.actions.act_window mrp.production form - tree,form,calendar + tree,form,calendar,graph @@ -456,7 +468,7 @@ ir.actions.act_window mrp.production form - tree,form,calendar + tree,form,calendar,graph [('state','=','ready')] @@ -465,7 +477,7 @@ ir.actions.act_window mrp.production form - tree,form,calendar + tree,form,calendar,graph [('state','=','in_production')] @@ -474,7 +486,7 @@ ir.actions.act_window mrp.production form - tree,form,calendar + tree,form,calendar,graph [('state','=','confirmed')] @@ -484,7 +496,7 @@ ir.actions.act_window mrp.production form - form,tree,calendar + form,tree,calendar,graph diff --git a/addons/mrp/mrp_wizard.xml b/addons/mrp/mrp_wizard.xml index 14a162c9551..6e02dbc55e6 100644 --- a/addons/mrp/mrp_wizard.xml +++ b/addons/mrp/mrp_wizard.xml @@ -2,19 +2,19 @@ - Compute all schedulers + Compute All Schedulers mrp.procurement.compute.all - Compute procurement + Compute Procurements Only mrp.procurement.compute - Compute stock minimum rules + Compute Stock Minimum Rules Only mrp.procurement.orderpoint.compute @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/addons/mrp/schedulers.py b/addons/mrp/schedulers.py new file mode 100644 index 00000000000..a02d8ae901c --- /dev/null +++ b/addons/mrp/schedulers.py @@ -0,0 +1,248 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id$ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +from osv import osv +import netsvc +import pooler +from mx import DateTime +import time + +class mrp_procurement(osv.osv): + _inherit = 'mrp.procurement' + def _procure_confirm(self, cr, uid, ids=None, use_new_cursor=False, context=None): + ''' + use_new_cursor: False or the dbname + ''' + if not context: + context={} + + if use_new_cursor: + cr = pooler.get_db(use_new_cursor).cursor() + wf_service = netsvc.LocalService("workflow") + + procurement_obj = self.pool.get('mrp.procurement') + if not ids: + ids=procurement_obj.search(cr,uid,[], order="date_planned") + for id in ids: + wf_service.trg_validate(uid, 'mrp.procurement', id, 'button_restart', cr) + if use_new_cursor: + cr.commit() + + company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id + maxdate = DateTime.now() + DateTime.RelativeDateTime(days=company.schedule_range) + start_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') + offset = 0 + report = [] + report_total = 0 + report_except = 0 + report_later = 0 + while True: + cr.execute('select id from mrp_procurement where state=%s and procure_method=%s order by date_planned limit 500 offset %d', ('confirmed','make_to_order',offset)) + ids = map(lambda x:x[0], cr.fetchall()) + for proc in procurement_obj.browse(cr, uid, ids): + if maxdate.strftime('%Y-%m-%d')>=proc.date_planned: + wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) + else: + offset+=1 + report_later += 1 + for proc in procurement_obj.browse(cr, uid, ids): + if proc.state == 'exception': + report.append('PROC %d: on order - %3.2f %-5s - %s' % \ + (proc.id, proc.product_qty, proc.product_uom.name, + proc.product_id.name)) + report_except += 1 + report_total += 1 + if use_new_cursor: + cr.commit() + if not ids: + break + + offset = 0 + ids = [] + while True: + report_ids = [] + ids = self.pool.get('mrp.procurement').search(cr, uid, [('state','=','confirmed'),('procure_method','=','make_to_stock')], offset=offset) + for proc in procurement_obj.browse(cr, uid, ids): + if (maxdate).strftime('%Y-%m-%d') >= proc.date_planned: + wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) + report_ids.append(proc.id) + else: + report_later +=1 + report_total +=1 + for proc in procurement_obj.browse(cr, uid, report_ids): + if proc.state == 'exception': + report.append('PROC %d: from stock - %3.2f %-5s - %s' % \ + (proc.id, proc.product_qty, proc.product_uom.name, + proc.product_id.name,)) + report_except +=1 + if use_new_cursor: + cr.commit() + offset += len(ids) + if not ids: break + end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') + if uid: + request = self.pool.get('res.request') + summary = '''Here is the procurement scheduling report. + + Computation Started; %s + Computation Finnished; %s + + Total procurement: %d + Exception procurement: %d + Not run now procurement: %d + + Exceptions; + '''% (start_date,end_date,report_total, report_except,report_later) + summary += '\n'.join(report) + request.create(cr, uid, + {'name' : "Procurement calculation report.", + 'act_from' : uid, + 'act_to' : uid, + 'body': summary, + }) + if use_new_cursor: + cr.commit() + cr.close() + return {} + + def create_automatic_op(cr, uid, context=None): + if not context: + context={} + product_obj = self.pool.get('product.product') + proc_obj = self.pool.get('mrp.procurement') + warehouse_obj = self.pool.get('stock.warehouse') + wf_service = netsvc.LocalService("workflow") + + cr.execute('select id from stock_warehouse') + warehouses = [x for x, in cr.fetchall()] + cr.execute('select id from product_product') + products_id = [x for x, in cr.fetchall()] + products = dict(zip(products_id, product_obj.browse(cr, uid, products_id, context))) + for warehouse in warehouses: + v_stock = product_obj._product_virtual_available(cr, uid, products_id, None, {'warehouse': warehouse}) + cr.execute("select lot_stock_id from stock_warehouse") + location_ids_str = ','.join([str(id) for id, in cr.fetchall()]) + stock_locations = warehouse_obj.read(cr, uid, [warehouse], ['lot_input_id', 'lot_stock_id'])[0] + for prod_id, available in v_stock.items(): + if available >= 0: + continue + newdate = DateTime.now() + DateTime.RelativeDateTime(days=products[prod_id].seller_delay) + if products[prod_id].supply_method == 'buy': + location_id = stock_locations['lot_input_id'][0] + elif products[prod_id].supply_method == 'produce': + location_id = stock_locations['lot_stock_id'][0] + else: + continue + proc_id = proc_obj.create(cr, uid, { + 'name': 'PROC:Automatic OP for product:%s' % products[prod_id].name, + 'origin': 'SCHEDULER', + 'date_planned': newdate.strftime('%Y-%m-%d'), + 'product_id': prod_id, + 'product_qty': -available, + 'product_uom': products[prod_id].uom_id.id, + 'location_id': location_id, + 'procure_method': 'make_to_order', + }) + wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr) + wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_check', cr) + + + def _procure_orderpoint_confirm(self, cr, uid, automatic=False,\ + use_new_cursor=False, context=None, user_id=False): + ''' + use_new_cursor: False or the dbname + ''' + if not context: + context={} + if use_new_cursor: + cr = pooler.get_db(use_new_cursor).cursor() + orderpoint_obj = self.pool.get('stock.warehouse.orderpoint') + location_obj = self.pool.get('stock.location') + procurement_obj = self.pool.get('mrp.procurement') + request_obj = self.pool.get('res.request') + wf_service = netsvc.LocalService("workflow") + report = [] + offset = 0 + ids = [1] + if automatic: + create_automatic_op(cr, uid, context=context) + while ids: + ids=orderpoint_obj.search(cr,uid,[],offset=offset,limit=100) + for op in orderpoint_obj.browse(cr, uid, ids): + try: + prods = location_obj._product_virtual_get(cr, uid, + op.warehouse_id.lot_stock_id.id, [op.product_id.id], + {'uom': op.product_uom.id})[op.product_id.id] + if prods < op.product_min_qty: + qty = max(op.product_min_qty, op.product_max_qty)-prods + reste = qty % op.qty_multiple + if reste>0: + qty += op.qty_multiple-reste + newdate = DateTime.now() + DateTime.RelativeDateTime( + days=op.product_id.seller_delay) + if op.product_id.supply_method == 'buy': + location_id = op.warehouse_id.lot_input_id + elif op.product_id.supply_method == 'produce': + location_id = op.warehouse_id.lot_stock_id + else: + continue + proc_id = procurement_obj.create(cr, uid, { + 'name': 'OP:'+str(op.id), + 'date_planned': newdate.strftime('%Y-%m-%d'), + 'product_id': op.product_id.id, + 'product_qty': qty, + 'product_uom': op.product_uom.id, + 'location_id': op.warehouse_id.lot_input_id.id, + 'procure_method': 'make_to_order', + 'origin': op.name + }) + wf_service.trg_validate(uid, 'mrp.procurement', proc_id, + 'button_confirm', cr) + wf_service.trg_validate(uid, 'mrp.procurement', proc_id, + 'button_check', cr) + orderpoint_obj.write(cr, uid, [op.id], + {'procurement_id': proc_id}) + except Exception, e: + report.append('OP %d:\n%s\n' % (op.id, str(e))) + offset += len(ids) + if use_new_cursor: + cr.commit() + if user_id and report: + request_obj.create(cr, uid, { + 'name': 'Orderpoint report.', + 'act_from': user_id, + 'act_to': user_id, + 'body': '\n'.join(report) + }) + if use_new_cursor: + cr.commit() + cr.close() + return {} +mrp_procurement() diff --git a/addons/mrp/wizard/schedulers.py b/addons/mrp/wizard/schedulers.py deleted file mode 100644 index 98ff98111ea..00000000000 --- a/addons/mrp/wizard/schedulers.py +++ /dev/null @@ -1,264 +0,0 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved. -# -# $Id$ -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsability of assessing all potential -# consequences resulting from its eventual inadequacies and bugs -# End users who are looking for a ready-to-use solution with commercial -# garantees and support are strongly adviced to contract a Free Software -# Service Company -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -############################################################################## - -import pooler -import time -from mx import DateTime -import netsvc -from osv import osv - -def _procure_confirm(self, cr, uid, schedule_cycle=1.0, po_cycle=1.0,\ - po_lead=1.0, security_lead=50.0, picking_lead=1.0, user_id=False,\ - use_new_cursor=False, context=None): - ''' - use_new_cursor: False or the dbname - ''' - if not context: - context={} - - if use_new_cursor: - cr = pooler.get_db(use_new_cursor).cursor() - wf_service = netsvc.LocalService("workflow") - - procurement_obj = pooler.get_pool(cr.dbname).get('mrp.procurement') - ids=procurement_obj.search(cr,uid,[], order="date_planned") - for id in ids: - wf_service.trg_validate(uid, 'mrp.procurement', id, 'button_restart', cr) - if use_new_cursor: - cr.commit() - - po_time = po_cycle + po_lead - maxdate = DateTime.now() + DateTime.RelativeDateTime(days=schedule_cycle + security_lead) - start_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') - offset = 0 - report = [] - report_total = 0 - report_except = 0 - report_later = 0 - ids = [1] - while len(ids): - cr.execute('select id from mrp_procurement where state=%s and procure_method=%s order by date_planned limit 500 offset %d', ('confirmed','make_to_order',offset)) - ids = map(lambda x:x[0], cr.fetchall()) - for proc in procurement_obj.browse(cr, uid, ids): - if proc.product_id.supply_method=='produce': - wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) - else: - if (maxdate + DateTime.RelativeDateTime(days=(proc.product_id.seller_delay or 0 + po_time))).strftime('%Y-%m-%d')>=proc.date_planned: - wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) - else: - offset+=1 - report_later += 1 - for proc in procurement_obj.browse(cr, uid, ids): - if proc.state == 'exception': - report.append('PROC %d: on order - %3.2f %-5s - %s' % \ - (proc.id, proc.product_qty, proc.product_uom.name, - proc.product_id.name)) - report_except += 1 - report_total += 1 - if use_new_cursor: - cr.commit() - - offset = 0 - ids = [1] - while len(ids): - report_ids = [] - ids = pooler.get_pool(cr.dbname).get('mrp.procurement').search(cr, uid, [('state','=','confirmed'),('procure_method','=','make_to_stock')], offset=offset) - for proc in procurement_obj.browse(cr, uid, ids): - if (maxdate + DateTime.RelativeDateTime(days=picking_lead)).strftime('%Y-%m-%d') >= proc.date_planned: - wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) - report_ids.append(proc.id) - else: - report_later +=1 - report_total +=1 - for proc in procurement_obj.browse(cr, uid, report_ids): - if proc.state == 'exception': - report.append('PROC %d: from stock - %3.2f %-5s - %s' % \ - (proc.id, proc.product_qty, proc.product_uom.name, - proc.product_id.name,)) - report_except +=1 - if use_new_cursor: - cr.commit() - offset += len(ids) - end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') - if user_id: - request = pooler.get_pool(cr.dbname).get('res.request') - summary = '''Here is the procurement scheduling report. - -Computation Started; %s -Computation Finnished; %s - -Total procurement: %d -Exception procurement: %d -Not run now procurement: %d - -Exceptions; -'''% (start_date,end_date,report_total, report_except,report_later) - summary += '\n'.join(report) - request.create(cr, uid, - {'name' : "Procurement calculation report.", - 'act_from' : user_id, - 'act_to' : user_id, - 'body': summary, - }) - if use_new_cursor: - cr.commit() - cr.close() - return {} - -def create_automatic_op(cr, uid, context=None): - if not context: - context={} - product_obj = pooler.get_pool(cr.dbname).get('product.product') - proc_obj = pooler.get_pool(cr.dbname).get('mrp.procurement') - warehouse_obj = pooler.get_pool(cr.dbname).get('stock.warehouse') - wf_service = netsvc.LocalService("workflow") - - cr.execute('select id from stock_warehouse') - warehouses = [x for x, in cr.fetchall()] - cr.execute('select id from product_product') - products_id = [x for x, in cr.fetchall()] - products = dict(zip(products_id, product_obj.browse(cr, uid, products_id, context))) - for warehouse in warehouses: - v_stock = product_obj._product_virtual_available(cr, uid, products_id, None, {'warehouse': warehouse}) - cr.execute("select lot_stock_id from stock_warehouse") - location_ids_str = ','.join([str(id) for id, in cr.fetchall()]) - stock_locations = warehouse_obj.read(cr, uid, [warehouse], ['lot_input_id', 'lot_stock_id'])[0] - for prod_id, available in v_stock.items(): - if available >= 0: - continue - newdate = DateTime.now() + DateTime.RelativeDateTime(days=products[prod_id].seller_delay) - if products[prod_id].supply_method == 'buy': - location_id = stock_locations['lot_input_id'][0] - elif products[prod_id].supply_method == 'produce': - location_id = stock_locations['lot_stock_id'][0] - else: - continue - proc_id = proc_obj.create(cr, uid, { - 'name': 'PROC:Automatic OP for product:%s' % products[prod_id].name, - 'origin': 'SCHEDULER', - 'date_planned': newdate.strftime('%Y-%m-%d'), - 'product_id': prod_id, - 'product_qty': -available, - 'product_uom': products[prod_id].uom_id.id, - 'location_id': location_id, - 'procure_method': 'make_to_order', - }) - wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr) - wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_check', cr) - - -def _procure_orderpoint_confirm(self, cr, uid, automatic=False,\ - use_new_cursor=False, context=None, user_id=False): - ''' - use_new_cursor: False or the dbname - ''' - if not context: - context={} - if use_new_cursor: - cr = pooler.get_db(use_new_cursor).cursor() - pool = pooler.get_pool(cr.dbname) - orderpoint_obj = pool.get('stock.warehouse.orderpoint') - location_obj = pool.get('stock.location') - procurement_obj = pool.get('mrp.procurement') - request_obj = pool.get('res.request') - wf_service = netsvc.LocalService("workflow") - report = [] - offset = 0 - ids = [1] - if automatic: - create_automatic_op(cr, uid, context=context) - while ids: - ids=orderpoint_obj.search(cr,uid,[],offset=offset,limit=100) - for op in orderpoint_obj.browse(cr, uid, ids): - #if op.procurement_id and op.procurement_id.purchase_id: - # if (op.procurement_id.purchase_id.state=='confirmed'): - # # - # # TODO: Should write a request with this warning - # # - # continue - # elif op.procurement_id.purchase_id.state=='draft': - # wf_service = netsvc.LocalService("workflow") - # wf_service.trg_validate(uid, 'purchase.order', - # op.procurement_id.purchase_id.id, 'purchase_cancel', cr) - try: - prods = location_obj._product_virtual_get(cr, uid, - op.warehouse_id.lot_stock_id.id, [op.product_id.id], - {'uom': op.product_uom.id})[op.product_id.id] - if prods < op.product_min_qty: - # order the quantity necessary to get to max(min_qty, max_qty) - qty = max(op.product_min_qty, op.product_max_qty)-prods - reste = qty % op.qty_multiple - if reste>0: - qty += op.qty_multiple-reste - newdate = DateTime.now() + DateTime.RelativeDateTime( - days=op.product_id.seller_delay) - if op.product_id.supply_method == 'buy': - location_id = op.warehouse_id.lot_input_id - elif op.product_id.supply_method == 'produce': - location_id = op.warehouse_id.lot_stock_id - else: - continue - proc_id = procurement_obj.create(cr, uid, { - 'name': 'OP:'+str(op.id), - 'date_planned': newdate.strftime('%Y-%m-%d'), - 'product_id': op.product_id.id, - 'product_qty': qty, - 'product_uom': op.product_uom.id, - 'location_id': op.warehouse_id.lot_input_id.id, - 'procure_method': 'make_to_order', - 'origin': op.name - }) - wf_service.trg_validate(uid, 'mrp.procurement', proc_id, - 'button_confirm', cr) - wf_service.trg_validate(uid, 'mrp.procurement', proc_id, - 'button_check', cr) - orderpoint_obj.write(cr, uid, [op.id], - {'procurement_id': proc_id}) - except Exception, e: - report.append('OP %d:\n%s\n' % (op.id, str(e))) - offset += len(ids) - if use_new_cursor: - cr.commit() - if user_id and report: - request_obj.create(cr, uid, { - 'name': 'Orderpoint report.', - 'act_from': user_id, - 'act_to': user_id, - 'body': '\n'.join(report) - }) - if use_new_cursor: - cr.commit() - cr.close() - return {} - - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/mrp/wizard/wizard_orderpoint_procurement.py b/addons/mrp/wizard/wizard_orderpoint_procurement.py index ef64c2c070b..956b5ed111c 100644 --- a/addons/mrp/wizard/wizard_orderpoint_procurement.py +++ b/addons/mrp/wizard/wizard_orderpoint_procurement.py @@ -51,8 +51,8 @@ def _procure_calculation_orderpoint(self, db_name, uid, data, context): cr = db.cursor() proc_obj = pool.get('mrp.procurement') automatic = data['form']['automatic'] - proc_obj.run_orderpoint_confirm(cr, uid, automatic=automatic,\ - use_new_cursor=cr.dbname, context=context, user_id=uid) + proc_obj._procure_orderpoint_confirm(cr, uid, automatic=automatic,\ + use_new_cursor=cr.dbname, context=context) return {} def _procure_calculation(self, cr, uid, data, context): diff --git a/addons/mrp/wizard/wizard_procurement.py b/addons/mrp/wizard/wizard_procurement.py index afa5795cdb8..09dde8071aa 100644 --- a/addons/mrp/wizard/wizard_procurement.py +++ b/addons/mrp/wizard/wizard_procurement.py @@ -34,38 +34,17 @@ import pooler parameter_form = '''
- - - - - - - - +