From 41b2cf3a27118df5be88b6418ea7e2fbcdd666f9 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Thu, 24 Nov 2016 14:36:59 +0100 Subject: [PATCH] [FIX] purchase: double validation minimum amount When we enable in the settings 'Get 2 levels of approvals' with a 'Double validation amount', and then create a request for quotation. When we confirm it, even if the total amount of the request for quotation is below the amount set in the settings, the purchase order needs to be approved. We excpect that if a purchase order has a total amount below the validation amount setting, the purchase order is automatically confirmed. So to fix it, we compare the amount when the user click on the button confirm. And immediatly call the function 'button_approve' if the amount is below the double validation amount set in settings. Bug introduced in rev: https://github.com/odoo/odoo/commit/9d4efc81a opw - 694381 --- addons/purchase/models/purchase.py | 11 +++++------ addons/purchase/tests/test_create_picking.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 8d1c5ae56c5..d5b3ea4ecd3 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -309,10 +309,6 @@ class PurchaseOrder(models.Model): @api.multi def button_approve(self, force=False): - if self.company_id.po_double_validation == 'two_step'\ - and self.amount_total >= self.env.user.company_id.currency_id.compute(self.company_id.po_double_validation_amount, self.currency_id)\ - and not self.user_has_groups('purchase.group_purchase_manager'): - raise UserError(_('You need purchase manager access rights to validate an order above %.2f %s.') % (self.company_id.po_double_validation_amount, self.company_id.currency_id.name)) self.write({'state': 'purchase'}) self._create_picking() if self.company_id.po_lock == 'lock': @@ -331,8 +327,11 @@ class PurchaseOrder(models.Model): continue order._add_supplier_to_product() # Deal with double validation process - if order.company_id.po_double_validation == 'one_step': - order.button_approve(force=True) + if order.company_id.po_double_validation == 'one_step'\ + or (order.company_id.po_double_validation == 'two_step'\ + and order.amount_total < self.env.user.company_id.currency_id.compute(order.company_id.po_double_validation_amount, order.currency_id))\ + or order.user_has_groups('purchase.group_purchase_manager'): + order.button_approve() else: order.write({'state': 'to approve'}) return True diff --git a/addons/purchase/tests/test_create_picking.py b/addons/purchase/tests/test_create_picking.py index 228afb7b566..0d4833f912b 100644 --- a/addons/purchase/tests/test_create_picking.py +++ b/addons/purchase/tests/test_create_picking.py @@ -76,7 +76,7 @@ class TestCreatePicking(common.TestProductCommon): def test_01_check_double_validation(self): # make double validation two step - self.env.user.company_id.write({'po_double_validation': 'two_step'}) + self.env.user.company_id.write({'po_double_validation': 'two_step','po_double_validation_amount':2000.00}) # Draft purchase order created self.po = self.env['purchase.order'].sudo(self.user_purchase_user).create(self.po_vals)