← Back to team overview

openerp-community team mailing list archive

lp:~openerp-community/purchase-wkfl/6.1-purchase_internal_validation into lp:purchase-wkfl/6.1

 

Maxime Chambreuil (http://www.savoirfairelinux.com) has proposed merging lp:~openerp-community/purchase-wkfl/6.1-purchase_internal_validation into lp:purchase-wkfl/6.1.

Requested reviews:
  Purchase Core Editors (purchase-core-editors)

For more details, see:
https://code.launchpad.net/~openerp-community/purchase-wkfl/6.1-purchase_internal_validation/+merge/170305

[IMP] Moved out from lp:openobject-addons/extra-trunk
-- 
https://code.launchpad.net/~openerp-community/purchase-wkfl/6.1-purchase_internal_validation/+merge/170305
Your team OpenERP Community is subscribed to branch lp:~openerp-community/purchase-wkfl/6.1-purchase_internal_validation.
=== added directory 'purchase_internal_validation'
=== added file 'purchase_internal_validation/__init__.py'
--- purchase_internal_validation/__init__.py	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/__init__.py	2013-06-19 11:57:33 +0000
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    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/>.
+#
+##############################################################################
+
+import purchase_internal_validation_installer
+import purchase_order
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'purchase_internal_validation/__openerp__.py'
--- purchase_internal_validation/__openerp__.py	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/__openerp__.py	2013-06-19 11:57:33 +0000
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    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" : "Internal Validation for Purchase",
+    "version" : "1.1",
+    "category": 'Purchases',
+    "images" : ["images/purchase_validation.jpeg"],
+    "depends" : ["base","purchase"],
+    "author" : 'Savoir-faire Linux',
+    "description": """
+        This module modifies the purchase workflow in order to validate purchases 
+        that exceeds minimum amount set by configuration wizard.
+    """,
+    'website': 'http://www.savoirfairelinux.com',
+    'init_xml': [],
+    'update_xml': [
+	   'purchase_internal_validation_workflow.xml',
+	   'purchase_internal_validation_installer.xml',
+           'purchase_view.xml'
+	    ],
+    'demo_xml': [],
+    'installable': True,
+    'active': False,
+    'certificate' : '',
+
+}

