summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/voucher.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-07-24 08:38:12 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-07-24 08:38:12 +0000
commitc344ccd81208b5b466ae047dbb9e084dd5d0f358 (patch)
treec07caf6a1df48719b828fbe270bb62ccc3e0c947 /indoteknik_custom/models/voucher.py
parent989002aca3ed9b1e724e9b98d8ca3513ba598663 (diff)
parent2ad6b4ecf783b5dfe0d4aa11f238cbf6aefd9747 (diff)
Merged in production (pull request #66)
Production
Diffstat (limited to 'indoteknik_custom/models/voucher.py')
-rw-r--r--indoteknik_custom/models/voucher.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py
index b327df6d..b3a55499 100644
--- a/indoteknik_custom/models/voucher.py
+++ b/indoteknik_custom/models/voucher.py
@@ -1,5 +1,6 @@
-from odoo import models, fields
+from odoo import models, fields, api
from datetime import datetime, timedelta
+from odoo.exceptions import ValidationError
class Voucher(models.Model):
@@ -37,6 +38,15 @@ class Voucher(models.Model):
min_purchase_amount = fields.Integer(string='Min. Purchase Amount', help='Nominal minimum untuk dapat menggunakan voucher. Isi 0 jika tidak ada minimum purchase amount')
max_discount_amount = fields.Integer(string='Max. Discount Amount', help='Max nominal terhadap persentase diskon')
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 record.description and len(record.description) > 120:
+ raise ValidationError('Description cannot exceed 120 characters')
def _compute_display_name(self):
for voucher in self:
@@ -61,6 +71,9 @@ class Voucher(models.Model):
'remaining_time': self._res_remaining_time(),
'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],
+ 'excl_pricelist_ids': [x.id for x in self.excl_pricelist_ids],
}
return data