Port/rewrite purchase_date_planned_update to v8
This commit is contained in:
3
purchase_date_planned_update/__init__.py
Normal file
3
purchase_date_planned_update/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import wizard
|
||||||
47
purchase_date_planned_update/__openerp__.py
Normal file
47
purchase_date_planned_update/__openerp__.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Purchase Date Planned Update module for Odoo
|
||||||
|
# Copyright (C) 2015-2016 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
|
||||||
|
============================
|
||||||
|
|
||||||
|
This module adds a wizard on confirmed purchase orders to update the date planned on one or several purchase order lines: it will update the scheduled date of the purchase order lines and the expected date of the related stock moves that are not already received.
|
||||||
|
|
||||||
|
This module has been written by Alexis de Lattre from Akretion
|
||||||
|
<alexis.delattre@akretion.com>.
|
||||||
|
""",
|
||||||
|
'author': 'Akretion',
|
||||||
|
'website': 'http://www.akretion.com',
|
||||||
|
'depends': ['purchase'],
|
||||||
|
'data': [
|
||||||
|
'wizard/purchase_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)
|
||||||
26
purchase_date_planned_update/purchase_view.xml
Normal file
26
purchase_date_planned_update/purchase_view.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2015-2016 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">date_planned_update.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="action_cancel" position="after">
|
||||||
|
<button name="%(purchase_date_planned_update_action)d" type="action"
|
||||||
|
string="Update Scheduled Date"
|
||||||
|
states="confirmed,approved,except_picking,except_invoice"/>
|
||||||
|
</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 purchase_date_planned_update
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Purchase Date Planned Update module for Odoo
|
||||||
|
# Copyright (C) 2015-2016 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 import models, fields, api, _
|
||||||
|
from openerp.exceptions import Warning as UserError
|
||||||
|
import openerp.addons.decimal_precision as dp
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseDatePlannedUpdate(models.TransientModel):
|
||||||
|
_name = 'purchase.date.planned.update'
|
||||||
|
_description = 'Update Scheduled Date on PO'
|
||||||
|
|
||||||
|
date_planned = fields.Date(string='New Scheduled Date For All Lines')
|
||||||
|
line_ids = fields.One2many(
|
||||||
|
'purchase.line.date.planned.update', 'parent_id', string="Lines")
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields):
|
||||||
|
res = super(PurchaseDatePlannedUpdate, self).default_get(fields)
|
||||||
|
po = self.env['purchase.order'].browse(self._context['active_id'])
|
||||||
|
lines = []
|
||||||
|
for line in po.order_line:
|
||||||
|
if line.move_ids:
|
||||||
|
if all([move.state == 'done' for move in line.move_ids]):
|
||||||
|
continue
|
||||||
|
lines.append({
|
||||||
|
'purchase_line_id': line.id,
|
||||||
|
'product_id': line.product_id.id,
|
||||||
|
'name': line.name,
|
||||||
|
'product_qty': line.product_qty,
|
||||||
|
'date_planned': line.date_planned,
|
||||||
|
'product_uom': line.product_uom.id,
|
||||||
|
'price_unit': line.price_unit,
|
||||||
|
})
|
||||||
|
if not lines:
|
||||||
|
raise UserError(_(
|
||||||
|
"All purchase order lines have been fully received."))
|
||||||
|
res.update(line_ids=lines)
|
||||||
|
return res
|
||||||
|
|
||||||
|
@api.onchange('date_planned')
|
||||||
|
def date_planned_change(self):
|
||||||
|
if self.date_planned:
|
||||||
|
for line in self.line_ids:
|
||||||
|
line.date_planned = self.date_planned
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def run(self):
|
||||||
|
self.ensure_one()
|
||||||
|
for wline in self.line_ids:
|
||||||
|
if wline.date_planned != wline.purchase_line_id.date_planned:
|
||||||
|
pline = wline.purchase_line_id
|
||||||
|
pline.order_id.message_post(_(
|
||||||
|
"Updated Scheduled Date of line <b>%s</b> from %s "
|
||||||
|
"to <b>%s</b>")
|
||||||
|
% (pline.name, pline.date_planned, wline.date_planned))
|
||||||
|
# Update PO line
|
||||||
|
pline.date_planned = wline.date_planned
|
||||||
|
# Update move lines
|
||||||
|
if pline.move_ids:
|
||||||
|
moves = pline.move_ids.filtered(
|
||||||
|
lambda x: x.state != 'done')
|
||||||
|
moves.write({'date_expected': wline.date_planned})
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseLineDatePlannedUpdate(models.TransientModel):
|
||||||
|
_name = 'purchase.line.date.planned.update'
|
||||||
|
_description = 'Purchase Line Date Planned Update'
|
||||||
|
|
||||||
|
parent_id = fields.Many2one(
|
||||||
|
'purchase.date.planned.update', string='Parent')
|
||||||
|
purchase_line_id = fields.Many2one(
|
||||||
|
'purchase.order.line', string='Purchase Order Line', readonly=True)
|
||||||
|
product_id = fields.Many2one(
|
||||||
|
'product.product', string='Product', readonly=True)
|
||||||
|
name = fields.Text('Description', readonly=True)
|
||||||
|
product_qty = fields.Float(
|
||||||
|
string='Quantity', digits=dp.get_precision('Product Unit of Measure'),
|
||||||
|
readonly=True)
|
||||||
|
date_planned = fields.Date(string='Scheduled Date', required=True)
|
||||||
|
product_uom = fields.Many2one(
|
||||||
|
'product.uom', string='Product Unit of Measure', readonly=True)
|
||||||
|
price_unit = fields.Float(
|
||||||
|
string='Unit Price', readonly=True,
|
||||||
|
digits=dp.get_precision('Product Price'))
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2015-2016 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_date_planned_update_form" model="ir.ui.view">
|
||||||
|
<field name="name">purchase_date_planned_update_form</field>
|
||||||
|
<field name="model">purchase.date.planned.update</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Update Scheduled Date">
|
||||||
|
<group name="main">
|
||||||
|
<label string="You can update all the lines at once or update only selected lines." colspan="2"/>
|
||||||
|
<label string="The purchase order lines that are already fully received are not listed below." colspan="2"/>
|
||||||
|
<field name="date_planned"/>
|
||||||
|
<field name="line_ids" colspan="2" nolabel="1">
|
||||||
|
<tree editable="bottom">
|
||||||
|
<field name="purchase_line_id" invisible="1"/>
|
||||||
|
<field name="product_id"/>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="date_planned"/>
|
||||||
|
<field name="product_qty"/>
|
||||||
|
<field name="product_uom" groups="product.group_uom"/>
|
||||||
|
<field name="price_unit"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</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="purchase_date_planned_update_action" model="ir.actions.act_window">
|
||||||
|
<field name="name">Update Scheduled Date</field>
|
||||||
|
<field name="res_model">purchase.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