=== added directory 'purchase_internal_validation/i18n'
=== added file 'purchase_internal_validation/i18n/en_US.po'
--- purchase_internal_validation/i18n/en_US.po	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/i18n/en_US.po	2013-06-19 11:57:33 +0000
@@ -0,0 +1,122 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* purchase_internal_validation
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 6.1-dev\n"
+"Report-Msgid-Bugs-To: support@xxxxxxxxxxx\n"
+"POT-Creation-Date: 2011-04-03 23:59+0000\n"
+"PO-Revision-Date: 2011-04-03 23:59+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: purchase_internal_validation
+#: code:addons/purchase_internal_validation/purchase_order.py:51
+#, python-format
+msgid "Purchase order '%s' is waiting for validation."
+msgstr "Purchase order '%s' is waiting for validation."
+
+#. module: purchase_internal_validation
+#: code:addons/purchase_internal_validation/purchase_order.py:47
+#, python-format
+msgid "You can not wait for purchase order to be validated without Purchase Order Lines."
+msgstr "You can not wait for purchase order to be validated without Purchase Order Lines."
+
+#. module: purchase_internal_validation
+#: view:purchase.order:0
+msgid "Refuse"
+msgstr "Refuse"
+
+#. module: purchase_internal_validation
+#: sql_constraint:purchase.order:0
+msgid "Order Reference must be unique !"
+msgstr "Order Reference must be unique !"
+
+#. module: purchase_internal_validation
+#: code:addons/purchase_internal_validation/purchase_order.py:47
+#, python-format
+msgid "Error !"
+msgstr "Error !"
+
+#. module: purchase_internal_validation
+#: field:purchase.internal.validation.installer,progress:0
+msgid "Configuration Progress"
+msgstr "Configuration Progress"
+
+#. module: purchase_internal_validation
+#: view:purchase.order:0
+msgid "Confirm"
+msgstr "Confirm"
+
+#. module: purchase_internal_validation
+#: field:purchase.internal.validation.installer,config_logo:0
+msgid "Image"
+msgstr "Image"
+
+#. module: purchase_internal_validation
+#: view:purchase.internal.validation.installer:0
+msgid "title"
+msgstr "title"
+
+#. module: purchase_internal_validation
+#: model:ir.model,name:purchase_internal_validation.model_purchase_order
+msgid "Purchase Order"
+msgstr "Purchase Order"
+
+#. module: purchase_internal_validation
+#: model:ir.actions.act_window,name:purchase_internal_validation.action_config_purchase_limit_amount
+#: view:purchase.internal.validation.installer:0
+msgid "Configure Limit Amount for Purchase"
+msgstr "Configure Limit Amount for Purchase"
+
+#. module: purchase_internal_validation
+#: model:ir.module.module,shortdesc:purchase_internal_validation.module_meta_information
+msgid "Internal Validation for Purchase"
+msgstr "Internal Validation for Purchase"
+
+#. module: purchase_internal_validation
+#: view:purchase.internal.validation.installer:0
+msgid "Purchase Application Configuration"
+msgstr "Purchase Application Configuration"
+
+#. module: purchase_internal_validation
+#: help:purchase.internal.validation.installer,limit_amount:0
+msgid "Maximum amount after which internal validation of purchase is required."
+msgstr "Maximum amount after which internal validation of purchase is required."
+
+#. module: purchase_internal_validation
+#: model:ir.model,name:purchase_internal_validation.model_purchase_internal_validation_installer
+msgid "purchase.internal.validation.installer"
+msgstr "purchase.internal.validation.installer"
+
+#. module: purchase_internal_validation
+#: view:purchase.internal.validation.installer:0
+msgid "Define minimum amount after which purchase needs to be validated."
+msgstr "Define minimum amount after which purchase needs to be validated."
+
+#. module: purchase_internal_validation
+#: field:purchase.internal.validation.installer,limit_amount:0
+msgid "Maximum Purchase Amount"
+msgstr "Maximum Purchase Amount"
+
+#. module: purchase_internal_validation
+#: model:ir.module.module,description:purchase_internal_validation.module_meta_information
+msgid "\n"
+"        This module modifies the purchase workflow in order to validate purchases \n"
+"        that exceeds minimum amount set by configuration wizard.\n"
+"    "
+msgstr "\n"
+"        This module modifies the purchase workflow in order to validate purchases \n"
+"        that exceeds minimum amount set by configuration wizard.\n"
+"    "
+
+#. module: purchase_internal_validation
+#: view:purchase.internal.validation.installer:0
+msgid "res_config_contents"
+msgstr "res_config_contents"
+

=== added file 'purchase_internal_validation/purchase_internal_validation_installer.py'
--- purchase_internal_validation/purchase_internal_validation_installer.py	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/purchase_internal_validation_installer.py	2013-06-19 11:57:33 +0000
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2011 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from osv import fields, osv
+
+class purchase_internal_validation_installer(osv.osv_memory):
+    _name = 'purchase.internal.validation.installer'
+    _inherit = 'res.config'
+    _columns = {
+        'limit_amount': fields.integer('Maximum Purchase Amount', required=True, help="Maximum amount after which internal validation of purchase is required."),
+    }
+
+    _defaults = {
+        'limit_amount': 5000,
+    }
+
+    def execute(self, cr, uid, ids, context=None):
+        data = self.read(cr, uid, ids, context=context)
+        if not data:
+            return {}
+        amt = data[0]['limit_amount']
+        data_pool = self.pool.get('ir.model.data')
+        transition_obj = self.pool.get('workflow.transition')
+        waiting = data_pool._get_id(cr, uid, 'purchase_internal_validation', 'trans_draft_waiting_internal_validation')
+        waiting_id = data_pool.browse(cr, uid, waiting, context=context).res_id
+        confirm = data_pool._get_id(cr, uid, 'purchase', 'trans_draft_confirmed')
+        confirm_id = data_pool.browse(cr, uid, confirm, context=context).res_id
+        transition_obj.write(cr, uid, waiting_id, {'condition': 'amount_total>=%s' % (amt)})
+        transition_obj.write(cr, uid, confirm_id, {'condition': 'amount_total<%s' % (amt)})
+        return {}
+
+purchase_internal_validation_installer()
+
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+

