diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-21 11:06:58 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-21 11:06:58 +0700 |
| commit | da2389775171d288b96958651a45f07865a2e014 (patch) | |
| tree | fe31280f59adf1718bd8e43e542bccd846d556a9 /indoteknik_custom/models | |
| parent | 7489d3fba967e711cb0fdfd6d3cb5097751e883f (diff) | |
Update voucher use manufacture rules
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/voucher.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py index b327df6d..1cdf88c4 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,14 @@ 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') + + @api.constrains('description') + def _check_description_length(self): + for record in self: + if len(record.description) > 120: + raise ValidationError('Description cannot exceed 120 characters') def _compute_display_name(self): for voucher in self: @@ -50,6 +59,12 @@ class Voucher(models.Model): ir_attachment = self.env['ir.attachment'] discount_type = self.discount_type max_discount_amount = self.max_discount_amount if discount_type == 'percentage' else 0 + manufactures = [] + for manufacture in self.manufacture_ids: + manufactures.append({ + 'id': manufacture.id, + 'name': manufacture.x_name, + }) data = { 'id': self.id, 'image': ir_attachment.api_image('voucher', 'image', self.id), @@ -61,6 +76,7 @@ class Voucher(models.Model): 'remaining_time': self._res_remaining_time(), 'min_purchase_amount': self.min_purchase_amount, 'max_discount_amount': max_discount_amount, + 'manufactures': manufactures } return data |
