Add module purchase_line_move_state
This commit is contained in:
4
purchase_line_move_state/__init__.py
Normal file
4
purchase_line_move_state/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import purchase
|
||||
from . import wizard
|
||||
45
purchase_line_move_state/__openerp__.py
Normal file
45
purchase_line_move_state/__openerp__.py
Normal file
@@ -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 <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 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 <alexis.delattre@akretion.com> for any help or question about this module.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['purchase'],
|
||||
'data': [
|
||||
'purchase_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
62
purchase_line_move_state/purchase.py
Normal file
62
purchase_line_move_state/purchase.py
Normal file
@@ -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 <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, 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."),
|
||||
}
|
||||
24
purchase_line_move_state/purchase_view.xml
Normal file
24
purchase_line_move_state/purchase_view.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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">
|
||||
<xpath expr="//field[@name='order_line']/tree/field[@name='price_subtotal']" position="after">
|
||||
<field name="reception_state"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
3
purchase_line_move_state/wizard/__init__.py
Normal file
3
purchase_line_move_state/wizard/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import po_date_planned_update
|
||||
58
purchase_line_move_state/wizard/po_date_planned_update.py
Normal file
58
purchase_line_move_state/wizard/po_date_planned_update.py
Normal 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
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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">
|
||||
<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