=== added file 'purchase_internal_validation/purchase_internal_validation_installer.xml'
--- purchase_internal_validation/purchase_internal_validation_installer.xml	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/purchase_internal_validation_installer.xml	2013-06-19 11:57:33 +0000
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <!-- configuration view -->
+
+        <record id="view_config_purchase_limit_amount" model="ir.ui.view">
+            <field name="name">Configure Limit Amount for Purchase</field>
+            <field name="model">purchase.internal.validation.installer</field>
+            <field name="type">form</field>
+            <field name="inherit_id" ref="base.res_config_view_base"/>
+            <field name="arch" type="xml">
+              <data>
+                <form position="attributes">
+                  <attribute name="string">Purchase Application Configuration</attribute>
+                </form>
+                <separator string="title" position="attributes">
+                <attribute name="string">Configure Limit Amount for Purchase</attribute>
+                  </separator>
+                  <xpath expr="//label[@string='description']" position="attributes">
+                    <attribute name="string">Define minimum amount after which purchase needs to be validated.</attribute>
+                  </xpath>
+                <xpath expr='//separator[@string="vsep"]' position='attributes'>
+                      <attribute name='rowspan'>15</attribute>
+                      <attribute name='string'></attribute>
+                  </xpath>
+                <group string="res_config_contents" position="replace">
+                  <field name="limit_amount"/>
+                  <newline/>
+                </group>
+              </data>
+            </field>
+        </record>
+
+        <record id="action_config_purchase_limit_amount" model="ir.actions.act_window">
+            <field name="name">Configure Limit Amount for Purchase</field>
+            <field name="type">ir.actions.act_window</field>
+            <field name="res_model">purchase.internal.validation.installer</field>
+            <field name="view_id" ref="view_config_purchase_limit_amount"/>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="target">new</field>
+        </record>
+
+        <!-- register configuration wizard -->
+        <record id="config_wizard_step_purchase_limit_amount" model="ir.actions.todo">
+            <field name="action_id" ref="action_config_purchase_limit_amount"/>
+            <field name="restart">onskip</field>
+        </record>
+        
+    </data>
+</openerp>

