Add module purchase_date_planned_update
This commit is contained in:
4
purchase_date_planned_update/__init__.py
Normal file
4
purchase_date_planned_update/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import purchase
|
||||||
|
from . import wizard
|
||||||
46
purchase_date_planned_update/__openerp__.py
Normal file
46
purchase_date_planned_update/__openerp__.py
Normal file
@@ -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 <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/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
'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 <alexis.delattre@akretion.com> 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,
|
||||||
|
}
|
||||||
53
purchase_date_planned_update/purchase.py
Normal file
53
purchase_date_planned_update/purchase.py
Normal file
@@ -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 <alexis.delattre@akretion.com>
|
||||||
|
# @author Sébastien Beau <sebastien.beau@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
|
||||||
|
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 <b>%s</b> from %s "
|
||||||
|
"to <b>%s</b>"
|
||||||
|
% (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)
|
||||||
25
purchase_date_planned_update/purchase_view.xml
Normal file
25
purchase_date_planned_update/purchase_view.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?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="purchase_order_form" model="ir.ui.view">
|
||||||
|
<field name="name">usability.purchase.order.form</field>
|
||||||
|
<field name="model">purchase.order</field>
|
||||||
|
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<button name="purchase_cancel" position="after">
|
||||||
|
<button name="%(po_date_planned_update_action)d" type="action"
|
||||||
|
string="Update Scheduled Date"/>
|
||||||
|
</button>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
3
purchase_date_planned_update/wizard/__init__.py
Normal file
3
purchase_date_planned_update/wizard/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import po_date_planned_update
|
||||||
@@ -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
|
||||||
@@ -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>
|
||||||
Reference in New Issue
Block a user