1
1
# Copyright 2018 ForgeFlow S.L.
2
2
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
3
3
4
+ from odoo import _ , fields
5
+ from odoo .exceptions import ValidationError
4
6
from odoo .tests import common
5
7
from odoo .tests .common import tagged
6
8
@@ -26,3 +28,56 @@ def test_02_form(self):
26
28
) as form :
27
29
form .save ()
28
30
self .assertTrue (form .hide_post_button )
31
+
32
+ def test_03_move_post (self ):
33
+ group_ids = [
34
+ self .env .ref ("base.group_system" ).id ,
35
+ self .env .ref ("account.group_account_manager" ).id ,
36
+ ]
37
+ self .test_user_1 = self .env ["res.users" ].create (
38
+ {
39
+ "name" : "John" ,
40
+ "login" : "test1" ,
41
+
42
+ "groups_id" : [(6 , 0 , group_ids )],
43
+ }
44
+ )
45
+ self .test_user_2 = self .env ["res.users" ].create (
46
+ {
47
+ "name" : "Mike" ,
48
+ "login" : "test2" ,
49
+
50
+ "groups_id" : [(6 , 0 , group_ids )],
51
+ }
52
+ )
53
+ self .env ["tier.definition" ].create (
54
+ {
55
+ "model_id" : self .env ["ir.model" ]
56
+ .search ([("model" , "=" , "account.move" )])
57
+ .id ,
58
+ "definition_domain" : "[('move_type', '=', 'out_invoice')]" ,
59
+ "reviewer_id" : self .test_user_1 .id ,
60
+ }
61
+ )
62
+ partner = self .env ["res.partner" ].create ({"name" : "Test Partner" })
63
+ product = self .env ["product.product" ].create ({"name" : "Test product" })
64
+ invoice = self .env ["account.move" ].create (
65
+ {
66
+ "move_type" : "out_invoice" ,
67
+ "partner_id" : partner .id ,
68
+ "invoice_date_due" : fields .Date .from_string ("2024-01-01" ),
69
+ "invoice_line_ids" : [
70
+ (0 , 0 , {"product_id" : product .id , "quantity" : 1 , "price_unit" : 30 })
71
+ ],
72
+ }
73
+ )
74
+ invoice .with_user (self .test_user_2 .id ).request_validation ()
75
+ invoice = invoice .with_user (self .test_user_1 .id )
76
+ invoice .invalidate_model ()
77
+ invoice .validate_tier ()
78
+ with self .assertRaisesRegex (
79
+ ValidationError , _ ("You are not allowed to write those fields" )
80
+ ):
81
+ invoice ._post ()
82
+ # Calls _post method by passing context skip_validation_check set to True
83
+ invoice .action_post ()
0 commit comments