summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-06-22 14:32:14 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-06-22 14:32:14 +0700
commit751a3684ebf54521daa2edc9f62fca8131c9d653 (patch)
tree5fdbeaad962e844b0b195a81e84ccb85a667a445
parent329668e82ca9e4ebd2ee93d6670380abf6ed6377 (diff)
Add type value, label and remaining_time on program
-rw-r--r--indoteknik_custom/models/promotion_program_line.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/indoteknik_custom/models/promotion_program_line.py b/indoteknik_custom/models/promotion_program_line.py
index 8d80bfb0..e6f2f0ea 100644
--- a/indoteknik_custom/models/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion_program_line.py
@@ -79,17 +79,17 @@ class PromotionProgramLine(models.Model):
('product_id', '=', product_id)
])
- def get_remaining_qty(self, line, user):
+ def _get_remaining_qty(self, user):
remaining_qty = {
- 'all': line.limit_qty,
- 'user': line.limit_qty_user,
- 'transaction': line.limit_qty_transaction
+ 'all': self.limit_qty,
+ 'user': self.limit_qty_user,
+ 'transaction': self.limit_qty_transaction
}
- for order in line.order_line_ids:
+ for order in self.order_line_ids:
parent_order = order.order_id
if parent_order.state != 'cancel':
remaining_qty['all'] -= order.product_uom_qty
- if parent_order.partner_id.id == user['partner_id']:
+ if user and parent_order.partner_id.id == user['partner_id']:
remaining_qty['user'] -= order.product_uom_qty
if remaining_qty['all'] < remaining_qty['user']:
@@ -99,6 +99,10 @@ class PromotionProgramLine(models.Model):
return remaining_qty
+ def _get_remaining_time(self):
+ calculate_time = self.program_id.end_time - datetime.now()
+ return round(calculate_time.total_seconds())
+
def res_format(self, lines, user):
ir_attachment = self.env['ir.attachment']
data = []
@@ -107,15 +111,19 @@ class PromotionProgramLine(models.Model):
'id': line.id,
'name': line.name,
'image': ir_attachment.api_image('promotion.program.line', 'image', line.id),
- 'type': line.promotion_type,
+ '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,
},
- 'remaining_qty': self.get_remaining_qty(line, user),
+ 'remaining_qty': line._get_remaining_qty(user),
})
return data