diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-21 17:03:15 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-21 17:03:15 +0700 |
| commit | bc0c9e782140d82dc2147afb4a049c37141b081a (patch) | |
| tree | b41fba25c0b28ecbb9817a11e3594f1fcb8e482d | |
| parent | c758c2c63243a01e090a7640839b2dd7ce9476be (diff) | |
Add exclude voucher pricelist API
| -rw-r--r-- | indoteknik_api/controllers/api_v1/voucher.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/voucher.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/views/voucher.xml | 1 |
3 files changed, 8 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 454961da..a6a88cad 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -18,6 +18,9 @@ class Voucher(controller.Controller): if code: visibility.append('private') parameter += [('code', '=', code)] + user_pricelist = request.env.user_pricelist + if user_pricelist: + parameter += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] parameter += [('visibility', 'in', visibility)] vouchers = request.env['voucher'].get_active_voucher(parameter) diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py index 839a5d47..b3a55499 100644 --- a/indoteknik_custom/models/voucher.py +++ b/indoteknik_custom/models/voucher.py @@ -40,11 +40,12 @@ class Voucher(models.Model): order_ids = fields.One2many('sale.order', 'voucher_id', string='Order') limit = fields.Integer(string='Limit', help='Voucher limit by sale order. Masukan 0 untuk tanpa limit') manufacture_ids = fields.Many2many('x_manufactures', string='Brands', help='Voucher appplied only for brand') + excl_pricelist_ids = fields.Many2many('product.pricelist', string='Excluded Pricelists', help='Hide voucher from selected exclude pricelist') @api.constrains('description') def _check_description_length(self): for record in self: - if len(record.description) > 120: + if record.description and len(record.description) > 120: raise ValidationError('Description cannot exceed 120 characters') def _compute_display_name(self): @@ -71,7 +72,8 @@ class Voucher(models.Model): 'min_purchase_amount': self.min_purchase_amount, 'max_discount_amount': max_discount_amount, 'manufacture_names': ", ".join([x.x_name for x in self.manufacture_ids]), - 'manufacture_ids': [x.id for x in self.manufacture_ids] + 'manufacture_ids': [x.id for x in self.manufacture_ids], + 'excl_pricelist_ids': [x.id for x in self.excl_pricelist_ids], } return data diff --git a/indoteknik_custom/views/voucher.xml b/indoteknik_custom/views/voucher.xml index d79e73f6..c6741a8d 100755 --- a/indoteknik_custom/views/voucher.xml +++ b/indoteknik_custom/views/voucher.xml @@ -59,6 +59,7 @@ <field name="end_time" required="1"/> <field name="limit" required="1"/> <field name="manufacture_ids" widget="many2many_tags"/> + <field name="excl_pricelist_ids" widget="many2many_tags"/> </group> </group> <notebook> |
