summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-02-20 16:20:25 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-02-20 16:20:25 +0700
commit7c1c4def22a72b9a6f6806d70a865594ae14386c (patch)
tree3ffb388cf77f1b464bc454f5e25725424964ce7c
parent38f8ddd9aaaad58c8d7ea27235cd109ba288693d (diff)
<iman> add CR voucher type account
-rw-r--r--indoteknik_api/controllers/api_v1/voucher.py22
-rwxr-xr-xindoteknik_custom/models/res_users.py7
-rw-r--r--indoteknik_custom/models/voucher.py6
-rwxr-xr-xindoteknik_custom/views/voucher.xml1
4 files changed, 32 insertions, 4 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
diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py
index 31b84ae3..63942bb5 100755
--- a/indoteknik_custom/models/res_users.py
+++ b/indoteknik_custom/models/res_users.py
@@ -71,6 +71,13 @@ class ResUsers(models.Model):
if not vouchers: return None
return ', '.join(x.code for x in vouchers)
return None
+
+ def get_voucher_code_switch_account(self, type):
+ if type == 'switch_account':
+ vouchers = self.env['voucher'].get_active_voucher([('account_type', 'in', ['all','company'])])
+ if not vouchers: return None
+ return ', '.join(x.code for x in vouchers)
+ return None
def check_access(self, model, mode):
assert mode in ('read', 'write', 'create', 'unlink', 'import', 'export'), 'Invalid access mode'
diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py
index 37c97338..101d4bcf 100644
--- a/indoteknik_custom/models/voucher.py
+++ b/indoteknik_custom/models/voucher.py
@@ -59,7 +59,11 @@ class Voucher(models.Model):
show_on_email = fields.Selection([
('user_activation', 'User Activation')
], 'Show on Email')
-
+ account_type = fields.Selection(string='Account Type', default="all", selection=[
+ ('all', "All Account"),
+ ('person', "Account Individu"),
+ ('company', "Account Company"),
+ ])
@api.constrains('description')
def _check_description_length(self):
for record in self:
diff --git a/indoteknik_custom/views/voucher.xml b/indoteknik_custom/views/voucher.xml
index 29d0ad4b..ae958f05 100755
--- a/indoteknik_custom/views/voucher.xml
+++ b/indoteknik_custom/views/voucher.xml
@@ -35,6 +35,7 @@
<field name="limit" required="1"/>
<field name="limit_user" required="1"/>
<field name="apply_type" required="1" />
+ <field name="account_type" required="1" />
<field name="show_on_email" />
<field name="excl_pricelist_ids" widget="many2many_tags" domain="[('id', 'in', [4, 15037, 15038, 15039, 17023, 17024, 17025, 17026,17027])]"/>
</group>