Add module purchase_date_planned_update

This commit is contained in:
Alexis de Lattre
2015-12-17 19:55:28 +01:00
parent 7d5efb1c49
commit 07a90ce45f
7 changed files with 226 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import po_date_planned_update

View File

@@ -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 <alexis.delattre@akretion.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="po_date_planned_update_form" model="ir.ui.view">
<field name="name">po_date_planned_update_form</field>
<field name="model">po.date.planned.update</field>
<field name="arch" type="xml">
<form string="Update Scheduled Date" version="7.0">
<group name="main">
<label string="This wizard will update the Scheduled Date on all the lines of this purchase order" colspan="2"/>
<field name="date_planned"/>
</group>
<footer>
<button name="run" type="object" string="Update"
class="oe_highlight"/>
<button special="cancel" string="Cancel" class="oe_link"/>
</footer>
</form>
</field>
</record>
<record id="po_date_planned_update_action" model="ir.actions.act_window">
<field name="name">Update Scheduled Date</field>
<field name="res_model">po.date.planned.update</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>