From 22f439416273eba39653e4e1cae38c0f10ca9887 Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Wed, 2 Jun 2010 19:24:27 +0530 Subject: [PATCH] [IMP] Improvement in sale and mrp bzr revid: ksa@tinyerp.co.in-20100602135427-p8w2q3n3venurpbn --- .../account/wizard/account_invoice_state.py | 6 +- addons/mrp/mrp.py | 20 ++++--- addons/project/project.py | 7 +-- addons/purchase/purchase.py | 57 +++++++++---------- addons/sale/sale.py | 4 +- 5 files changed, 48 insertions(+), 46 deletions(-) diff --git a/addons/account/wizard/account_invoice_state.py b/addons/account/wizard/account_invoice_state.py index c3934e38db0..3b63ed843d1 100644 --- a/addons/account/wizard/account_invoice_state.py +++ b/addons/account/wizard/account_invoice_state.py @@ -37,11 +37,11 @@ class account_invoice_confirm(osv.osv_memory): context = {} pool_obj = pooler.get_pool(cr.dbname) data_inv = pool_obj.get('account.invoice').read(cr, uid, context['active_ids'], ['state'], context=context) - + for record in data_inv: if record['state'] not in ('draft','proforma','proforma2'): raise osv.except_osv(_('Warning'), _("Selected Invoice(s) cannot be confirmed as they are not in 'Draft' or 'Pro-Forma' state!")) - wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_open', cr) + wf_service.trg_validate(uid, 'account.invoice', record['id'], 'invoice_open', cr) return {} account_invoice_confirm() @@ -61,7 +61,7 @@ class account_invoice_cancel(osv.osv_memory): wf_service = netsvc.LocalService('workflow') pool_obj = pooler.get_pool(cr.dbname) data_inv = pool_obj.get('account.invoice').read(cr, uid, context['active_ids'], ['state'], context=context) - + for record in data_inv: if record['state'] in ('cancel','paid'): raise osv.except_osv(_('Warning'), _("Selected Invoice(s) cannot be cancelled as they are already in 'Cancelled' or 'Done' state!")) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 685d289a194..701438f4c5b 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -20,6 +20,7 @@ ############################################################################## from mx import DateTime +from datetime import datetime, timedelta from osv import fields from osv import osv from tools.translate import _ @@ -117,9 +118,9 @@ class mrp_bom(osv.osv): """ Defines bills of material for a product. """ - _name = 'mrp.bom' + _name = 'mrp.bom' _description = 'Bill of Material' - + def _child_compute(self, cr, uid, ids, name, arg, context={}): """ Gets child bom. @param self: The object pointer @@ -419,7 +420,6 @@ class mrp_production(osv.osv): _name = 'mrp.production' _description = 'Manufacturing Order' _date_name = 'date_planned' - _log_create = True def _production_calc(self, cr, uid, ids, prop, unknow_none, context={}): """ Calculates total hours and total no. of cycles for a production order. @@ -647,15 +647,19 @@ class mrp_production(osv.osv): """ Changes the production state to Ready and location id of stock move. @return: True """ + for production in self.browse(cr, uid, ids): + production = self.browse(cr, uid, [production.id])[0] + s_date = datetime.strptime(production.date_planned,'%Y-%m-%d %H:%M:%S') + for (id,name) in self.name_get(cr, uid, ids): - message = _('Manufacturing Order ') + " '" + name + "' "+ _("is ready to produce.") + message = _('Manufacturing Order ') + " '" + name + "' "+ _("scheduled the") + " " + message += s_date.strftime('%Y-%m-%d') + " " + _("for") + " " + production.product_id.default_code self.log(cr, uid, id, message) move_obj = self.pool.get('stock.move') self.write(cr, uid, ids, {'state': 'ready'}) - for production in self.browse(cr, uid, ids): - if production.move_prod_id: - move_obj.write(cr, uid, [production.move_prod_id.id], - {'location_id': production.location_dest_id.id}) + if production.move_prod_id: + move_obj.write(cr, uid, [production.move_prod_id.id], + {'location_id': production.location_dest_id.id}) return True def action_production_end(self, cr, uid, ids): diff --git a/addons/project/project.py b/addons/project/project.py index 61720675f49..43430f134ee 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -150,14 +150,14 @@ class project(osv.osv): if leave['date_start'] > leave['date']: return False return True - + def _check_escalation(self, cr, uid, ids): project_obj = self.browse(cr, uid, ids[0]) if project_obj.project_escalation_id: if project_obj.project_escalation_id.id == project_obj.id: return False - return True - + return True + _constraints = [ (_check_dates, 'Error! project start-date must be lower then project end-date.', ['date_start', 'date']), (_check_escalation, 'Error! You cannot assign escalation to the same project!', ['project_escalation_id']) @@ -261,7 +261,6 @@ project() class task(osv.osv): _name = "project.task" _description = "Task" - _log_create = True _date_name = "date_start" def _str_get(self, task, level=0, border='***', context={}): diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index b886dc60a0e..3c09d748360 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -211,7 +211,6 @@ class purchase_order(osv.osv): } _name = "purchase.order" _description = "Purchase Order" - _log_create = True _order = "name desc" def unlink(self, cr, uid, ids, context=None): @@ -223,7 +222,7 @@ class purchase_order(osv.osv): else: raise osv.except_osv(_('Invalid action !'), _('Cannot delete Purchase Order(s) which are in %s State!' % s['state'])) - # TODO: temporary fix in 5.0, to remove in 5.2 when subflows support + # TODO: temporary fix in 5.0, to remove in 5.2 when subflows support # automatically sending subflow.delete upon deletion wf_service = netsvc.LocalService("workflow") for id in unlink_ids: @@ -248,7 +247,7 @@ class purchase_order(osv.osv): return {'value':{'location_id': res, 'dest_address_id': False}} def onchange_partner_id(self, cr, uid, ids, part): - + if not part: return {'value':{'partner_address_id': False, 'fiscal_position': False}} addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['default']) @@ -264,12 +263,12 @@ class purchase_order(osv.osv): #TODO: implement messages system def wkf_confirm_order(self, cr, uid, ids, context={}): todo = [] - for po in self.browse(cr, uid, ids): + for po in self.browse(cr, uid, ids): if not po.order_line: raise osv.except_osv(_('Error !'),_('You can not confirm purchase order without Purchase Order Lines.')) - for line in po.order_line: + for line in po.order_line: if line.state=='draft': - todo.append(line.id) + todo.append(line.id) current_name = self.name_get(cr, uid, ids)[0][1] self.pool.get('purchase.order.line').action_confirm(cr, uid, todo, context) for id in ids: @@ -313,13 +312,13 @@ class purchase_order(osv.osv): wf_service = netsvc.LocalService("workflow") for p_id in ids: # Deleting the existing instance of workflow for PO - wf_service.trg_delete(uid, 'purchase.order', p_id, cr) + wf_service.trg_delete(uid, 'purchase.order', p_id, cr) wf_service.trg_create(uid, 'purchase.order', p_id, cr) return True def action_invoice_create(self, cr, uid, ids, *args): res = False - + journal_obj = self.pool.get('account.journal') for o in self.browse(cr, uid, ids): il = [] @@ -437,7 +436,7 @@ class purchase_order(osv.osv): }) if order_line.move_dest_id: self.pool.get('stock.move').write(cr, uid, [order_line.move_dest_id.id], {'location_id':order.location_id.id}) - todo_moves.append(move) + todo_moves.append(move) self.pool.get('stock.move').action_confirm(cr, uid, todo_moves) self.pool.get('stock.move').force_assign(cr, uid, todo_moves) wf_service = netsvc.LocalService("workflow") @@ -459,26 +458,26 @@ class purchase_order(osv.osv): def do_merge(self, cr, uid, ids, context): - """ - To merge similar type of purchase orders. - Orders will only be merged if: - * Purchase Orders are in draft - * Purchase Orders belong to the same partner + """ + To merge similar type of purchase orders. + Orders will only be merged if: + * Purchase Orders are in draft + * Purchase Orders belong to the same partner * Purchase Orders are have same stock location, same pricelist - Lines will only be merged if: - * Order lines are exactly the same except for the quantity and unit + Lines will only be merged if: + * Order lines are exactly the same except for the quantity and unit @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in - @param ids: the ID or list of IDs - @param context: A standard dictionary - + @param ids: the ID or list of IDs + @param context: A standard dictionary + @return: new purchase order id - - """ - wf_service = netsvc.LocalService("workflow") - def make_key(br, fields): + + """ + wf_service = netsvc.LocalService("workflow") + def make_key(br, fields): list_key = [] for field in fields: field_val = getattr(br, field) @@ -496,9 +495,9 @@ class purchase_order(osv.osv): return tuple(list_key) # compute what the new orders should contain - + new_orders = {} - + for porder in [order for order in self.browse(cr, uid, ids) if order.state == 'draft']: order_key = make_key(porder, ('partner_id', 'location_id', 'pricelist_id')) new_order = new_orders.setdefault(order_key, ({}, [])) @@ -541,7 +540,7 @@ class purchase_order(osv.osv): o_line[field] = field_val o_line['uom_factor'] = order_line.product_uom and order_line.product_uom.factor or 1.0 - + allorders = [] for order_key, (order_data, old_ids) in new_orders.iteritems(): @@ -601,7 +600,7 @@ class purchase_order_line(osv.osv): 'invoiced': fields.boolean('Invoiced', readonly=True), 'partner_id': fields.related('order_id','partner_id',string='Partner',readonly=True,type="many2one", relation="res.partner"), 'date_order': fields.related('order_id','date_order',string='Order Date',readonly=True,type="date") - + } _defaults = { 'product_qty': lambda *a: 1.0, @@ -692,7 +691,7 @@ class purchase_order_line(osv.osv): return res def action_confirm(self, cr, uid, ids, context={}): self.write(cr, uid, ids, {'state': 'confirmed'}, context) - return True + return True purchase_order_line() class mrp_procurement(osv.osv): @@ -700,7 +699,7 @@ class mrp_procurement(osv.osv): _columns = { 'purchase_id': fields.many2one('purchase.order', 'Latest Requisition'), } - + def action_po_assign(self, cr, uid, ids, context={}): """ This is action which call from workflow to assign purchase order to procurements @return: True diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 356bd69f679..a19f51c2f3c 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -510,12 +510,12 @@ class sale_order(osv.osv): def action_invoice_end(self, cr, uid, ids, context=None): if context is None: context = {} - + for order in self.browse(cr, uid, ids, context=context): for line in order.order_line: if line.state == 'exception': self.pool.get('sale.order.line').write(cr, uid, [line.id], {'state': 'confirmed'}, context=context) - + if order.state == 'invoice_except': self.write(cr, uid, [order.id], {'state' : 'progress'}, context=context)