summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_picking.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-11 10:02:33 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-11 10:02:33 +0700
commitc631620706a24426faea6b43c2a0602eebf9a5e4 (patch)
tree440ad54110f0cb11f9252537b58616934fc009e7 /indoteknik_custom/models/stock_picking.py
parent9c6e2e8f35f14dda376e543e5b63b0bddee2fd88 (diff)
<iman> fix code get telegram api
Diffstat (limited to 'indoteknik_custom/models/stock_picking.py')
-rw-r--r--indoteknik_custom/models/stock_picking.py37
1 files changed, 29 insertions, 8 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 58eb5d82..5f2fe99a 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -312,18 +312,39 @@ class StockPicking(models.Model):
def ask_return_approval(self):
telegram_data = {
- 'tittle': 'Permintaan retur ' + self.name,
+ 'tittle': self.name,
'about': 'Permintaan retur ' + self.name,
'id_data': self.id,
'username': '@'+self.name.replace('/', '')
}
- telegram = request.env['website.telegram'].create(telegram_data)
- for pick in self:
- if self.env.user.is_accounting:
- pick.approval_return_status = 'approved'
- else:
- pick.approval_return_status = 'pengajuan1'
- telegram.create_channel()
+ channel_data = self.env['website.telegram'].search([('tittle', '=', self.name)])
+ if channel_data:
+ for pick in self:
+ self._check_telegram(pick)
+ else:
+ telegram = request.env['website.telegram'].create(telegram_data)
+ telegram.create_channel()
+ for pick in self:
+ pick.approval_return_status = 'pengajuan1'
+
+ def read(self, fields=None, load='_classic_read'):
+ # Panggil method 'read' bawaan terlebih dahulu
+ records = super(StockPicking, self).read(fields, load)
+
+ # Jalankan _check_telegram untuk setiap record yang diakses
+ for record in self:
+ if record.approval_return_status == 'pengajuan1':
+ record._check_telegram()
+
+ return records
+
+
+ def _check_telegram(self):
+ telegram = self.env['website.telegram'].search([('id_data', '=', self.id)])
+ if telegram:
+ ask_return = telegram.receive_messages()
+ if ask_return:
+ self.approval_return_status = 'approved'
def calculate_line_no(self):
for picking in self: