diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-06-22 16:00:25 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-06-22 16:00:25 +0700 |
| commit | ae998f145e4f8b4a0939a97c02e70564ef758e73 (patch) | |
| tree | 55ca8a2c32a5b4aa1bc1094b9a9f9f7de9964e71 | |
| parent | 751a3684ebf54521daa2edc9f62fca8131c9d653 (diff) | |
Refactor get promotion by product API
| -rw-r--r-- | indoteknik_custom/models/promotion_program_line.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/indoteknik_custom/models/promotion_program_line.py b/indoteknik_custom/models/promotion_program_line.py index e6f2f0ea..3e419ef9 100644 --- a/indoteknik_custom/models/promotion_program_line.py +++ b/indoteknik_custom/models/promotion_program_line.py @@ -103,6 +103,19 @@ class PromotionProgramLine(models.Model): calculate_time = self.program_id.end_time - datetime.now() return round(calculate_time.total_seconds()) + def _res_limit_qty(self): + return { + 'all': self.limit_qty, + 'user': self.limit_qty_user, + 'transaction': self.limit_qty_transaction, + } + + def _res_promotion_type(self): + return { + 'value': self.promotion_type, + 'label': dict(self._fields['promotion_type'].selection).get(self.promotion_type) + } + def res_format(self, lines, user): ir_attachment = self.env['ir.attachment'] data = [] @@ -111,18 +124,11 @@ class PromotionProgramLine(models.Model): 'id': line.id, 'name': line.name, 'image': ir_attachment.api_image('promotion.program.line', 'image', line.id), - 'type': { - 'value': line.promotion_type, - 'label': dict(self._fields['promotion_type'].selection).get(line.promotion_type) - }, 'minimum_purchase_qty': line.minimum_purchase_qty, 'applies_multiply': line.applies_multiply, 'remaining_time': line._get_remaining_time(), - 'limit_qty': { - 'all': line.limit_qty, - 'user': line.limit_qty_user, - 'transaction': line.limit_qty_transaction, - }, + 'type': line._res_promotion_type(), + 'limit_qty': line._res_limit_qty(), 'remaining_qty': line._get_remaining_qty(user), }) return data |
