File tree 3 files changed +55
-2
lines changed
subscription_web_access/models
3 files changed +55
-2
lines changed Original file line number Diff line number Diff line change 1
1
from . import res_partner
2
+ from . import res_users
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class ResPartner(models.Model):
19
19
20
20
@api .depends (
21
21
"contract_ids.contract_line_ids.state" ,
22
- "contract_ids.contract_line_ids.price " ,
22
+ "contract_ids.contract_line_ids.price_unit " ,
23
23
)
24
24
def _compute_subscription_status (self ):
25
25
for rec in self :
@@ -30,4 +30,4 @@ def _compute_subscription_status(self):
30
30
if line .state == "in-progress" or line .state == "upcoming-close" :
31
31
rec .is_web_subscribed = True
32
32
if line .price_unit > 0 :
33
- rec .is_web_subscribed = True
33
+ rec .subscriber = True
Original file line number Diff line number Diff line change
1
+ # Copyright 2019 Coop IT Easy SCRL fs
2
+ # Robin Keunen <robin@coopiteasy.be>
3
+ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4
+ import json
5
+
6
+ from odoo import api , models
7
+ from odoo .exceptions import MissingError
8
+
9
+
10
+ class ResUsers (models .Model ):
11
+ _inherit = "res.users"
12
+
13
+ @api .model
14
+ def get_subscription (self , user_id ):
15
+ user = self .env ["res.users" ].browse (user_id )
16
+ if not user :
17
+ return json .dumps ({"error" : "user not found" })
18
+
19
+ try :
20
+ partner = user .partner_id
21
+ except MissingError :
22
+ return json .dumps (
23
+ {
24
+ "id" : user_id ,
25
+ "start" : "" ,
26
+ "end" : "" ,
27
+ "subscription" : "" ,
28
+ "subscribed" : False ,
29
+ }
30
+ )
31
+
32
+ for contract in partner .contract_ids :
33
+ for line in contract .contract_line_ids :
34
+ if line .state == "in-progress" or line .state == "upcoming-close" :
35
+ return json .dumps (
36
+ {
37
+ "id" : user_id ,
38
+ "start" : line .date_start ,
39
+ "end" : line .date_end ,
40
+ "subscription" : line .contract_id .name ,
41
+ "subscribed" : partner .is_web_subscribed ,
42
+ }
43
+ )
44
+ return json .dumps (
45
+ {
46
+ "id" : user_id ,
47
+ "start" : "" ,
48
+ "end" : "" ,
49
+ "subscription" : "" ,
50
+ "subscribed" : partner .is_web_subscribed ,
51
+ }
52
+ )
You can’t perform that action at this time.
0 commit comments