From b801e6eab97cc8331b870654d37f57d228e13a2b Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 16 Oct 2013 17:03:35 +0200 Subject: [PATCH 1/4] [IMP] procurement: better workflow bzr revid: mat@openerp.com-20131016150335-oikqm6twbukp666t --- addons/procurement/procurement.py | 2 +- addons/procurement/procurement_workflow.xml | 2 -- addons/procurement/schedulers.py | 23 --------------------- addons/purchase/purchase.py | 3 +-- 4 files changed, 2 insertions(+), 28 deletions(-) diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index 2bc095a9661..a39b2d79843 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -371,7 +371,7 @@ class procurement_order(osv.osv): #temporary context passed in write to prevent an infinite loop ctx_wkf = dict(context or {}) ctx_wkf['workflow.trg_write.%s' % self._name] = False - self.write(cr, uid, [procurement.id], {'message': message},context=ctx_wkf) + self.write(cr, uid, [procurement.id], {'message': message, 'state': 'exception'},context=ctx_wkf) return ok def _workflow_trigger(self, cr, uid, ids, trigger, context=None): diff --git a/addons/procurement/procurement_workflow.xml b/addons/procurement/procurement_workflow.xml index 76b54370ef2..8ddd619a527 100644 --- a/addons/procurement/procurement_workflow.xml +++ b/addons/procurement/procurement_workflow.xml @@ -29,8 +29,6 @@ confirm_wait - function - write({'state':'exception'}) diff --git a/addons/procurement/schedulers.py b/addons/procurement/schedulers.py index 07280b38ae7..cf08cb91a06 100644 --- a/addons/procurement/schedulers.py +++ b/addons/procurement/schedulers.py @@ -72,10 +72,6 @@ class procurement_order(osv.osv): maxdate = (datetime.today() + relativedelta(days=company.schedule_range)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) start_date = fields.datetime.now() offset = 0 - report = [] - report_total = 0 - report_except = 0 - report_later = 0 while True: ids = procurement_obj.search(cr, uid, [('state', '=', 'confirmed'), ('procure_method', '=', 'make_to_order')], offset=offset, limit=500, order='priority, date_planned', context=context) for proc in procurement_obj.browse(cr, uid, ids, context=context): @@ -83,14 +79,7 @@ class procurement_order(osv.osv): wf_service.trg_validate(uid, 'procurement.order', proc.id, 'button_check', cr) else: offset += 1 - report_later += 1 - 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: @@ -98,22 +87,10 @@ class procurement_order(osv.osv): offset = 0 ids = [] while True: - report_ids = [] ids = procurement_obj.search(cr, uid, [('state', '=', 'confirmed'), ('procure_method', '=', 'make_to_stock')], offset=offset) for proc in procurement_obj.browse(cr, uid, ids): if maxdate >= proc.date_planned: wf_service.trg_validate(uid, 'procurement.order', proc.id, 'button_check', cr) - report_ids.append(proc.id) - else: - report_later += 1 - report_total += 1 - - 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() diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 992af37222e..04b380ef098 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1044,10 +1044,9 @@ class procurement_order(osv.osv): message = _('No default supplier defined for this product') elif not partner_obj.address_get(cr, uid, [partner.id], ['delivery'])['delivery']: message = _('No address defined for the supplier') - if message: if procurement.message != message: - cr.execute('update procurement_order set message=%s where id=%s', (message, procurement.id)) + cr.execute("update procurement_order set message=%s, state='exception' where id=%s", (message, procurement.id)) return False if user.company_id and user.company_id.partner_id: From c4370b47f8049cad7a5000aaf93de49bea5143a1 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 17 Oct 2013 09:46:35 +0200 Subject: [PATCH 2/4] [IMP] procurement: redifine workflow to avoid going back to confrmed state bzr revid: mat@openerp.com-20131017074635-qp1n3x8955bf3aqd --- addons/procurement/procurement_workflow.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/procurement/procurement_workflow.xml b/addons/procurement/procurement_workflow.xml index 8ddd619a527..086a92214f0 100644 --- a/addons/procurement/procurement_workflow.xml +++ b/addons/procurement/procurement_workflow.xml @@ -119,7 +119,7 @@ - + button_restart @@ -129,7 +129,7 @@ - + button_restart From b98f935d271b6aa25329420ee3afe49f6bdd7616 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 17 Oct 2013 12:44:26 +0200 Subject: [PATCH 3/4] revert change of workflow bzr revid: mat@openerp.com-20131017104426-260y7v0113q8iue9 --- addons/procurement/procurement.py | 2 +- addons/procurement/procurement_workflow.xml | 6 ++++-- addons/procurement/schedulers.py | 23 +++++++++++++++++++++ addons/purchase/purchase.py | 3 ++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index a39b2d79843..2bc095a9661 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -371,7 +371,7 @@ class procurement_order(osv.osv): #temporary context passed in write to prevent an infinite loop ctx_wkf = dict(context or {}) ctx_wkf['workflow.trg_write.%s' % self._name] = False - self.write(cr, uid, [procurement.id], {'message': message, 'state': 'exception'},context=ctx_wkf) + self.write(cr, uid, [procurement.id], {'message': message},context=ctx_wkf) return ok def _workflow_trigger(self, cr, uid, ids, trigger, context=None): diff --git a/addons/procurement/procurement_workflow.xml b/addons/procurement/procurement_workflow.xml index 086a92214f0..76b54370ef2 100644 --- a/addons/procurement/procurement_workflow.xml +++ b/addons/procurement/procurement_workflow.xml @@ -29,6 +29,8 @@ confirm_wait + function + write({'state':'exception'}) @@ -119,7 +121,7 @@ - + button_restart @@ -129,7 +131,7 @@ - + button_restart diff --git a/addons/procurement/schedulers.py b/addons/procurement/schedulers.py index cf08cb91a06..07280b38ae7 100644 --- a/addons/procurement/schedulers.py +++ b/addons/procurement/schedulers.py @@ -72,6 +72,10 @@ class procurement_order(osv.osv): maxdate = (datetime.today() + relativedelta(days=company.schedule_range)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) start_date = fields.datetime.now() offset = 0 + report = [] + report_total = 0 + report_except = 0 + report_later = 0 while True: ids = procurement_obj.search(cr, uid, [('state', '=', 'confirmed'), ('procure_method', '=', 'make_to_order')], offset=offset, limit=500, order='priority, date_planned', context=context) for proc in procurement_obj.browse(cr, uid, ids, context=context): @@ -79,7 +83,14 @@ class procurement_order(osv.osv): wf_service.trg_validate(uid, 'procurement.order', proc.id, 'button_check', cr) else: offset += 1 + report_later += 1 + 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: @@ -87,10 +98,22 @@ class procurement_order(osv.osv): offset = 0 ids = [] while True: + report_ids = [] ids = procurement_obj.search(cr, uid, [('state', '=', 'confirmed'), ('procure_method', '=', 'make_to_stock')], offset=offset) for proc in procurement_obj.browse(cr, uid, ids): if maxdate >= proc.date_planned: wf_service.trg_validate(uid, 'procurement.order', proc.id, 'button_check', cr) + report_ids.append(proc.id) + else: + report_later += 1 + report_total += 1 + + 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() diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 04b380ef098..992af37222e 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1044,9 +1044,10 @@ class procurement_order(osv.osv): message = _('No default supplier defined for this product') elif not partner_obj.address_get(cr, uid, [partner.id], ['delivery'])['delivery']: message = _('No address defined for the supplier') + if message: if procurement.message != message: - cr.execute("update procurement_order set message=%s, state='exception' where id=%s", (message, procurement.id)) + cr.execute('update procurement_order set message=%s where id=%s', (message, procurement.id)) return False if user.company_id and user.company_id.partner_id: From b60da2a9a3693866cd018e73faab2034d6673c45 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 17 Oct 2013 13:35:21 +0200 Subject: [PATCH 4/4] [IMP] procurement: track only once the change of state to exception and confirmed bzr revid: mat@openerp.com-20131017113521-5u2k9glb3o7cnmmk --- addons/procurement/procurement.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index 2bc095a9661..f5d4761642b 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -128,6 +128,22 @@ class procurement_order(osv.osv): 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c) } + def message_track(self, cr, uid, ids, tracked_fields, initial_values, context=None): + """ Overwrite message_track to avoid tracking more than once the confirm-exception loop + Add '_first_pass_done_' to the note field only the first time stuck in exception state + Will avoid getting furthur confirmed and exception change of state messages + + TODO: this hack is necessary for a stable version but should be avoided for the next release. + Instead find a more elegant way to prevent redundant messages or entirely stop tracking states on procurement orders + """ + for proc in self.browse(cr, uid, ids, context=context): + if not proc.note or '_first_pass_done_' not in proc.note or proc.state not in ('confirmed', 'exception'): + super(procurement_order, self).message_track(cr, uid, [proc.id], tracked_fields, initial_values, context=context) + if proc.state == 'exception': + cr.execute("""UPDATE procurement_order set note = CONCAT(note, %s) WHERE id = %s""", ('_first_pass_done_',proc.id)) + + return True + def unlink(self, cr, uid, ids, context=None): procurements = self.read(cr, uid, ids, ['state'], context=context) unlink_ids = []