[ADD] purchase: add the two-step validation process

Two-step validation process is set up at the level of the company.
This commit is contained in:
Nicolas Martinelli
2015-09-03 13:15:16 +02:00
parent e87144b255
commit 3f48d2b6c4
4 changed files with 27 additions and 8 deletions
+11 -5
View File
@@ -1,13 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp import api, fields, models, _
from openerp import fields, models
class company(models.Model):
_inherit = 'res.company'
po_lead = fields.Float(string='Purchase Lead Time', required=True,
help="Margin of error for vendor lead times. When the system "\
"generates Purchase Orders for procuring products, "\
"they will be scheduled that many days earlier "\
po_lead = fields.Float(string='Purchase Lead Time', required=True,\
help="Margin of error for vendor lead times. When the system "
"generates Purchase Orders for procuring products, "
"they will be scheduled that many days earlier "
"to cope with unexpected vendor delays.", default=1.0)
po_double_validation = fields.Selection([
('one_step', 'Confirm purchase orders in one step'),
('two_step', 'Get 2 levels of approvals to confirm a purchase order')
], string="Levels of Approvals", default='one_step',\
help="Provide a double validation mechanism for purchases")
+1
View File
@@ -10,6 +10,7 @@
<field name="arch" type="xml">
<xpath expr="//group[@name='logistics_grp']" position="inside">
<field name="po_lead"/>
<field name="po_double_validation" widget="radio"/>
</xpath>
</field>
</record>
+8 -1
View File
@@ -145,6 +145,7 @@ class PurchaseOrder(models.Model):
product_id = fields.Many2one('product.product', related='order_line.product_id', string='Product')
create_uid = fields.Many2one('res.users', 'Responsible')
company_id = fields.Many2one('res.company', 'Company', required=True, select=1, states=READONLY_STATES, default=lambda self: self.env.user.company_id.id)
po_double_validation = fields.Selection(related='company_id.po_double_validation', store=False, readonly=True)
picking_type_id = fields.Many2one('stock.picking.type', 'Deliver To', states=READONLY_STATES, required=True, default=_default_picking_type,\
help="This will determine picking type of incoming shipment")
@@ -242,7 +243,13 @@ class PurchaseOrder(models.Model):
@api.multi
def button_confirm(self):
return self.button_approve()
# Deal with double validation process
if self.user_has_groups('purchase.group_purchase_manager'):
return self.button_approve()
elif self.po_double_validation == 'two_step':
self.write({'state': 'to approve'})
else:
return self.button_approve()
@api.multi
def button_cancel(self):
+7 -2
View File
@@ -143,14 +143,18 @@
<button name="print_quotation" string="Re-Print RFQ" type="object" states="sent" groups="base.group_user"/>
<button name="button_confirm" type="object" states="draft" string="Confirm Order" id="draft_confirm"/>
<button name="button_confirm" type="object" states="sent" string="Confirm Order" class="oe_highlight" id="bid_confirm"/>
<button name="button_approve" type="object" states="to approve" string="Approve Order" class="oe_highlight" groups="purchase.group_purchase_manager"/>
<button name="button_approve" type="object" string="Approve Order" class="oe_highlight" groups="purchase.group_purchase_manager"
attrs="{'invisible': ['|', ('state', 'not in', ('to approve')), ('po_double_validation', '=', 'one_step')]}"/>
<button name="action_rfq_send" states="approved" string="Send PO by Email" type="object" context="{'send_rfq':False}"/>
<button name="%(purchase_open_picking)d" string="Receive Products" type="action" attrs="{'invisible': [('state','not in', ('purchase','done'))]}"/>
<button name="button_draft" states="cancel" string="Set to Draft" type="object" />
<button name="button_cancel" states="draft,to approve,sent,purchase" string="Cancel" type="object" />
<button name="button_done" type="object" string="Set to Done" states="purchase"
help="If a purchase order is done, you can not modify it manually anymore. But you will still be able to bill or receive."/>
<field name="state" widget="statusbar" statusbar_visible="draft,sent,purchase,done" readonly="1"/>
<field name="state" widget="statusbar" statusbar_visible="draft,sent,purchase,done" readonly="1"
attrs="{'invisible': [('po_double_validation', '=', 'two_step')]}"/>
<field name="state" widget="statusbar" statusbar_visible="draft,sent,to approve,purchase,done" readonly="1"
attrs="{'invisible': [('po_double_validation', '=', 'one_step')]}"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
@@ -183,6 +187,7 @@
<field name="date_order"/>
<field name="origin" attrs="{'invisible': [('origin','=',False)]}"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="po_double_validation" invisible='1'/>
</group>
</group>
<notebook>