[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
This commit is contained in:
Pierre Masereel
2016-11-24 17:17:38 +01:00
parent 440c8cc7c9
commit 41b2cf3a27
2 changed files with 6 additions and 7 deletions
+5 -6
View File
@@ -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
+1 -1
View File
@@ -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)