diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-02-20 16:20:25 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-02-20 16:20:25 +0700 |
| commit | 7c1c4def22a72b9a6f6806d70a865594ae14386c (patch) | |
| tree | 3ffb388cf77f1b464bc454f5e25725424964ce7c /indoteknik_api/controllers/api_v1 | |
| parent | 38f8ddd9aaaad58c8d7ea27235cd109ba288693d (diff) | |
<iman> add CR voucher type account
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/voucher.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 910488d1..9ffeeace 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -22,9 +22,14 @@ class Voucher(controller.Controller): code = kw.get('code') type = kw.get('type') user_id = int(kw.get('user_id', 0)) + partner_id = int(kw.get('partner_id', 0)) source = kw.get('source') visibility = ['public'] + user = request.env['res.users'].search([('id', '=', user_id)], limit=1) + if not user: + return self.response([]) + domain = [] if code: visibility.append('private') @@ -37,14 +42,19 @@ class Voucher(controller.Controller): type = type.split(',') domain += [('apply_type', 'in', type)] + if partner_id: + partner = request.env['res.partner'].search([('id', '=', partner_id)], limit=1) + main_parent = partner.get_main_parent() + if main_parent and main_parent.company_type: + domain += [('account_type', 'in', ['all',main_parent.company_type])] + # domain += [('account_type', 'in', main_parent.company_type)] + + domain += [('visibility', 'in', visibility)] vouchers = request.env['voucher'].get_active_voucher(domain) checkout = cart.get_user_checkout(user_id, source=source) products = checkout['products'] - user = request.env['res.users'].search([('id', '=', user_id)], limit=1) - if not user: - return self.response([]) order_line = [] for product in products: @@ -89,3 +99,9 @@ class Voucher(controller.Controller): sorted_results = sorted(results, key=lambda x: x['can_apply'], reverse=True) return self.response(sorted_results) + + def get_user_by_email(self, email): + return request.env['res.users'].search([ + ('login', '=', email), + ('active', 'in', [True, False]) + ])
\ No newline at end of file |