=== added file 'purchase_internal_validation/purchase_internal_validation_workflow.xml'
--- purchase_internal_validation/purchase_internal_validation_workflow.xml	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/purchase_internal_validation_workflow.xml	2013-06-19 11:57:33 +0000
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <!-- Server Actions -->
+        <record model="ir.actions.server" id="purchase_waiting_validation">
+            <field name="name">Notify the purchase manager group of a new purchase order to validate</field>
+            <field name="model_id" ref="model_purchase_order" />
+            <field name="state">email</field>
+            <field name="sequence">5</field>
+            <field name="condition">True</field>
+            <field name="email">object.create_uid.user_email</field>
+            <field name="subject">New PO to validate</field>
+            <field name="message">Hello,
+&lt;br /&gt;
+&lt;br /&gt;
+The purchase order [[object.name]] is waiting for validation:
+&lt;br /&gt;
+&lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt;
+&lt;br /&gt;
+Thank you.
+&lt;br /&gt;
+--
+&lt;br /&gt;
+OpenERP</field>
+        </record>
+
+        <record model="ir.actions.server" id="purchase_refused">
+            <field name="name">Notify the buyer that the purchase order has been refused</field>
+            <field name="model_id" ref="model_purchase_order" />
+            <field name="state">email</field>
+            <field name="sequence">5</field>
+            <field name="condition">True</field>
+            <field name="email">object.create_uid.user_email</field>
+            <field name="subject">[[object.name]] refused</field>
+            <field name="message">Hello,
+&lt;br /&gt;
+&lt;br /&gt;
+The purchase order [[object.name]] has been refused:
+&lt;br /&gt;
+&lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt;
+&lt;br /&gt;
+Thank you.
+&lt;br /&gt;
+--
+&lt;br /&gt;
+OpenERP</field>
+        </record>
+
+        <record model="ir.actions.server" id="purchase_validated">
+            <field name="name">Notify the buyer that the purchase order has been validated</field>
+            <field name="model_id" ref="model_purchase_order" />
+            <field name="state">email</field>
+            <field name="sequence">5</field>
+            <field name="condition">True</field>
+            <field name="email">object.create_uid.user_email</field>
+            <field name="subject">[[object.name]] validated</field>
+            <field name="message">Hello,
+&lt;br /&gt;
+&lt;br /&gt;
+The purchase order [[object.name]] has been validated:
+&lt;br /&gt;
+&lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt;
+&lt;br /&gt;
+Thank you.
+&lt;br /&gt;
+--
+&lt;br /&gt;
+OpenERP</field>
+        </record>
+
+        <!-- Activities -->
+        <record model="workflow.activity" id="purchase_waiting_internal_validation">
+            <field name="name">wait_valid</field>
+            <field name="wkf_id" ref="purchase.purchase_order"/>
+            <field name="kind">function</field>
+            <field name="split_mode">XOR</field>
+            <field name="join_mode">XOR</field>
+            <field name="action">wkf_wait_validation_order()</field>
+            <field name="action_id" ref="purchase_waiting_validation"/>
+        </record>
+
+        <record model="workflow.activity" id="purchase_waiting_correction">
+            <field name="name">wait_correct</field>
+            <field name="wkf_id" ref="purchase.purchase_order"/>
+            <field name="kind">function</field>
+            <field name="split_mode">XOR</field>
+            <field name="join_mode">XOR</field>
+            <field name="action">wkf_wait_correction()</field>
+            <field name="action_id" ref="purchase_refused"/>
+        </record>
+
+        <record model="workflow.activity" id="purchase.act_confirmed">
+            <field name="action_id" ref="purchase_validated"/>
+        </record>
+
+        <!-- Transitions -->
+        <record id="trans_draft_waiting_internal_validation" model="workflow.transition">
+            <field name="act_from" ref="purchase.act_draft"/>
+            <field name="act_to" ref="purchase_waiting_internal_validation"/>
+            <field name="condition">amount_untaxed &gt;= 1000</field>
+            <field name="signal">purchase_confirm</field>
+        </record>
+
+        <record id="purchase.trans_draft_confirmed" model="workflow.transition">
+            <field name="condition">amount_untaxed &lt; 1000</field>
+        </record>
+
+        <record id="trans_waiting_approval_confirmed" model="workflow.transition">
+            <field name="act_from" ref="purchase_waiting_internal_validation"/>
+            <field name="act_to" ref="purchase.act_confirmed"/>
+            <field name="group_id" ref="purchase.group_purchase_manager"/>
+            <field name="signal">purchase_confirm</field>
+        </record>
+
+        <record id="trans_waiting_approval_wait_correction" model="workflow.transition">
+            <field name="act_from" ref="purchase_waiting_internal_validation"/>
+            <field name="act_to" ref="purchase_waiting_correction"/>
+            <field name="group_id" ref="purchase.group_purchase_manager"/>
+            <field name="signal">purchase_refuse</field>
+        </record>
+
+        <record id="trans_waiting_correction_wait_approval" model="workflow.transition">
+            <field name="act_from" ref="purchase_waiting_correction"/>
+            <field name="act_to" ref="purchase_waiting_internal_validation"/>
+            <field name="signal">purchase_confirm</field>
+        </record>
+
+        <record id="trans_waiting_correction_cancel" model="workflow.transition">
+            <field name="act_from" ref="purchase_waiting_correction"/>
+            <field name="act_to" ref="purchase.act_cancel"/>
+            <field name="signal">purchase_cancel</field>
+        </record>
+
+    </data>
+</openerp>

