diff --git a/purchase_date_planned_update/__init__.py b/purchase_date_planned_update/__init__.py new file mode 100644 index 0000000..861e30d --- /dev/null +++ b/purchase_date_planned_update/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import purchase +from . import wizard diff --git a/purchase_date_planned_update/__openerp__.py b/purchase_date_planned_update/__openerp__.py new file mode 100644 index 0000000..11c3372 --- /dev/null +++ b/purchase_date_planned_update/__openerp__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Date Planned Update module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + + +{ + 'name': 'Purchase Date Planned Update', + 'version': '0.1', + 'category': 'Purchase', + 'license': 'AGPL-3', + 'summary': "Update of date planned on PO line updates date on stock move", + 'description': """ +Purchase Date Planned Update +============================ + +If you update the date planned on a PO line, the schedule date of the move line will be updated. + +Please contact Alexis de Lattre from Akretion for any help or question about this module. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['purchase'], + 'data': [ + 'wizard/po_date_planned_update_view.xml', + 'purchase_view.xml', + ], + 'installable': True, +} diff --git a/purchase_date_planned_update/purchase.py b/purchase_date_planned_update/purchase.py new file mode 100644 index 0000000..6c3ce8e --- /dev/null +++ b/purchase_date_planned_update/purchase.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Date Planned Update module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# @author Sébastien Beau +# +# 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 . +# +############################################################################## + +from openerp.osv import orm +from openerp.tools.translate import _ +from openerp import SUPERUSER_ID + + +class PurchaseOrderLine(orm.Model): + _inherit = 'purchase.order.line' + + def write(self, cr, uid, ids, vals, context=None): + if vals.get('date_planned'): + if not isinstance(ids, list): + ids = [ids] + polines = self.browse(cr, uid, ids, context=context) + move_ids = [] + for poline in polines: + # Add msg in chatter + poline.order_id.message_post(_( + "Updated Scheduled Date of line %s from %s " + "to %s" + % (poline.name, poline.date_planned, + vals['date_planned']))) + move_ids += [ + sm.id for sm in poline.move_ids if sm.state != 'done'] + if move_ids: + # update related stock move + self.pool['stock.move'].write(cr, SUPERUSER_ID, move_ids, { + 'date_expected': vals['date_planned'], + }, context=context) + return super(PurchaseOrderLine, self).write( + cr, uid, ids, vals, context=context) diff --git a/purchase_date_planned_update/purchase_view.xml b/purchase_date_planned_update/purchase_view.xml new file mode 100644 index 0000000..8506a65 --- /dev/null +++ b/purchase_date_planned_update/purchase_view.xml @@ -0,0 +1,25 @@ + + + + + + + + usability.purchase.order.form + purchase.order + + + + + + + + + diff --git a/purchase_date_planned_update/wizard/__init__.py b/purchase_date_planned_update/wizard/__init__.py new file mode 100644 index 0000000..18df482 --- /dev/null +++ b/purchase_date_planned_update/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import po_date_planned_update diff --git a/purchase_date_planned_update/wizard/po_date_planned_update.py b/purchase_date_planned_update/wizard/po_date_planned_update.py new file mode 100644 index 0000000..0d13ca2 --- /dev/null +++ b/purchase_date_planned_update/wizard/po_date_planned_update.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Date Planned Update module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +from openerp.osv import orm, fields +from openerp.tools.translate import _ + + +class PoDatePlannedUpdate(orm.TransientModel): + _name = 'po.date.planned.update' + _description = 'Update Scheduled Date on PO' + + _columns = { + 'date_planned': fields.date('New Scheduled Date', required=True), + } + + def run(self, cr, uid, ids, context=None): + if context is None: + context = {} + assert len(ids) == 1, '1 ID' + wiz = self.browse(cr, uid, ids[0], context=context) + assert context.get('active_model') == 'purchase.order',\ + 'wrong active model' + assert context.get('active_id'), 'Missing active_id in ctx' + today = fields.date.context_today(self, cr, uid, context=context) + if wiz.date_planned < today: + raise orm.except_orm( + _('Error'), + _("The new scheduled date should not be in the past !")) + polo = self.pool['purchase.order.line'] + pol_ids = polo.search(cr, uid, [ + ('order_id', '=', context['active_id'])], context=context) + if pol_ids: + polo.write(cr, uid, pol_ids, { + 'date_planned': wiz.date_planned}, context=context) + else: + raise orm.except_orm( + _('Error'), + _("This PO doesn't have purchase order line")) + return True diff --git a/purchase_date_planned_update/wizard/po_date_planned_update_view.xml b/purchase_date_planned_update/wizard/po_date_planned_update_view.xml new file mode 100644 index 0000000..ad196ed --- /dev/null +++ b/purchase_date_planned_update/wizard/po_date_planned_update_view.xml @@ -0,0 +1,37 @@ + + + + + + + + po_date_planned_update_form + po.date.planned.update + +
+ + +
+
+
+
+
+ + + Update Scheduled Date + po.date.planned.update + form + new + + +
+