diff --git a/purchase_line_move_state/__init__.py b/purchase_line_move_state/__init__.py new file mode 100644 index 0000000..861e30d --- /dev/null +++ b/purchase_line_move_state/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import purchase +from . import wizard diff --git a/purchase_line_move_state/__openerp__.py b/purchase_line_move_state/__openerp__.py new file mode 100644 index 0000000..a78f001 --- /dev/null +++ b/purchase_line_move_state/__openerp__.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Line Move State 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 Line Move State', + 'version': '0.1', + 'category': 'Purchase', + 'license': 'AGPL-3', + 'summary': "Adds reception status on PO lines", + 'description': """ +Purchase Line Move State +============================ + +Adds a field *Reception Status* on PO lines that reflect the status of the related stock moves. + +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': [ + 'purchase_view.xml', + ], + 'installable': True, +} diff --git a/purchase_line_move_state/purchase.py b/purchase_line_move_state/purchase.py new file mode 100644 index 0000000..5ef714c --- /dev/null +++ b/purchase_line_move_state/purchase.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Line Move State 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, fields +from openerp.tools.translate import _ + + +class PurchaseOrderLine(orm.Model): + _inherit = 'purchase.order.line' + + def _get_reception_state( + self, cr, uid, ids, field_name, args, context=None): + res = {} + state_label = { + 'assigned': _('Waiting'), + 'done': _('Received'), + 'cancel': _('Cancelled'), + } + for line in self.browse(cr, uid, ids, context=context): + count = {} + for move in line.move_ids: + if move.state in count: + count[move.state] += move.product_qty + else: + count[move.state] = move.product_qty + if count: + entries = [] + for state, qty in count.iteritems(): + entries.append( + "%s: %s" % (state_label.get(state, state), qty)) + label = "\n".join(entries) + else: + label = _('Not applicable') + res[line.id] = label + return res + + _columns = { + 'reception_state': fields.function( + _get_reception_state, + string='Reception Status', readonly=True, + type='char', help="Human readable status of the reception."), + } diff --git a/purchase_line_move_state/purchase_view.xml b/purchase_line_move_state/purchase_view.xml new file mode 100644 index 0000000..4730489 --- /dev/null +++ b/purchase_line_move_state/purchase_view.xml @@ -0,0 +1,24 @@ + + + + + + + + usability.purchase.order.form + purchase.order + + + + + + + + + + + diff --git a/purchase_line_move_state/wizard/__init__.py b/purchase_line_move_state/wizard/__init__.py new file mode 100644 index 0000000..18df482 --- /dev/null +++ b/purchase_line_move_state/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import po_date_planned_update diff --git a/purchase_line_move_state/wizard/po_date_planned_update.py b/purchase_line_move_state/wizard/po_date_planned_update.py new file mode 100644 index 0000000..0d13ca2 --- /dev/null +++ b/purchase_line_move_state/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_line_move_state/wizard/po_date_planned_update_view.xml b/purchase_line_move_state/wizard/po_date_planned_update_view.xml new file mode 100644 index 0000000..345767d --- /dev/null +++ b/purchase_line_move_state/wizard/po_date_planned_update_view.xml @@ -0,0 +1,36 @@ + + + + + + + + po_date_planned_update_form + po.date.planned.update + +
+ + + +
+
+
+
+
+ + + Update Scheduled Date + po.date.planned.update + form + new + + +
+