=== added file 'purchase_internal_validation/purchase_order.py'
--- purchase_internal_validation/purchase_order.py	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/purchase_order.py	2013-06-19 11:57:33 +0000
@@ -0,0 +1,70 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#    
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#
+##############################################################################
+
+import netsvc
+from tools.translate import _
+from osv import osv, fields
+
+class purchase_order(osv.osv):
+    _inherit = 'purchase.order'
+
+    STATE_SELECTION = [
+        ('draft', 'Request for Quotation'),
+        ('wait_valid', 'Waiting for Validation'),
+        ('wait_correct', 'Waiting for Correction'),
+        ('wait', 'Waiting'),
+        ('confirmed', 'Waiting Approval'),
+        ('approved', 'Approved'),
+        ('except_picking', 'Shipping Exception'),
+        ('except_invoice', 'Invoice Exception'),
+        ('done', 'Done'),
+        ('cancel', 'Cancelled')
+    ]
+
+    _columns = {
+        'state': fields.selection(STATE_SELECTION, 'State', readonly=True, help="The state of the purchase order or the quotation request. A quotation is a purchase order in a 'Draft' state. Then the order has to be confirmed by the user, the state switch to 'Confirmed'. Then the supplier must confirm the order to change the state to 'Approved'. When the purchase order is paid and received, the state becomes 'Done'. If a cancel action occurs in the invoice or in the reception of goods, the state becomes in exception.", select=True)
+   } 
+
+    #TODO: implement messages system
+    def wkf_wait_validation_order(self, cr, uid, ids, context=None):
+        todo = []
+        for po in self.browse(cr, uid, ids, context=context):
+            if not po.order_line:
+                raise osv.except_osv(_('Error !'),_('You can not wait for purchase order to be validated without Purchase Order Lines.'))
+            for line in po.order_line:
+                if line.state=='draft':
+                    todo.append(line.id)
+            message = _("Purchase order '%s' is waiting for validation.") % (po.name,)
+            self.log(cr, uid, po.id, message)
+#        current_name = self.name_get(cr, uid, ids)[0][1]
+        for id in ids:
+            self.write(cr, uid, [id], {'state' : 'wait_valid'})
+        return True
+
+    #TODO: implement messages system
+    def wkf_wait_correction(self, cr, uid, ids, context=None):
+        for id in ids:
+            self.write(cr, uid, [id], {'state' : 'wait_correct'})
+        return True
+
+purchase_order()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'purchase_internal_validation/purchase_view.xml'
--- purchase_internal_validation/purchase_view.xml	1970-01-01 00:00:00 +0000
+++ purchase_internal_validation/purchase_view.xml	2013-06-19 11:57:33 +0000
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <record id="purchase_order_internal_validation_form" model="ir.ui.view">
+            <field name="name">purchase.order.form.internalvalidation</field>
+            <field name="model">purchase.order</field>
+            <field name="inherit_id" ref="purchase.purchase_order_form"/>
+            <field name="arch" type="xml">
+                <field name="state" position="after">
+                    <button name="purchase_refuse" states="wait_valid" string="Refuse" icon="gtk-cancel"/>
+                    <button name="purchase_confirm" states="wait_valid" string="Confirm" icon="gtk-go-forward"/>
+                    <button name="purchase_cancel" states="wait_correct" string="Cancel" icon="gtk-cancel"/>
+                    <button name="purchase_confirm" states="wait_correct" string="Confirm" icon="gtk-go-forward"/>
+                </field>
+            </field>
+        </record>
+
+
+    </data>
+</openerp>


Follow ups