From cc862f2bb8a6a751612bab7fb2d07f7306f9a4fd Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 4 Oct 2024 12:28:29 +0700 Subject: add telegram --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/website_telegram.py | 63 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 indoteknik_custom/models/website_telegram.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 3d700ce0..1620c82e 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -128,3 +128,4 @@ from . import sales_order_reject from . import approval_date_doc from . import account_tax from . import approval_unreserve +from . import website_telegram diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py new file mode 100644 index 00000000..8fc6a8ea --- /dev/null +++ b/indoteknik_custom/models/website_telegram.py @@ -0,0 +1,63 @@ +import requests + +import clipboard + +from odoo import models, fields, api + +class WebsiteTelegram(models.Model): + _name = 'website.telegram' + _description = 'Telegram Channel' + + name = fields.Char(string='Bot Name', required=True) + bot_name = fields.Char(string='Bot Token', help="Create your bot from Bot Father form Telegram App", required=True, ) + python_code = fields.Char(compute="_calc_python_code") + chatID = fields.Char(string='Channel Name', required=True, help="Create yor channel , Add members , Add Bot As an Admin") + + test_message = fields.Char(string='Test Message', required=False, default='Test') + + def send_to_telegram(self, message): + # if self.env.all.registry.db_name == 'odoo016':return + + # message = self.env.all.registry.db_name + " : " + message + message = self.test_message + + apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage' + try: + requests.post(apiURL, json={'chat_id': self.chatID, 'text': message}) + except Exception as e: + print(e) + + def test_send(self): + try: + self.env.cr.savepoint() + + self.env['website.telegram'].search([('name', '=', self.name)])[0].send_to_telegram(self.test_message) + except Exception as e: + print(e) + + @api.depends('name', 'chatID', 'bot_name') + def _calc_python_code(self): + for record in self: + if not record.name: + record.python_code = "pleas put a name" + elif not record.test_message: + record.test_message = "test" + else: + record.python_code = "self.env['website.telegram'].search([('name', '=', '" + record.name + "')])[0].send_to_telegram('" + record.test_message + "')" + + def copy_chat_id(self): + record = self.browse(self.id) + clipboard.copy(record.python_code) + + def paste_chat_id(self): + record = self.browse(self.id) + chat_id = clipboard.paste() + record.write({'chatID': chat_id}) + + def paste_bot_name(self): + record = self.browse(self.id) + bot_name = clipboard.paste() + record.write({'bot_name': bot_name}) + + + -- cgit v1.2.3 From ec1e2331be248a505d89c00244d6b0fe5bd61c26 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 4 Oct 2024 14:31:33 +0700 Subject: add get text from channel --- indoteknik_custom/models/website_telegram.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 8fc6a8ea..bb3031a0 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -29,7 +29,7 @@ class WebsiteTelegram(models.Model): def test_send(self): try: - self.env.cr.savepoint() + self.env.cr.savepoint() #kembalikan database ke save point jika mengalami kesalahan self.env['website.telegram'].search([('name', '=', self.name)])[0].send_to_telegram(self.test_message) except Exception as e: @@ -59,5 +59,24 @@ class WebsiteTelegram(models.Model): bot_name = clipboard.paste() record.write({'bot_name': bot_name}) + def get_updates(self): + apiURL = f'https://api.telegram.org/bot{self.bot_name}/getUpdates' + try: + response = requests.get(apiURL) + updates = response.json() + return updates # Ini akan berisi semua pembaruan, termasuk pesan baru + except Exception as e: + print(e) + return None + + def receive_messages(self): + updates = self.get_updates() + if updates and 'result' in updates: + for update in updates['result']: + if 'text' in update['channel_post']: + message_text = update['channel_post']['text'] + chat_id = update['channel_post']['chat']['id'] + chat_name = update['channel_post']['chat']['username'] + print(f"Received message: {message_text} from chat_id: {chat_id}, that is: {chat_name}") -- cgit v1.2.3 From 04d994e53a36ea9a6f7a2c0dd3f5f1b2c0ca9a74 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 8 Oct 2024 15:37:58 +0700 Subject: update code --- indoteknik_custom/models/website_telegram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index bb3031a0..5684eff8 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -19,7 +19,7 @@ class WebsiteTelegram(models.Model): # if self.env.all.registry.db_name == 'odoo016':return # message = self.env.all.registry.db_name + " : " + message - message = self.test_message + # message = self.test_message apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage' try: -- cgit v1.2.3 From 94141d0871e9abed968d3c249eeaf7b3c1ae87d9 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 9 Oct 2024 15:59:34 +0700 Subject: update telegram create channel --- indoteknik_custom/models/stock_picking.py | 7 +++++ indoteknik_custom/models/website_telegram.py | 39 +++++++++++++++++++++------- 2 files changed, 37 insertions(+), 9 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 14190474..5397b59f 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -4,6 +4,7 @@ from odoo.tools.float_utils import float_is_zero from datetime import datetime from itertools import groupby import pytz, datetime +from odoo.http import request class StockPicking(models.Model): @@ -310,11 +311,17 @@ class StockPicking(models.Model): self.approval_receipt_status = 'pengajuan1' def ask_return_approval(self): + telegram_data = { + 'tittle': 'Permintaan retur ' + self.name, + 'about': 'Permintaan retur ' + self.name, + } + 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() def calculate_line_no(self): for picking in self: diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 5684eff8..c0e7be2f 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -1,19 +1,40 @@ import requests - import clipboard - from odoo import models, fields, api +from telethon.sessions import StringSession +from telethon.sync import TelegramClient +from telethon import functions, types +from telethon.tl.types import InputChannel, InputPeerChannel +import asyncio class WebsiteTelegram(models.Model): _name = 'website.telegram' _description = 'Telegram Channel' - - name = fields.Char(string='Bot Name', required=True) - bot_name = fields.Char(string='Bot Token', help="Create your bot from Bot Father form Telegram App", required=True, ) - python_code = fields.Char(compute="_calc_python_code") - chatID = fields.Char(string='Channel Name', required=True, help="Create yor channel , Add members , Add Bot As an Admin") - - test_message = fields.Char(string='Test Message', required=False, default='Test') + tittle = fields.Char("Channel Title") + about = fields.Char("Channel Description") + is_broadcast = fields.Boolean("Is Broadcast", default=True) + is_megagroup = fields.Boolean("Is Megagroup", default=False) + # session_string = 'MIIBCgKCAQEAyMEdY1aR+sCR3ZSJrtztKTKqigvO/vBfqACJLZtS7QMgCGXJ6XIRyy7mx66W0/sOFa7/1mAZtEoIokDP3ShoqF4fVNb6XeqgQfaUHd8wJpDWHcR2OFwvplUUI1PLTktZ9uW2WE23b+ixNwJjJGwBDJPQEQFBE+vfmH0JP503wr5INS1poWg/j25sIWeYPHYeOrFp/eXaqhISP6G+q2IeTaWTXpwZj4LzXq5YOpk4bYEQ6mvRq7D1aHWfYmlEGepfaYR8Q0YqvvhYtMte3ITnuSJs171+GDqpdKcSwHnd6FudwGO4pcCOj4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB' + + def create_channel(self, *args, **kwargs): + asyncio.run(self._async_create_channel()) + + async def _async_create_channel(self): + async with TelegramClient(StringSession('1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client: + result = await client(functions.channels.CreateChannelRequest( + title=self.tittle, + about=self.about, + broadcast=True, + megagroup=False, + )) + channel = result.updates[3].message.peer_id + username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] + for name in username_to_add: + user_to_add = await client.get_entity(name) + result = await client(functions.channels.InviteToChannelRequest( + channel=channel, + users=[user_to_add.id], + )) def send_to_telegram(self, message): # if self.env.all.registry.db_name == 'odoo016':return -- cgit v1.2.3 From dcbb5680c9dd6ecf18eaf3dbbc3af26ac7a47134 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 9 Oct 2024 17:00:18 +0700 Subject: update bisa kirim chat --- indoteknik_custom/models/stock_picking.py | 1 + indoteknik_custom/models/website_telegram.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 5397b59f..b65d06e4 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -314,6 +314,7 @@ class StockPicking(models.Model): telegram_data = { 'tittle': 'Permintaan retur ' + self.name, 'about': 'Permintaan retur ' + self.name, + 'id_data': self.id } telegram = request.env['website.telegram'].create(telegram_data) for pick in self: diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index c0e7be2f..45927b73 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -6,11 +6,13 @@ from telethon.sync import TelegramClient from telethon import functions, types from telethon.tl.types import InputChannel, InputPeerChannel import asyncio +from telethon.tl.functions.messages import SendMessageRequest class WebsiteTelegram(models.Model): _name = 'website.telegram' _description = 'Telegram Channel' tittle = fields.Char("Channel Title") + id_data = fields.Char("Channel ID") about = fields.Char("Channel Description") is_broadcast = fields.Boolean("Is Broadcast", default=True) is_megagroup = fields.Boolean("Is Megagroup", default=False) @@ -24,8 +26,8 @@ class WebsiteTelegram(models.Model): result = await client(functions.channels.CreateChannelRequest( title=self.tittle, about=self.about, - broadcast=True, - megagroup=False, + broadcast=False, + megagroup=True, )) channel = result.updates[3].message.peer_id username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] @@ -35,6 +37,8 @@ class WebsiteTelegram(models.Model): channel=channel, users=[user_to_add.id], )) + message = 'https://erp.indoteknik.com/web#id='+self.id_data+'&action=209&model=stock.picking&view_type=form&cids=1&menu_id=101' + result = await client(SendMessageRequest(channel, message)) def send_to_telegram(self, message): # if self.env.all.registry.db_name == 'odoo016':return -- cgit v1.2.3 From 9c6e2e8f35f14dda376e543e5b63b0bddee2fd88 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 10 Oct 2024 08:53:39 +0700 Subject: update telegram --- indoteknik_custom/models/stock_picking.py | 3 +- indoteknik_custom/models/website_telegram.py | 41 +++++++++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index b65d06e4..58eb5d82 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -314,7 +314,8 @@ class StockPicking(models.Model): telegram_data = { 'tittle': 'Permintaan retur ' + self.name, 'about': 'Permintaan retur ' + self.name, - 'id_data': self.id + 'id_data': self.id, + 'username': '@'+self.name.replace('/', '') } telegram = request.env['website.telegram'].create(telegram_data) for pick in self: diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 45927b73..d67cafc5 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -12,6 +12,7 @@ class WebsiteTelegram(models.Model): _name = 'website.telegram' _description = 'Telegram Channel' tittle = fields.Char("Channel Title") + username = fields.Char("Channel Name") id_data = fields.Char("Channel ID") about = fields.Char("Channel Description") is_broadcast = fields.Boolean("Is Broadcast", default=True) @@ -30,7 +31,8 @@ class WebsiteTelegram(models.Model): megagroup=True, )) channel = result.updates[3].message.peer_id - username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] + # username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] + username_to_add = ['@imsep81'] for name in username_to_add: user_to_add = await client.get_entity(name) result = await client(functions.channels.InviteToChannelRequest( @@ -40,6 +42,24 @@ class WebsiteTelegram(models.Model): message = 'https://erp.indoteknik.com/web#id='+self.id_data+'&action=209&model=stock.picking&view_type=form&cids=1&menu_id=101' result = await client(SendMessageRequest(channel, message)) + result = client(functions.channels.UpdateUsernameRequest( + channel=channel, + username='@indoJaya21' + )) + print(result.stringify()) + + def receive_messages(self): + asyncio.run(self._async_receive_messages()) + + async def _async_receive_messages(self): + async with TelegramClient(StringSession('1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), + 27799517, 'df8ee44b0ed11108245037d47b511201') as client: + channel = await client.get_entity(self.username) + result = client(functions.channels.GetMessagesRequest( + channel=channel, + id=channel.chats + )) + print(result.stringify()) def send_to_telegram(self, message): # if self.env.all.registry.db_name == 'odoo016':return @@ -94,14 +114,15 @@ class WebsiteTelegram(models.Model): print(e) return None - def receive_messages(self): - updates = self.get_updates() - if updates and 'result' in updates: - for update in updates['result']: - if 'text' in update['channel_post']: - message_text = update['channel_post']['text'] - chat_id = update['channel_post']['chat']['id'] - chat_name = update['channel_post']['chat']['username'] - print(f"Received message: {message_text} from chat_id: {chat_id}, that is: {chat_name}") + # def receive_messages(self): + # updates = self.get_updates() + # if updates and 'result' in updates: + # for update in updates['result']: + # if 'text' in update['channel_post']: + # message_text = update['channel_post']['text'] + # chat_id = update['channel_post']['chat']['id'] + # chat_name = update['channel_post']['chat']['username'] + # print(f"Received message: {message_text} from chat_id: {chat_id}, that is: {chat_name}") + -- cgit v1.2.3 From c631620706a24426faea6b43c2a0602eebf9a5e4 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 11 Oct 2024 10:02:33 +0700 Subject: fix code get telegram api --- indoteknik_custom/models/stock_picking.py | 37 ++++++++--- indoteknik_custom/models/website_telegram.py | 92 +++++++++++++++++++--------- 2 files changed, 91 insertions(+), 38 deletions(-) (limited to 'indoteknik_custom/models') 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: diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index d67cafc5..8bd789a1 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -4,68 +4,103 @@ from odoo import models, fields, api from telethon.sessions import StringSession from telethon.sync import TelegramClient from telethon import functions, types -from telethon.tl.types import InputChannel, InputPeerChannel +from telethon.tl.types import InputPeerChannel import asyncio from telethon.tl.functions.messages import SendMessageRequest +from telethon.tl.types import InputMediaPoll, Poll, PollAnswer, PeerChannel +import datetime +from telethon.tl.types import MessageMediaPoll +from telethon.tl.functions.messages import SendMediaRequest +from telethon.tl.types import TextWithEntities class WebsiteTelegram(models.Model): _name = 'website.telegram' _description = 'Telegram Channel' tittle = fields.Char("Channel Title") + invite_link = fields.Char("Channel invite link") username = fields.Char("Channel Name") id_data = fields.Char("Channel ID") about = fields.Char("Channel Description") is_broadcast = fields.Boolean("Is Broadcast", default=True) is_megagroup = fields.Boolean("Is Megagroup", default=False) + is_accept = fields.Boolean("Is Megagroup", default=False) + # session_string = 'MIIBCgKCAQEAyMEdY1aR+sCR3ZSJrtztKTKqigvO/vBfqACJLZtS7QMgCGXJ6XIRyy7mx66W0/sOFa7/1mAZtEoIokDP3ShoqF4fVNb6XeqgQfaUHd8wJpDWHcR2OFwvplUUI1PLTktZ9uW2WE23b+ixNwJjJGwBDJPQEQFBE+vfmH0JP503wr5INS1poWg/j25sIWeYPHYeOrFp/eXaqhISP6G+q2IeTaWTXpwZj4LzXq5YOpk4bYEQ6mvRq7D1aHWfYmlEGepfaYR8Q0YqvvhYtMte3ITnuSJs171+GDqpdKcSwHnd6FudwGO4pcCOj4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB' def create_channel(self, *args, **kwargs): asyncio.run(self._async_create_channel()) async def _async_create_channel(self): - async with TelegramClient(StringSession('1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client: + async with TelegramClient(StringSession( + '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), + 27799517, 'df8ee44b0ed11108245037d47b511201') as client: result = await client(functions.channels.CreateChannelRequest( - title=self.tittle, + title='Permintaan retur ' + self.tittle, about=self.about, broadcast=False, megagroup=True, )) channel = result.updates[3].message.peer_id - # username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] - username_to_add = ['@imsep81'] + channel_link = await client(functions.messages.ExportChatInviteRequest( + peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), + )) + self.invite_link = channel_link.link + username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] + # username_to_add = ['@imsep81'] for name in username_to_add: user_to_add = await client.get_entity(name) - result = await client(functions.channels.InviteToChannelRequest( + result_add_user = await client(functions.channels.InviteToChannelRequest( channel=channel, users=[user_to_add.id], )) - message = 'https://erp.indoteknik.com/web#id='+self.id_data+'&action=209&model=stock.picking&view_type=form&cids=1&menu_id=101' - result = await client(SendMessageRequest(channel, message)) - - result = client(functions.channels.UpdateUsernameRequest( - channel=channel, - username='@indoJaya21' + message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=stock.picking&view_type=form&cids=1&menu_id=101' + result_massage = await client(SendMessageRequest(channel, message)) + + # Send the poll to the channel using PeerChannel with the channel's ID + result_polling = await client(SendMediaRequest( + peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), + media=InputMediaPoll(poll=Poll( + question=TextWithEntities(text="ASK RETURN?", entities=[]), + answers=[ + PollAnswer(text=TextWithEntities(text="Accept", entities=[]), option=b'\x01'), + PollAnswer(text=TextWithEntities(text="Reject", entities=[]), option=b'\x02'), + ], + id=2 + )), + message='Ask Return Polling' )) - print(result.stringify()) def receive_messages(self): - asyncio.run(self._async_receive_messages()) + return asyncio.run(self._async_receive_messages()) async def _async_receive_messages(self): - async with TelegramClient(StringSession('1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), - 27799517, 'df8ee44b0ed11108245037d47b511201') as client: - channel = await client.get_entity(self.username) - result = client(functions.channels.GetMessagesRequest( - channel=channel, - id=channel.chats + async with TelegramClient(StringSession( + '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), + 27799517, 'df8ee44b0ed11108245037d47b511201') as client: + channel = await client.get_entity(self.invite_link) + result = await client(functions.messages.GetHistoryRequest( + peer=channel, + offset_id=42, + offset_date=datetime.datetime(2024, 12, 31), + add_offset=0, + limit=100, + max_id=0, + min_id=0, + hash=channel.access_hash )) - print(result.stringify()) - def send_to_telegram(self, message): - # if self.env.all.registry.db_name == 'odoo016':return + accept_found = False + + for message in result.messages: + if not isinstance(message.media, MessageMediaPoll): + continue + if message.media.results.total_voters > 0: + if message.media.results.results[0].voters > message.media.results.results[1].voters: + accept_found = True + break - # message = self.env.all.registry.db_name + " : " + message - # message = self.test_message + return accept_found + def send_to_telegram(self, message): apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage' try: requests.post(apiURL, json={'chat_id': self.chatID, 'text': message}) @@ -74,7 +109,7 @@ class WebsiteTelegram(models.Model): def test_send(self): try: - self.env.cr.savepoint() #kembalikan database ke save point jika mengalami kesalahan + self.env.cr.savepoint() self.env['website.telegram'].search([('name', '=', self.name)])[0].send_to_telegram(self.test_message) except Exception as e: @@ -109,7 +144,7 @@ class WebsiteTelegram(models.Model): try: response = requests.get(apiURL) updates = response.json() - return updates # Ini akan berisi semua pembaruan, termasuk pesan baru + return updates except Exception as e: print(e) return None @@ -123,6 +158,3 @@ class WebsiteTelegram(models.Model): # chat_id = update['channel_post']['chat']['id'] # chat_name = update['channel_post']['chat']['username'] # print(f"Received message: {message_text} from chat_id: {chat_id}, that is: {chat_name}") - - - -- cgit v1.2.3 From 6ad0aa164ed76c8889fd76bff99f5d57b1ac1b2e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 4 Dec 2024 15:31:54 +0700 Subject: add telegram --- indoteknik_custom/models/sale_order.py | 14 ++++++++++++++ indoteknik_custom/models/website_telegram.py | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 7fc6d96a..88bbe3cf 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -145,6 +145,20 @@ class SaleOrder(models.Model): ('NP', 'Non Pareto') ]) + def action_print_proforma_invoice(self): + """Cetak laporan Jasper secara langsung""" + self.ensure_one() + # Konfigurasi laporan Jasper + report_action = self.env['ir.actions.report'].search([ + ('model', '=', 'sale.order'), + ('report_name', '=', 'Proforma Invoice New') + ], limit=1) + + if report_action: + return report_action.report_action(self) + else: + raise ValueError('Report not found!') + @api.onchange('payment_status') def _is_continue_transaction(self): if not self.is_continue_transaction: diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 8bd789a1..e17da371 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -45,8 +45,8 @@ class WebsiteTelegram(models.Model): peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), )) self.invite_link = channel_link.link - username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] - # username_to_add = ['@imsep81'] + # username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] + username_to_add = ['@imsep81'] for name in username_to_add: user_to_add = await client.get_entity(name) result_add_user = await client(functions.channels.InviteToChannelRequest( -- cgit v1.2.3 From bab6a911535b771e988093725e0ba378c77297c6 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 10 Dec 2024 08:58:25 +0700 Subject: update telegram --- indoteknik_custom/models/sale_order.py | 14 -------------- indoteknik_custom/models/website_telegram.py | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 88bbe3cf..7fc6d96a 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -145,20 +145,6 @@ class SaleOrder(models.Model): ('NP', 'Non Pareto') ]) - def action_print_proforma_invoice(self): - """Cetak laporan Jasper secara langsung""" - self.ensure_one() - # Konfigurasi laporan Jasper - report_action = self.env['ir.actions.report'].search([ - ('model', '=', 'sale.order'), - ('report_name', '=', 'Proforma Invoice New') - ], limit=1) - - if report_action: - return report_action.report_action(self) - else: - raise ValueError('Report not found!') - @api.onchange('payment_status') def _is_continue_transaction(self): if not self.is_continue_transaction: diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index e17da371..58816fe2 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -46,7 +46,7 @@ class WebsiteTelegram(models.Model): )) self.invite_link = channel_link.link # username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] - username_to_add = ['@imsep81'] + username_to_add = ['@radiant81'] for name in username_to_add: user_to_add = await client.get_entity(name) result_add_user = await client(functions.channels.InviteToChannelRequest( -- cgit v1.2.3 From 1bf746c93dc5010e30490d0a5ed6a2a174726be0 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 10 Dec 2024 13:21:14 +0700 Subject: update code telegram print so when amount > 200jt --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/ir_actions_report.py | 29 ++++++++++++++++++ indoteknik_custom/models/stock_picking.py | 34 --------------------- indoteknik_custom/models/website_telegram.py | 43 ++++++++++++++++----------- 4 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 indoteknik_custom/models/ir_actions_report.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 1e0cedc9..b319883c 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -135,3 +135,4 @@ from . import find_page from . import approval_retur_picking from . import va_multi_approve from . import va_multi_reject +from . import ir_actions_report diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py new file mode 100644 index 00000000..d620f8a7 --- /dev/null +++ b/indoteknik_custom/models/ir_actions_report.py @@ -0,0 +1,29 @@ +from odoo import models +import requests +class IrActionsReport(models.Model): + _inherit = 'ir.actions.report' + + def _get_readable_fields(self): + self.send_to_telegram() + return super()._get_readable_fields() + + def send_to_telegram(self): + so_id = self.env.context.get('active_id') + if so_id: + sale_order = self.env['sale.order'].browse(so_id) + if sale_order.amount_total < 200000000: + return + telegram_data = { + 'tittle': sale_order.name, + 'about': 'Permintaan retur ' + sale_order.name, + 'id_data': sale_order.id, + 'username': '@' + sale_order.name.replace('/', '') + } + channel_data = self.env['website.telegram'].search([('tittle', '=', sale_order.name)]) + if channel_data: + channel_data.send_to_telegram(sale_order.name + " Telah di print") + for pick in self: + self._check_telegram(pick) + else: + telegram = self.env['website.telegram'].create(telegram_data) + telegram.create_channel() diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 2095e957..31c45531 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -468,40 +468,6 @@ class StockPicking(models.Model): raise UserError('Harus Sales Admin yang Ask Return') else: raise UserError('Harus Purchasing yang Ask Return') - telegram_data = { - 'tittle': self.name, - 'about': 'Permintaan retur ' + self.name, - 'id_data': self.id, - 'username': '@'+self.name.replace('/', '') - } - 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): diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 58816fe2..92707ea2 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -35,7 +35,7 @@ class WebsiteTelegram(models.Model): '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client: result = await client(functions.channels.CreateChannelRequest( - title='Permintaan retur ' + self.tittle, + title=self.tittle + ' Telah Diprint', about=self.about, broadcast=False, megagroup=True, @@ -45,30 +45,30 @@ class WebsiteTelegram(models.Model): peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), )) self.invite_link = channel_link.link - # username_to_add = ['@imsep81', '6285764475716', '@stephanchrst'] - username_to_add = ['@radiant81'] + # username_to_add = ['@radiant81', '6285764475716', '@stephanchrst'] + username_to_add = ['6282339129611'] for name in username_to_add: user_to_add = await client.get_entity(name) result_add_user = await client(functions.channels.InviteToChannelRequest( channel=channel, users=[user_to_add.id], )) - message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=stock.picking&view_type=form&cids=1&menu_id=101' + message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101' result_massage = await client(SendMessageRequest(channel, message)) # Send the poll to the channel using PeerChannel with the channel's ID - result_polling = await client(SendMediaRequest( - peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), - media=InputMediaPoll(poll=Poll( - question=TextWithEntities(text="ASK RETURN?", entities=[]), - answers=[ - PollAnswer(text=TextWithEntities(text="Accept", entities=[]), option=b'\x01'), - PollAnswer(text=TextWithEntities(text="Reject", entities=[]), option=b'\x02'), - ], - id=2 - )), - message='Ask Return Polling' - )) + # result_polling = await client(SendMediaRequest( + # peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), + # media=InputMediaPoll(poll=Poll( + # question=TextWithEntities(text="ASK RETURN?", entities=[]), + # answers=[ + # PollAnswer(text=TextWithEntities(text="Accept", entities=[]), option=b'\x01'), + # PollAnswer(text=TextWithEntities(text="Reject", entities=[]), option=b'\x02'), + # ], + # id=2 + # )), + # message='Ask Return Polling' + # )) def receive_messages(self): return asyncio.run(self._async_receive_messages()) @@ -101,12 +101,19 @@ class WebsiteTelegram(models.Model): return accept_found def send_to_telegram(self, message): - apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage' + # apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage' try: - requests.post(apiURL, json={'chat_id': self.chatID, 'text': message}) + # requests.post(apiURL, json={'chat_id': self.chatID, 'text': message}) + asyncio.run(self._async_send_to_telegram(message)) except Exception as e: print(e) + async def _async_send_to_telegram(self, message): + async with TelegramClient(StringSession( + '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), + 27799517, 'df8ee44b0ed11108245037d47b511201') as client: + channel = await client.get_entity(self.invite_link) + result_massage = await client(SendMessageRequest(channel, message)) def test_send(self): try: self.env.cr.savepoint() -- cgit v1.2.3 From e81db305d2727e7b95f1bb579315da1597a8185b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 14 Dec 2024 09:47:33 +0700 Subject: update send message to telegram --- indoteknik_custom/models/ir_actions_report.py | 4 ++-- indoteknik_custom/models/website_telegram.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index d620f8a7..286c3a3d 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -15,13 +15,13 @@ class IrActionsReport(models.Model): return telegram_data = { 'tittle': sale_order.name, - 'about': 'Permintaan retur ' + sale_order.name, + 'about': sale_order.name + ' Telah Di Print', 'id_data': sale_order.id, 'username': '@' + sale_order.name.replace('/', '') } channel_data = self.env['website.telegram'].search([('tittle', '=', sale_order.name)]) if channel_data: - channel_data.send_to_telegram(sale_order.name + " Telah di print") + channel_data.send_to_telegram(sale_order.name + " Telah di print Oleh " + self.env.user.name) for pick in self: self._check_telegram(pick) else: diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 92707ea2..25dea14e 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -54,7 +54,9 @@ class WebsiteTelegram(models.Model): users=[user_to_add.id], )) message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101' + message2 = self.tittle + ' di print oleh ' + self.env.user.name result_massage = await client(SendMessageRequest(channel, message)) + result_massage2 = await client(SendMessageRequest(channel, message2)) # Send the poll to the channel using PeerChannel with the channel's ID # result_polling = await client(SendMediaRequest( -- cgit v1.2.3 From 05d8edef111df1f32be76f3fdfaabfb1c8057644 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 16 Dec 2024 15:05:10 +0700 Subject: update telegram --- indoteknik_custom/models/ir_actions_report.py | 2 +- indoteknik_custom/models/website_telegram.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index 286c3a3d..f6ef4e3e 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -15,7 +15,7 @@ class IrActionsReport(models.Model): return telegram_data = { 'tittle': sale_order.name, - 'about': sale_order.name + ' Telah Di Print', + 'about': sale_order.name, 'id_data': sale_order.id, 'username': '@' + sale_order.name.replace('/', '') } diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 25dea14e..a3c64c7e 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -16,9 +16,13 @@ from telethon.tl.types import TextWithEntities class WebsiteTelegram(models.Model): _name = 'website.telegram' _description = 'Telegram Channel' + + tittle = fields.Char("Channel Title") invite_link = fields.Char("Channel invite link") username = fields.Char("Channel Name") + username_to_add = fields.Char("username to add on channel", compute='_compute_username_to_add') + user_id = fields.Many2many('res.partner', string='User Member', store=True) id_data = fields.Char("Channel ID") about = fields.Char("Channel Description") is_broadcast = fields.Boolean("Is Broadcast", default=True) @@ -27,6 +31,11 @@ class WebsiteTelegram(models.Model): # session_string = 'MIIBCgKCAQEAyMEdY1aR+sCR3ZSJrtztKTKqigvO/vBfqACJLZtS7QMgCGXJ6XIRyy7mx66W0/sOFa7/1mAZtEoIokDP3ShoqF4fVNb6XeqgQfaUHd8wJpDWHcR2OFwvplUUI1PLTktZ9uW2WE23b+ixNwJjJGwBDJPQEQFBE+vfmH0JP503wr5INS1poWg/j25sIWeYPHYeOrFp/eXaqhISP6G+q2IeTaWTXpwZj4LzXq5YOpk4bYEQ6mvRq7D1aHWfYmlEGepfaYR8Q0YqvvhYtMte3ITnuSJs171+GDqpdKcSwHnd6FudwGO4pcCOj4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB' + @api.depends('user_id') + def _compute_username_to_add(self): + for name in self.user_id: + self.username_to_add.append(str(name.mobile)) + def create_channel(self, *args, **kwargs): asyncio.run(self._async_create_channel()) @@ -35,7 +44,7 @@ class WebsiteTelegram(models.Model): '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client: result = await client(functions.channels.CreateChannelRequest( - title=self.tittle + ' Telah Diprint', + title=self.tittle, about=self.about, broadcast=False, megagroup=True, @@ -115,12 +124,21 @@ class WebsiteTelegram(models.Model): '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client: channel = await client.get_entity(self.invite_link) + + for name in self.username_to_add: + data = name + user_to_add = await client.get_entity(data) + result_add_user = await client(functions.channels.InviteToChannelRequest( + channel=channel, + users=[user_to_add.id], + )) result_massage = await client(SendMessageRequest(channel, message)) + def test_send(self): try: self.env.cr.savepoint() - self.env['website.telegram'].search([('name', '=', self.name)])[0].send_to_telegram(self.test_message) + self.env['website.telegram'].search([('tittle', '=', self.tittle)])[0].send_to_telegram('test message') except Exception as e: print(e) -- cgit v1.2.3 From 9ba922eded6d752c2a4299c9c444238309877bb9 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 20 Dec 2024 09:39:47 +0700 Subject: update code --- indoteknik_custom/models/ir_actions_report.py | 1 + indoteknik_custom/models/website_telegram.py | 38 ++++++++++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index f6ef4e3e..b7d4e372 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -16,6 +16,7 @@ class IrActionsReport(models.Model): telegram_data = { 'tittle': sale_order.name, 'about': sale_order.name, + 'user_id': sale_order, 'id_data': sale_order.id, 'username': '@' + sale_order.name.replace('/', '') } diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index a3c64c7e..ade6c326 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -33,8 +33,13 @@ class WebsiteTelegram(models.Model): @api.depends('user_id') def _compute_username_to_add(self): - for name in self.user_id: - self.username_to_add.append(str(name.mobile)) + for record in self: + usernames = [] + for partner in record.user_id: + if partner.mobile: # Pastikan mobile tidak None + usernames.append(partner.mobile) + # Gabungkan semua nomor menjadi satu string, dipisahkan koma + record.username_to_add = ', '.join(usernames) def create_channel(self, *args, **kwargs): asyncio.run(self._async_create_channel()) @@ -125,14 +130,27 @@ class WebsiteTelegram(models.Model): 27799517, 'df8ee44b0ed11108245037d47b511201') as client: channel = await client.get_entity(self.invite_link) - for name in self.username_to_add: - data = name - user_to_add = await client.get_entity(data) - result_add_user = await client(functions.channels.InviteToChannelRequest( - channel=channel, - users=[user_to_add.id], - )) - result_massage = await client(SendMessageRequest(channel, message)) + # Memproses username_to_add menjadi list + usernames = self.username_to_add.split(', ') # Pisahkan berdasarkan koma dan spasi + + # Iterasi untuk setiap username + for username in usernames: + if username: # Pastikan username tidak kosong + try: + # Mendapatkan entitas user berdasarkan username + user_to_add = await client.get_entity(username) + + # Mengundang user ke channel + result_add_user = await client(functions.channels.InviteToChannelRequest( + channel=channel, + users=[user_to_add.id], + )) + except Exception as e: + # Tangani error (misal user tidak ditemukan atau sudah ada di channel) + print(f"Error adding user {username}: {e}") + + # Mengirim pesan ke channel + result_message = await client(SendMessageRequest(channel, message)) def test_send(self): try: -- cgit v1.2.3 From b4a8de6bd7ca7051eee16f877b4e5d8fd65e3056 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 20 Dec 2024 13:57:52 +0700 Subject: add telegram --- indoteknik_custom/models/ir_actions_report.py | 6 ++++-- indoteknik_custom/models/res_partner.py | 1 + indoteknik_custom/models/website_telegram.py | 26 ++++++++++---------------- 3 files changed, 15 insertions(+), 18 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index b7d4e372..7b1dcee8 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -1,5 +1,5 @@ from odoo import models -import requests +from odoo.http import request class IrActionsReport(models.Model): _inherit = 'ir.actions.report' @@ -13,10 +13,12 @@ class IrActionsReport(models.Model): sale_order = self.env['sale.order'].browse(so_id) if sale_order.amount_total < 200000000: return + # id ci vita 79160 + partner = request.env['res.partner'].search([('id', '=', 112718)], limit=1) telegram_data = { 'tittle': sale_order.name, 'about': sale_order.name, - 'user_id': sale_order, + 'user_id': partner, 'id_data': sale_order.id, 'username': '@' + sale_order.name.replace('/', '') } diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index da4a6cb6..c648c729 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -74,6 +74,7 @@ class ResPartner(models.Model): "customer is crossed blocking amount." "Set its value to 0.00 to disable " "this feature", tracking=3) + telegram_id = fields.Char(string="Telegram") @api.model def _default_payment_term(self): diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index ade6c326..7d76f27d 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -36,7 +36,7 @@ class WebsiteTelegram(models.Model): for record in self: usernames = [] for partner in record.user_id: - if partner.mobile: # Pastikan mobile tidak None + if partner.telegram_id: # Pastikan mobile tidak None usernames.append(partner.mobile) # Gabungkan semua nomor menjadi satu string, dipisahkan koma record.username_to_add = ', '.join(usernames) @@ -59,15 +59,16 @@ class WebsiteTelegram(models.Model): peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), )) self.invite_link = channel_link.link - # username_to_add = ['@radiant81', '6285764475716', '@stephanchrst'] - username_to_add = ['6282339129611'] - for name in username_to_add: - user_to_add = await client.get_entity(name) + + # Iterasi untuk setiap username + for name in self.user_id: + user_to_add = await client.get_entity(name.telegram_id) result_add_user = await client(functions.channels.InviteToChannelRequest( channel=channel, users=[user_to_add.id], )) - message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101' + # message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101' + message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=357&model=sale.order&view_type=form&cids=1&menu_id=212' message2 = self.tittle + ' di print oleh ' + self.env.user.name result_massage = await client(SendMessageRequest(channel, message)) result_massage2 = await client(SendMessageRequest(channel, message2)) @@ -130,26 +131,19 @@ class WebsiteTelegram(models.Model): 27799517, 'df8ee44b0ed11108245037d47b511201') as client: channel = await client.get_entity(self.invite_link) - # Memproses username_to_add menjadi list - usernames = self.username_to_add.split(', ') # Pisahkan berdasarkan koma dan spasi - # Iterasi untuk setiap username - for username in usernames: - if username: # Pastikan username tidak kosong + for username in self.user_id: + if username: try: - # Mendapatkan entitas user berdasarkan username - user_to_add = await client.get_entity(username) + user_to_add = await client.get_entity(username.telegram_id) - # Mengundang user ke channel result_add_user = await client(functions.channels.InviteToChannelRequest( channel=channel, users=[user_to_add.id], )) except Exception as e: - # Tangani error (misal user tidak ditemukan atau sudah ada di channel) print(f"Error adding user {username}: {e}") - # Mengirim pesan ke channel result_message = await client(SendMessageRequest(channel, message)) def test_send(self): -- cgit v1.2.3 From 6a7b2e28c9c1612ac3e91ac321b72e3400fdb5a3 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 20 Dec 2024 14:05:19 +0700 Subject: update --- indoteknik_custom/models/ir_actions_report.py | 2 +- indoteknik_custom/models/website_telegram.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index 7b1dcee8..31bcf168 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -29,4 +29,4 @@ class IrActionsReport(models.Model): self._check_telegram(pick) else: telegram = self.env['website.telegram'].create(telegram_data) - telegram.create_channel() + telegram.create_channel(sale_order.name + " Telah di print Oleh " + self.env.user.name) diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 7d76f27d..74955b7b 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -41,10 +41,10 @@ class WebsiteTelegram(models.Model): # Gabungkan semua nomor menjadi satu string, dipisahkan koma record.username_to_add = ', '.join(usernames) - def create_channel(self, *args, **kwargs): - asyncio.run(self._async_create_channel()) + def create_channel(self, message): + asyncio.run(self._async_create_channel(message)) - async def _async_create_channel(self): + async def _async_create_channel(self, message): async with TelegramClient(StringSession( '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client: @@ -68,10 +68,10 @@ class WebsiteTelegram(models.Model): users=[user_to_add.id], )) # message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101' - message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=357&model=sale.order&view_type=form&cids=1&menu_id=212' + message_template = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=357&model=sale.order&view_type=form&cids=1&menu_id=212' message2 = self.tittle + ' di print oleh ' + self.env.user.name - result_massage = await client(SendMessageRequest(channel, message)) - result_massage2 = await client(SendMessageRequest(channel, message2)) + result_massage = await client(SendMessageRequest(channel, message_template)) + result_massage2 = await client(SendMessageRequest(channel, message)) # Send the poll to the channel using PeerChannel with the channel's ID # result_polling = await client(SendMediaRequest( -- cgit v1.2.3 From 1d5e4ca1fa58bcd59954a08b694f273d4c563cdf Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 31 Dec 2024 09:44:40 +0700 Subject: update telegram --- indoteknik_custom/models/website_telegram.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 74955b7b..290fd1f9 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -21,7 +21,6 @@ class WebsiteTelegram(models.Model): tittle = fields.Char("Channel Title") invite_link = fields.Char("Channel invite link") username = fields.Char("Channel Name") - username_to_add = fields.Char("username to add on channel", compute='_compute_username_to_add') user_id = fields.Many2many('res.partner', string='User Member', store=True) id_data = fields.Char("Channel ID") about = fields.Char("Channel Description") @@ -31,15 +30,6 @@ class WebsiteTelegram(models.Model): # session_string = 'MIIBCgKCAQEAyMEdY1aR+sCR3ZSJrtztKTKqigvO/vBfqACJLZtS7QMgCGXJ6XIRyy7mx66W0/sOFa7/1mAZtEoIokDP3ShoqF4fVNb6XeqgQfaUHd8wJpDWHcR2OFwvplUUI1PLTktZ9uW2WE23b+ixNwJjJGwBDJPQEQFBE+vfmH0JP503wr5INS1poWg/j25sIWeYPHYeOrFp/eXaqhISP6G+q2IeTaWTXpwZj4LzXq5YOpk4bYEQ6mvRq7D1aHWfYmlEGepfaYR8Q0YqvvhYtMte3ITnuSJs171+GDqpdKcSwHnd6FudwGO4pcCOj4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB' - @api.depends('user_id') - def _compute_username_to_add(self): - for record in self: - usernames = [] - for partner in record.user_id: - if partner.telegram_id: # Pastikan mobile tidak None - usernames.append(partner.mobile) - # Gabungkan semua nomor menjadi satu string, dipisahkan koma - record.username_to_add = ', '.join(usernames) def create_channel(self, message): asyncio.run(self._async_create_channel(message)) -- cgit v1.2.3 From 3d672f12eecd77af9a805cebd8ce3a7083957a1f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 16 Jan 2025 10:30:17 +0700 Subject: wms push --- indoteknik_custom/models/stock_move.py | 4 + indoteknik_custom/models/stock_picking.py | 234 ++++++++++++++++++++++++------ 2 files changed, 190 insertions(+), 48 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index e1d4e74c..6b631713 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -12,9 +12,13 @@ class StockMove(models.Model): default=lambda self: self.product_id.print_barcode, ) qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') + barcode = fields.Char(string='Barcode', related='product_id.barcode') def _compute_qr_code_variant(self): for rec in self: + if rec.picking_id.picking_type_code == 'outgoing' and rec.picking_id and rec.picking_id.origin and rec.picking_id.origin.startswith('SO/'): + rec.qr_code_variant = rec.product_id.qr_code_variant + rec.print_barcode = True if rec.print_barcode and rec.print_barcode == True and rec.product_id and rec.product_id.qr_code_variant: rec.qr_code_variant = rec.product_id.qr_code_variant else: diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index cd330aeb..05a7ee4a 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -16,7 +16,8 @@ _logger = logging.getLogger(__name__) class StockPicking(models.Model): _inherit = 'stock.picking' - # check_product_lines = fields.One2many('check.product', 'picking_id', string='Check Product', auto_join=True) + check_product_lines = fields.One2many('check.product', 'picking_id', string='Check Product', auto_join=True) + barcode_product_lines = fields.One2many('barcode.product', 'picking_id', string='Barcode Product', auto_join=True) is_internal_use = fields.Boolean('Internal Use', help='flag which is internal use or not') account_id = fields.Many2one('account.account', string='Account') efaktur_id = fields.Many2one('vit.efaktur', string='Faktur Pajak') @@ -176,7 +177,8 @@ class StockPicking(models.Model): pickings = self.env['stock.picking'].search([ ('picking_type_code', '=', 'outgoing'), ('state', '=', 'done'), - ('carrier_id', '=', 9) + ('carrier_id', '=', 9), + ('lalamove_order_id', '!=', False) ]) for picking in pickings: try: @@ -810,7 +812,24 @@ class StockPicking(models.Model): self.date_done = datetime.datetime.utcnow() self.state_reserve = 'done' return res - + + + def check_qty_done_stock(self): + for line in self.move_line_ids_without_package: + def check_qty_per_inventory(self, product, location): + quant = self.env['stock.quant'].search([ + ('product_id', '=', product.id), + ('location_id', '=', location.id), + ]) + + if quant: + return quant.quantity + + return 0 + + qty_onhand = check_qty_per_inventory(self, line.product_id, line.location_id) + if line.qty_done > qty_onhand: + raise UserError('Quantity Done melebihi Quantity Onhand') def send_mail_bills(self): if self.picking_type_code == 'incoming' and self.purchase_id: @@ -1008,48 +1027,167 @@ class StockPicking(models.Model): return f'{formatted_fastest_eta} - {formatted_longest_eta}' -# class CheckProduct(models.Model): -# _name = 'check.product' -# _description = 'Check Product' -# _order = 'picking_id, id' - -# picking_id = fields.Many2one('stock.picking', string='Picking Reference', required=True, ondelete='cascade', index=True, copy=False) -# product_id = fields.Many2one('product.product', string='Product') - - -# @api.constrains('product_id') -# def check_product_validity(self): -# """ -# Validate if the product exists in the related stock.picking's move_ids_without_package -# and ensure that the product's quantity does not exceed the available product_uom_qty. -# """ -# for record in self: -# if not record.picking_id or not record.product_id: -# continue - -# # Filter move lines in the related picking for the selected product -# moves = record.picking_id.move_ids_without_package.filtered( -# lambda move: move.product_id.id == record.product_id.id -# ) - -# if not moves: -# raise UserError(( -# "The product '%s' is not available in the related stock picking's moves. " -# "Please check and try again." -# ) % record.product_id.display_name) - -# # Calculate the total entries for the product in check.product for the same picking -# product_entries_count = self.search_count([ -# ('picking_id', '=', record.picking_id.id), -# ('product_id', '=', record.product_id.id) -# ]) - -# # Sum the product_uom_qty for all relevant moves -# total_qty_in_moves = sum(moves.mapped('product_uom_qty')) - -# # Compare the count of entries against the available quantity -# if product_entries_count > total_qty_in_moves: -# raise UserError(( -# "The product '%s' exceeds the allowable quantity (%s) in the related stock picking's moves. " -# "You can only add it %s times." -# ) % (record.product_id.display_name, total_qty_in_moves, total_qty_in_moves)) +class CheckProduct(models.Model): + _name = 'check.product' + _description = 'Check Product' + _order = 'picking_id, id' + + picking_id = fields.Many2one( + 'stock.picking', + string='Picking Reference', + required=True, + ondelete='cascade', + index=True, + copy=False, + ) + product_id = fields.Many2one('product.product', string='Product', required=True) + quantity = fields.Float(string='Quantity', default=1.0, required=True) + status = fields.Char(string='Status', compute='_compute_status') + + @api.depends('quantity') + def _compute_status(self): + for record in self: + moves = record.picking_id.move_ids_without_package.filtered( + lambda move: move.product_id.id == record.product_id.id + ) + total_qty_in_moves = sum(moves.mapped('product_uom_qty')) + + if record.quantity < total_qty_in_moves: + record.status = 'Pending' + else: + record.status = 'Done' + + + def create(self, vals): + # Create the record + record = super(CheckProduct, self).create(vals) + # Ensure uniqueness after creation + if not self.env.context.get('skip_consolidate'): + record.with_context(skip_consolidate=True)._consolidate_duplicate_lines() + return record + + def write(self, vals): + # Write changes to the record + result = super(CheckProduct, self).write(vals) + # Ensure uniqueness after writing + if not self.env.context.get('skip_consolidate'): + self.with_context(skip_consolidate=True)._consolidate_duplicate_lines() + return result + + def _sync_check_product_to_moves(self, picking): + """ + Sinkronisasi quantity_done di move_ids_without_package + dengan total quantity dari check.product berdasarkan product_id. + """ + for product_id in picking.check_product_lines.mapped('product_id'): + # Totalkan quantity dari semua baris check.product untuk product_id ini + total_quantity = sum( + line.quantity for line in picking.check_product_lines.filtered(lambda line: line.product_id == product_id) + ) + # Update quantity_done di move yang relevan + moves = picking.move_ids_without_package.filtered(lambda move: move.product_id == product_id) + for move in moves: + move.quantity_done = total_quantity + + def _consolidate_duplicate_lines(self): + """ + Consolidate duplicate lines with the same product_id under the same picking_id + and sync the total quantity to related moves. + """ + for picking in self.mapped('picking_id'): + lines_to_remove = self.env['check.product'] # Recordset untuk menyimpan baris yang akan dihapus + product_lines = picking.check_product_lines.filtered(lambda line: line.product_id) + + # Group lines by product_id + product_groups = {} + for line in product_lines: + product_groups.setdefault(line.product_id.id, []).append(line) + + for product_id, lines in product_groups.items(): + if len(lines) > 1: + # Consolidate duplicate lines + first_line = lines[0] + total_quantity = sum(line.quantity for line in lines) + + # Update the first line's quantity + first_line.with_context(skip_consolidate=True).write({'quantity': total_quantity}) + + # Add the remaining lines to the lines_to_remove recordset + lines_to_remove |= self.env['check.product'].browse([line.id for line in lines[1:]]) + + # Perform unlink after consolidation + if lines_to_remove: + lines_to_remove.unlink() + + # Sync total quantities to moves + self._sync_check_product_to_moves(picking) + + @api.onchange('product_id', 'quantity') + def check_product_validity(self): + for record in self: + if not record.picking_id or not record.product_id: + continue + + # Filter moves related to the selected product + moves = record.picking_id.move_ids_without_package.filtered( + lambda move: move.product_id.id == record.product_id.id + ) + + if not moves: + raise UserError(( + "The product '%s' is not available in the related stock picking's moves. " + "Please check and try again." + ) % record.product_id.display_name) + + total_qty_in_moves = sum(moves.mapped('product_uom_qty')) + + # Find existing lines for the same product, excluding the current line + existing_lines = record.picking_id.check_product_lines.filtered( + lambda line: line.product_id == record.product_id and line.id != record.id + ) + + if existing_lines: + # Get the first existing line + first_line = existing_lines[0] + + # Calculate the total quantity after addition + total_quantity = sum(existing_lines.mapped('quantity')) - record.quantity + + if total_quantity > total_qty_in_moves: + raise UserError(( + "Quantity Product '%s' sudah melebihi quantity demand: (%s)." + ) % (record.product_id.display_name)) + + else: + # Check if the quantity exceeds the allowed total + if record.quantity > total_qty_in_moves: + raise UserError(( + "Quantity Product '%s' sudah melebihi quantity demand: (%s)." + ) % (record.product_id.display_name)) + + # Set the quantity to the entered value + record.quantity = record.quantity + +class BarcodeProduct(models.Model): + _name = 'barcode.product' + _description = 'Barcode Product' + _order = 'picking_id, id' + + picking_id = fields.Many2one( + 'stock.picking', + string='Picking Reference', + required=True, + ondelete='cascade', + index=True, + copy=False, + ) + product_id = fields.Many2one('product.product', string='Product', required=True) + barcode = fields.Char(string='Barcode') + + @api.constrains('barcode') + def send_barcode_to_product(self): + for record in self: + if record.barcode and not record.product_id.barcode: + record.product_id.barcode = record.barcode + else: + raise UserError('Barcode sudah terisi') \ No newline at end of file -- cgit v1.2.3 From 6424192cdcb34ff2ea57a19b5ee41bf4bf68870c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 16 Jan 2025 13:29:35 +0700 Subject: push --- indoteknik_custom/models/product_template.py | 2 +- indoteknik_custom/models/stock_picking.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 5bedae13..29608297 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -416,7 +416,7 @@ class ProductProduct(models.Model): box_size=5, border=4, ) - qr.add_data(rec.default_code) + qr.add_data(rec.barcode if rec.barcode else rec.default_code) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 05a7ee4a..cf5b0502 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -894,10 +894,20 @@ class StockPicking(models.Model): @api.model def create(self, vals): self._use_faktur(vals) + if vals.get('picking_type_code') == 'incoming' and vals.get('location_dest_id') == 58: + if 'name' in vals and vals['name'].startswith('BU/IN/'): + vals['name'] = vals['name'].replace('BU/IN/', 'BU/INPUT/', 1) return super(StockPicking, self).create(vals) def write(self, vals): self._use_faktur(vals) + for picking in self: + if (vals.get('picking_type_code', picking.picking_type_code) == 'incoming' and + vals.get('location_dest_id', picking.location_dest_id.id) == 58): + if 'name' in vals or picking.name.startswith('BU/IN/'): + name_to_modify = vals.get('name', picking.name) + if name_to_modify.startswith('BU/IN/'): + vals['name'] = name_to_modify.replace('BU/IN/', 'BU/INPUT/', 1) return super(StockPicking, self).write(vals) def _use_faktur(self, vals): -- cgit v1.2.3 From 11a561355208a403d635b16d6c306cc9f19eb714 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 16 Jan 2025 15:51:33 +0700 Subject: change name --- indoteknik_custom/models/stock_picking.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index cf5b0502..4c19cb3a 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -897,17 +897,36 @@ class StockPicking(models.Model): if vals.get('picking_type_code') == 'incoming' and vals.get('location_dest_id') == 58: if 'name' in vals and vals['name'].startswith('BU/IN/'): vals['name'] = vals['name'].replace('BU/IN/', 'BU/INPUT/', 1) + + if vals.get('picking_type_code') == 'internal' and vals.get('location_id') == 58: + if 'name' in vals and vals['name'].startswith('BU/INT'): + new_name = vals['name'].replace('BU/INT', 'BU/IN', 1) + # Periksa apakah nama sudah ada + if self.env['stock.picking'].search_count([('name', '=', new_name), ('company_id', '=', vals.get('company_id'))]) > 0: + new_name = f"{new_name}-DUP" + vals['name'] = new_name return super(StockPicking, self).create(vals) def write(self, vals): self._use_faktur(vals) for picking in self: + # Periksa apakah kondisi terpenuhi saat data diubah if (vals.get('picking_type_code', picking.picking_type_code) == 'incoming' and vals.get('location_dest_id', picking.location_dest_id.id) == 58): if 'name' in vals or picking.name.startswith('BU/IN/'): name_to_modify = vals.get('name', picking.name) if name_to_modify.startswith('BU/IN/'): vals['name'] = name_to_modify.replace('BU/IN/', 'BU/INPUT/', 1) + + if (vals.get('picking_type_code', picking.picking_type_code) == 'internal' and + vals.get('location_id', picking.location_id.id) == 58): + name_to_modify = vals.get('name', picking.name) + if name_to_modify.startswith('BU/INT'): + new_name = name_to_modify.replace('BU/INT', 'BU/IN', 1) + # Periksa apakah nama sudah ada + if self.env['stock.picking'].search_count([('name', '=', new_name), ('company_id', '=', picking.company_id.id)]) > 0: + new_name = f"{new_name}-DUP" + vals['name'] = new_name return super(StockPicking, self).write(vals) def _use_faktur(self, vals): -- cgit v1.2.3 From 69b84d53a07b77aaca96f88ff4a3b24e52d48fc3 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 20 Jan 2025 12:57:18 +0700 Subject: update code --- indoteknik_custom/models/ir_actions_report.py | 3 ++- indoteknik_custom/models/website_telegram.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index 31bcf168..e6b9c303 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -14,7 +14,8 @@ class IrActionsReport(models.Model): if sale_order.amount_total < 200000000: return # id ci vita 79160 - partner = request.env['res.partner'].search([('id', '=', 112718)], limit=1) + # id iman 112718 + partner = request.env['res.partner'].search([('id', '=', 79160)], limit=1) telegram_data = { 'tittle': sale_order.name, 'about': sale_order.name, diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 290fd1f9..c655143e 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -3,6 +3,7 @@ import clipboard from odoo import models, fields, api from telethon.sessions import StringSession from telethon.sync import TelegramClient +from odoo.exceptions import UserError from telethon import functions, types from telethon.tl.types import InputPeerChannel import asyncio @@ -52,11 +53,14 @@ class WebsiteTelegram(models.Model): # Iterasi untuk setiap username for name in self.user_id: - user_to_add = await client.get_entity(name.telegram_id) - result_add_user = await client(functions.channels.InviteToChannelRequest( - channel=channel, - users=[user_to_add.id], - )) + if name.telegram_id: + user_to_add = await client.get_entity(name.telegram_id) + result_add_user = await client(functions.channels.InviteToChannelRequest( + channel=channel, + users=[user_to_add.id], + )) + else: + raise UserError('ID Telegram '+ name.name + ' salah atau belum diisi') # message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101' message_template = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=357&model=sale.order&view_type=form&cids=1&menu_id=212' message2 = self.tittle + ' di print oleh ' + self.env.user.name -- cgit v1.2.3 From d4d24ffeff13b6169e0e3657c48990e45e80fd17 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 20 Jan 2025 13:35:37 +0700 Subject: delete clipboard modul import --- indoteknik_custom/models/website_telegram.py | 74 ++++++++++++++-------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index c655143e..c877a067 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -1,5 +1,5 @@ import requests -import clipboard +# import clipboard from odoo import models, fields, api from telethon.sessions import StringSession from telethon.sync import TelegramClient @@ -8,11 +8,11 @@ from telethon import functions, types from telethon.tl.types import InputPeerChannel import asyncio from telethon.tl.functions.messages import SendMessageRequest -from telethon.tl.types import InputMediaPoll, Poll, PollAnswer, PeerChannel +# from telethon.tl.types import InputMediaPoll, Poll, PollAnswer, PeerChannel import datetime from telethon.tl.types import MessageMediaPoll -from telethon.tl.functions.messages import SendMediaRequest -from telethon.tl.types import TextWithEntities +# from telethon.tl.functions.messages import SendMediaRequest +# from telethon.tl.types import TextWithEntities class WebsiteTelegram(models.Model): _name = 'website.telegram' @@ -148,39 +148,39 @@ class WebsiteTelegram(models.Model): except Exception as e: print(e) - @api.depends('name', 'chatID', 'bot_name') - def _calc_python_code(self): - for record in self: - if not record.name: - record.python_code = "pleas put a name" - elif not record.test_message: - record.test_message = "test" - else: - record.python_code = "self.env['website.telegram'].search([('name', '=', '" + record.name + "')])[0].send_to_telegram('" + record.test_message + "')" - - def copy_chat_id(self): - record = self.browse(self.id) - clipboard.copy(record.python_code) - - def paste_chat_id(self): - record = self.browse(self.id) - chat_id = clipboard.paste() - record.write({'chatID': chat_id}) - - def paste_bot_name(self): - record = self.browse(self.id) - bot_name = clipboard.paste() - record.write({'bot_name': bot_name}) - - def get_updates(self): - apiURL = f'https://api.telegram.org/bot{self.bot_name}/getUpdates' - try: - response = requests.get(apiURL) - updates = response.json() - return updates - except Exception as e: - print(e) - return None + # @api.depends('name', 'chatID', 'bot_name') + # def _calc_python_code(self): + # for record in self: + # if not record.name: + # record.python_code = "pleas put a name" + # elif not record.test_message: + # record.test_message = "test" + # else: + # record.python_code = "self.env['website.telegram'].search([('name', '=', '" + record.name + "')])[0].send_to_telegram('" + record.test_message + "')" + # + # def copy_chat_id(self): + # record = self.browse(self.id) + # clipboard.copy(record.python_code) + # + # def paste_chat_id(self): + # record = self.browse(self.id) + # chat_id = clipboard.paste() + # record.write({'chatID': chat_id}) + # + # def paste_bot_name(self): + # record = self.browse(self.id) + # bot_name = clipboard.paste() + # record.write({'bot_name': bot_name}) + # + # def get_updates(self): + # apiURL = f'https://api.telegram.org/bot{self.bot_name}/getUpdates' + # try: + # response = requests.get(apiURL) + # updates = response.json() + # return updates + # except Exception as e: + # print(e) + # return None # def receive_messages(self): # updates = self.get_updates() -- cgit v1.2.3 From 717719226f60f6a7c5e89e8db18eb22a62b3391a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 20 Jan 2025 14:35:30 +0700 Subject: push --- indoteknik_custom/models/ir_actions_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index e6b9c303..6e15fbfc 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -4,7 +4,7 @@ class IrActionsReport(models.Model): _inherit = 'ir.actions.report' def _get_readable_fields(self): - self.send_to_telegram() + # self.send_to_telegram() return super()._get_readable_fields() def send_to_telegram(self): -- cgit v1.2.3 From 4b41c2b82a7ec48baf91746dfa9e79b94a17eefb Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 20 Jan 2025 14:45:08 +0700 Subject: hanya send telegram if quotation --- indoteknik_custom/models/ir_actions_report.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index 6e15fbfc..c1e84031 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -4,7 +4,8 @@ class IrActionsReport(models.Model): _inherit = 'ir.actions.report' def _get_readable_fields(self): - # self.send_to_telegram() + if self.env.context.get('active_model') == 'sale.order': + self.send_to_telegram() return super()._get_readable_fields() def send_to_telegram(self): -- cgit v1.2.3 From d406e0cc949f8f35631d872993850f3ccec0821d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 20 Jan 2025 16:03:00 +0700 Subject: add other taxes in account move --- indoteknik_custom/models/account_move.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index d62f19ae..85ed1d54 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -63,6 +63,11 @@ class AccountMove(models.Model): flag_delivery_amt = fields.Boolean(string="Flag Delivery Amount", compute='compute_flag_delivery_amt') nomor_kwitansi = fields.Char(string="Nomor Kwitansi") other_subtotal = fields.Float(string="Other Subtotal", compute='compute_other_subtotal') + other_taxes = fields.Float(string="Other Taxes", compute='compute_other_taxes') + + def compute_other_taxes(self): + for rec in self: + rec.other_taxes = rec.other_subtotal * 0.12 def compute_other_subtotal(self): for rec in self: -- cgit v1.2.3 From 190e71e69ac16b23f327ff436b1292b9f1aba790 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 21 Jan 2025 08:35:04 +0700 Subject: ganti notif tele 200jt ke 50jt --- indoteknik_custom/models/ir_actions_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index c1e84031..94245c1a 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -12,7 +12,7 @@ class IrActionsReport(models.Model): so_id = self.env.context.get('active_id') if so_id: sale_order = self.env['sale.order'].browse(so_id) - if sale_order.amount_total < 200000000: + if sale_order.amount_total < 50000000: return # id ci vita 79160 # id iman 112718 -- cgit v1.2.3 From 9ae65ca732475a41f4055264b0e068bc607de759 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 21 Jan 2025 09:44:55 +0700 Subject: cr forecast --- .../models/report_stock_forecasted.py | 49 +--------------------- 1 file changed, 1 insertion(+), 48 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py index c9d54a15..37082869 100644 --- a/indoteknik_custom/models/report_stock_forecasted.py +++ b/indoteknik_custom/models/report_stock_forecasted.py @@ -1,51 +1,4 @@ from odoo import api, models class ReplenishmentReport(models.AbstractModel): - _inherit = 'report.stock.report_product_product_replenishment' - - @api.model - def _get_report_lines(self, product_template_ids, product_variant_ids, wh_location_ids): - lines = super(ReplenishmentReport, self)._get_report_lines(product_template_ids, product_variant_ids, wh_location_ids) - # result_dict = {} - # - # for line in lines: - # document_out = line.get('document_out') - # - # if document_out and "SO/" in document_out.name: - # order_id = document_out.id - # if document_out == False: - # continue - # product_id = line.get('product', {}).get('id') - # query = [('product_id', '=', product_id)] - # - # if order_id: - # result = self._calculate_result(line) - # quantity = line.get('quantity', 0) - # result_dict.setdefault(order_id, []).append((result, quantity)) - # - # for order_id, results in result_dict.items(): - # sales_order = self.env['sale.order'].browse(order_id) - # - # for result, quantity in results: - # self.env['sales.order.fullfillment'].create({ - # 'sales_order_id': sales_order.id, - # 'product_id': product_id, - # 'reserved_from': result, - # 'qty_fullfillment': quantity, - # }) - return lines - - def _calculate_result(self, line): - if line['document_in']: - return str(line["document_in"].name) - elif line['reservation'] and not line['document_in']: - return 'Reserved from stock' - elif line['replenishment_filled']: - if line['document_out']: - return 'Inventory On Hand' - else: - return 'Free Stock' - else: - return 'Unfulfilled' - - + _inherit = 'report.stock.report_product_product_replenishment' \ No newline at end of file -- cgit v1.2.3 From 696d5e4bf41b927300102293e5027778ffdc9296 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 21 Jan 2025 10:19:54 +0700 Subject: cr ir actions report --- indoteknik_custom/models/ir_actions_report.py | 49 ++++++++++++++++++--------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index 94245c1a..28adcf74 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -1,5 +1,6 @@ from odoo import models from odoo.http import request +import requests class IrActionsReport(models.Model): _inherit = 'ir.actions.report' @@ -14,21 +15,37 @@ class IrActionsReport(models.Model): sale_order = self.env['sale.order'].browse(so_id) if sale_order.amount_total < 50000000: return + # ci_vita 7751529082:AAE9XsZa_Pj2Pi2IN1grX98WkwTaIt32pbI & 5081411103 + # iman 7094158106:AAHpWtYOMnA3Yqm_Fvrr3Vw7MrB45vLV9AY & 6592318498 + # bot_name_iman = '7094158106:AAHpWtYOMnA3Yqm_Fvrr3Vw7MrB45vLV9AY' + # chat_id_iman = '6592318498' + bot_name_vita = '7751529082:AAE9XsZa_Pj2Pi2IN1grX98WkwTaIt32pbI' + chat_id_vita = '5081411103' + apiURL = f'https://api.telegram.org/bot{bot_name_vita}/sendMessage' + try: + requests.post(apiURL, json={'chat_id': chat_id_vita, 'text': sale_order.name + " senilai Rp" + self.format_currency(sale_order.amount_total) + ' untuk customer ' + sale_order.partner_id.name + ' telah dibuat oleh sales ' +sale_order.user_id.name}) + except Exception as e: + print(e) + # id ci vita 79160 # id iman 112718 - partner = request.env['res.partner'].search([('id', '=', 79160)], limit=1) - telegram_data = { - 'tittle': sale_order.name, - 'about': sale_order.name, - 'user_id': partner, - 'id_data': sale_order.id, - 'username': '@' + sale_order.name.replace('/', '') - } - channel_data = self.env['website.telegram'].search([('tittle', '=', sale_order.name)]) - if channel_data: - channel_data.send_to_telegram(sale_order.name + " Telah di print Oleh " + self.env.user.name) - for pick in self: - self._check_telegram(pick) - else: - telegram = self.env['website.telegram'].create(telegram_data) - telegram.create_channel(sale_order.name + " Telah di print Oleh " + self.env.user.name) + # partner = request.env['res.partner'].search([('id', '=', 112718)], limit=1) + # telegram_data = { + # 'tittle': sale_order.name, + # 'about': sale_order.name, + # 'user_id': partner, + # 'id_data': sale_order.id, + # 'username': '@' + sale_order.name.replace('/', '') + # } + # channel_data = self.env['website.telegram'].search([('tittle', '=', sale_order.name)]) + # if channel_data: + # channel_data.send_to_telegram(sale_order.name + " Telah di print Oleh " + self.env.user.name) + # for pick in self: + # self._check_telegram(pick) + # else: + # telegram = self.env['website.telegram'].create(telegram_data) + # telegram.create_channel(sale_order.name + " Telah di print Oleh " + self.env.user.name) + + def format_currency(self, number): + number = int(number) + return "{:,}".format(number).replace(',', '.') \ No newline at end of file -- cgit v1.2.3 From e3521c2153c36cee6629cee9146e1b4b0201da9f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 21 Jan 2025 10:48:25 +0700 Subject: cr purchasing job --- indoteknik_custom/models/purchasing_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 4efb0cd4..74b5134e 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -182,7 +182,7 @@ class OutstandingSales(models.Model): join product_product pp on pp.id = sm.product_id join product_template pt on pt.id = pp.product_tmpl_id left join x_manufactures xm on xm.id = pt.x_manufacture - where sp.state in ('draft', 'waiting', 'confirmed', 'assigned') + where sp.state in ('draft', 'waiting', 'confirmed') and sp.name like '%OUT%' ) """) -- cgit v1.2.3 From e072cbf06a86cb376d71c0490f0f48c6de1fd3f7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 21 Jan 2025 14:41:19 +0700 Subject: fix pj --- indoteknik_custom/models/purchasing_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 74b5134e..4efb0cd4 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -182,7 +182,7 @@ class OutstandingSales(models.Model): join product_product pp on pp.id = sm.product_id join product_template pt on pt.id = pp.product_tmpl_id left join x_manufactures xm on xm.id = pt.x_manufacture - where sp.state in ('draft', 'waiting', 'confirmed') + where sp.state in ('draft', 'waiting', 'confirmed', 'assigned') and sp.name like '%OUT%' ) """) -- cgit v1.2.3 From 25ea83dd6a1f8ff272fd086a998904ed792b1041 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 21 Jan 2025 14:57:10 +0700 Subject: fix bug pj --- indoteknik_custom/models/purchasing_job.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 4efb0cd4..902bc34b 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -183,6 +183,7 @@ class OutstandingSales(models.Model): join product_template pt on pt.id = pp.product_tmpl_id left join x_manufactures xm on xm.id = pt.x_manufacture where sp.state in ('draft', 'waiting', 'confirmed', 'assigned') + and sm.state in ('draft', 'waiting', 'confirmed', 'partially_available') and sp.name like '%OUT%' ) """) -- cgit v1.2.3 From afbdeb766a04d4c6d31d55151c02320f2b67c3fb Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 23 Jan 2025 09:58:19 +0700 Subject: update bisa edit limit dan durasi tambah ko step dan mba wid --- indoteknik_custom/models/user_pengajuan_tempo_request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index b43f56ac..8023dfa7 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -334,13 +334,13 @@ class UserPengajuanTempoRequest(models.Model): @api.onchange('tempo_duration') def _tempo_duration_change(self): for tempo in self: - if tempo.env.user.id not in (7, 377, 12182): + if tempo.env.user.id not in (7, 688, 28, 377, 12182): raise UserError("Durasi tempo hanya bisa di ubah oleh Sales Manager atau Direktur") @api.onchange('tempo_limit') def _onchange_tempo_limit(self): for tempo in self: - if tempo.env.user.id not in (7, 377, 12182): + if tempo.env.user.id not in (7, 688, 28, 377, 12182): raise UserError("Limit tempo hanya bisa diubah oleh Sales Manager atau Direktur") def button_approve(self): for tempo in self: -- cgit v1.2.3 From 2a47fdafcb12440c68e346d35d465b0a0c800945 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 23 Jan 2025 10:03:15 +0700 Subject: push --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/barcoding_product.py | 36 +++++++++++++++++++++++++++ indoteknik_custom/models/stock_picking.py | 8 +++--- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 indoteknik_custom/models/barcoding_product.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 3990e81c..ed9e91da 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -139,3 +139,4 @@ from . import va_multi_approve from . import va_multi_reject from . import stock_immediate_transfer from . import coretax_fatur +from . import barcoding_product diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py new file mode 100644 index 00000000..41444646 --- /dev/null +++ b/indoteknik_custom/models/barcoding_product.py @@ -0,0 +1,36 @@ +from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import timedelta, date, datetime +import logging + +_logger = logging.getLogger(__name__) + +class BarcodingProduct(models.Model): + _name = "barcoding.product" + _description = "Barcoding Product" + + barcoding_product_line = fields.One2many('barcoding.product.line', 'barcoding_product_id', string='Barcoding Product Lines', auto_join=True) + product_id = fields.Many2one('product.product', string="Product", tracking=3) + quantity = fields.Float(string="Quantity", tracking=3) + + @api.onchange('product_id', 'quantity') + def _onchange_product_or_quantity(self): + """Update barcoding_product_line based on product_id and quantity""" + if self.product_id and self.quantity > 0: + # Clear existing lines + self.barcoding_product_line = [(5, 0, 0)] + + # Add a new line with the current product and quantity + self.barcoding_product_line = [(0, 0, { + 'product_id': self.product_id.id, + 'barcoding_product_id': self.id, + }) for _ in range(int(self.quantity))] + + +class BarcodingProductLine(models.Model): + _name = 'barcoding.product.line' + _description = 'Barcoding Product Line' + _order = 'barcoding_product_id, id' + + barcoding_product_id = fields.Many2one('barcoding.product', string='Barcoding Product Ref', required=True, ondelete='cascade', index=True, copy=False) + product_id = fields.Many2one('product.product', string="Product") \ No newline at end of file diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 4c19cb3a..cc86c451 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1164,8 +1164,7 @@ class CheckProduct(models.Model): if not moves: raise UserError(( - "The product '%s' is not available in the related stock picking's moves. " - "Please check and try again." + "The product '%s' tidak ada di operations. " ) % record.product_id.display_name) total_qty_in_moves = sum(moves.mapped('product_uom_qty')) @@ -1184,14 +1183,13 @@ class CheckProduct(models.Model): if total_quantity > total_qty_in_moves: raise UserError(( - "Quantity Product '%s' sudah melebihi quantity demand: (%s)." + "Quantity Product '%s' sudah melebihi quantity demand." ) % (record.product_id.display_name)) - else: # Check if the quantity exceeds the allowed total if record.quantity > total_qty_in_moves: raise UserError(( - "Quantity Product '%s' sudah melebihi quantity demand: (%s)." + "Quantity Product '%s' sudah melebihi quantity demand." ) % (record.product_id.display_name)) # Set the quantity to the entered value -- cgit v1.2.3 From 8af596373c8eb997bbb96cf020f670b6b60b57ca Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 23 Jan 2025 10:06:29 +0700 Subject: push --- indoteknik_custom/models/barcoding_product.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index 41444646..6bbf9fde 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -33,4 +33,5 @@ class BarcodingProductLine(models.Model): _order = 'barcoding_product_id, id' barcoding_product_id = fields.Many2one('barcoding.product', string='Barcoding Product Ref', required=True, ondelete='cascade', index=True, copy=False) - product_id = fields.Many2one('product.product', string="Product") \ No newline at end of file + product_id = fields.Many2one('product.product', string="Product") + qr_code_variant = fields.Binary("QR Code Variant", related='product_id.qr_code_variant') \ No newline at end of file -- cgit v1.2.3 From 64ef15502562e392ddeb011ced08239f9c6934f3 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 24 Jan 2025 09:15:14 +0700 Subject: update code --- indoteknik_custom/models/ir_actions_report.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index 28adcf74..5b49a3ae 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -17,13 +17,13 @@ class IrActionsReport(models.Model): return # ci_vita 7751529082:AAE9XsZa_Pj2Pi2IN1grX98WkwTaIt32pbI & 5081411103 # iman 7094158106:AAHpWtYOMnA3Yqm_Fvrr3Vw7MrB45vLV9AY & 6592318498 - # bot_name_iman = '7094158106:AAHpWtYOMnA3Yqm_Fvrr3Vw7MrB45vLV9AY' - # chat_id_iman = '6592318498' + bot_name_iman = '7094158106:AAHpWtYOMnA3Yqm_Fvrr3Vw7MrB45vLV9AY' + chat_id_iman = '6592318498' bot_name_vita = '7751529082:AAE9XsZa_Pj2Pi2IN1grX98WkwTaIt32pbI' chat_id_vita = '5081411103' - apiURL = f'https://api.telegram.org/bot{bot_name_vita}/sendMessage' + apiURL = f'https://api.telegram.org/bot{bot_name_iman}/sendMessage' try: - requests.post(apiURL, json={'chat_id': chat_id_vita, 'text': sale_order.name + " senilai Rp" + self.format_currency(sale_order.amount_total) + ' untuk customer ' + sale_order.partner_id.name + ' telah dibuat oleh sales ' +sale_order.user_id.name}) + requests.post(apiURL, json={'chat_id': chat_id_iman, 'text': sale_order.name + " senilai Rp" + self.format_currency(sale_order.amount_total) + ' untuk customer ' + sale_order.partner_id.name + ' telah dibuat oleh sales ' +sale_order.user_id.name}) except Exception as e: print(e) -- cgit v1.2.3 From 1a5b7ce42ffd240da52e01758d636a31c0877e6e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 24 Jan 2025 09:20:45 +0700 Subject: revisi chat id telegram --- indoteknik_custom/models/ir_actions_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py index 5b49a3ae..83636945 100644 --- a/indoteknik_custom/models/ir_actions_report.py +++ b/indoteknik_custom/models/ir_actions_report.py @@ -18,7 +18,7 @@ class IrActionsReport(models.Model): # ci_vita 7751529082:AAE9XsZa_Pj2Pi2IN1grX98WkwTaIt32pbI & 5081411103 # iman 7094158106:AAHpWtYOMnA3Yqm_Fvrr3Vw7MrB45vLV9AY & 6592318498 bot_name_iman = '7094158106:AAHpWtYOMnA3Yqm_Fvrr3Vw7MrB45vLV9AY' - chat_id_iman = '6592318498' + chat_id_iman = '-1002493002821' bot_name_vita = '7751529082:AAE9XsZa_Pj2Pi2IN1grX98WkwTaIt32pbI' chat_id_vita = '5081411103' apiURL = f'https://api.telegram.org/bot{bot_name_iman}/sendMessage' -- cgit v1.2.3 From d61386fdd9e6082f66ba412dc5ad56e3ff3b2c08 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 24 Jan 2025 09:48:27 +0700 Subject: cr chart of account journal entries --- indoteknik_custom/models/invoice_reklas.py | 4 ++-- indoteknik_custom/models/uangmuka_pembelian.py | 2 +- indoteknik_custom/models/uangmuka_penjualan.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/invoice_reklas.py b/indoteknik_custom/models/invoice_reklas.py index 30da02d1..f5bb5a25 100644 --- a/indoteknik_custom/models/invoice_reklas.py +++ b/indoteknik_custom/models/invoice_reklas.py @@ -49,7 +49,7 @@ class InvoiceReklas(models.TransientModel): if self.reklas_type == 'penjualan': parameter_debit = { 'move_id': account_move.id, - 'account_id': 449, # uang muka penjualan + 'account_id': 668, # penerimaan belum alokasi 'partner_id': invoice.partner_id.id, 'currency_id': 12, 'debit': self.pay_amt, @@ -77,7 +77,7 @@ class InvoiceReklas(models.TransientModel): } parameter_credit = { 'move_id': account_move.id, - 'account_id': 401, + 'account_id': 669, 'partner_id': invoice.partner_id.id, 'currency_id': 12, 'debit': 0, diff --git a/indoteknik_custom/models/uangmuka_pembelian.py b/indoteknik_custom/models/uangmuka_pembelian.py index 204855d3..ba41f814 100644 --- a/indoteknik_custom/models/uangmuka_pembelian.py +++ b/indoteknik_custom/models/uangmuka_pembelian.py @@ -64,7 +64,7 @@ class UangmukaPembelian(models.TransientModel): param_debit = { 'move_id': account_move.id, - 'account_id': 401, # uang muka persediaan barang dagang + 'account_id': 669, # uang muka persediaan barang dagang 'partner_id': partner_id, 'currency_id': 12, 'debit': self.pay_amt, diff --git a/indoteknik_custom/models/uangmuka_penjualan.py b/indoteknik_custom/models/uangmuka_penjualan.py index 5acf604d..a3e95ecd 100644 --- a/indoteknik_custom/models/uangmuka_penjualan.py +++ b/indoteknik_custom/models/uangmuka_penjualan.py @@ -74,7 +74,7 @@ class UangmukaPenjualan(models.TransientModel): # sisa di credit untuk uang muka penjualan, diluar ongkir dan selisih param_credit = { 'move_id': account_move.id, - 'account_id': 449, # uang muka penjualan + 'account_id': 668, # penerimaan belum alokasi 'partner_id': partner_id, 'currency_id': 12, 'debit': 0, -- cgit v1.2.3 From 1dd6174e739bb81c651ead6749200fcd09190ddc Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 24 Jan 2025 13:42:27 +0700 Subject: cr account id --- indoteknik_custom/models/invoice_reklas_penjualan.py | 2 +- indoteknik_custom/models/purchase_order.py | 4 ++-- indoteknik_custom/models/purchase_order_multi_uangmuka.py | 2 +- indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/invoice_reklas_penjualan.py b/indoteknik_custom/models/invoice_reklas_penjualan.py index 5027c8af..80c3ed43 100644 --- a/indoteknik_custom/models/invoice_reklas_penjualan.py +++ b/indoteknik_custom/models/invoice_reklas_penjualan.py @@ -33,7 +33,7 @@ class InvoiceReklasPenjualan(models.TransientModel): parameter_debit = { 'move_id': account_move.id, - 'account_id': 449, # uang muka penjualan + 'account_id': 668, # uang muka penjualan 'partner_id': invoice.partner_id.id, 'currency_id': 12, 'debit': invoice.pay_amt, diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index d487ada3..12a94730 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -178,7 +178,7 @@ class PurchaseOrder(models.Model): 'move_id': bills.id, 'product_id': product_dp.id, # product down payment 'name': '[IT.121456] Down Payment', # product down payment - 'account_id': 401, # Uang Muka persediaan barang dagang + 'account_id': 669, # Uang Muka persediaan barang dagang # 'price_unit': move_line.price_unit, 'quantity': -1, 'product_uom_id': 1, @@ -240,7 +240,7 @@ class PurchaseOrder(models.Model): data_line_bills = { 'move_id': bills.id, 'product_id': product_dp.id, # product down payment - 'account_id': 401, # Uang Muka persediaan barang dagang + 'account_id': 669, # Uang Muka persediaan barang dagang 'quantity': 1, 'product_uom_id': 1, 'tax_ids': [line[0].taxes_id.id for line in self.order_line], diff --git a/indoteknik_custom/models/purchase_order_multi_uangmuka.py b/indoteknik_custom/models/purchase_order_multi_uangmuka.py index dd63e698..0570efd9 100644 --- a/indoteknik_custom/models/purchase_order_multi_uangmuka.py +++ b/indoteknik_custom/models/purchase_order_multi_uangmuka.py @@ -76,7 +76,7 @@ class PurchaseOrderMultiUangmuka(models.TransientModel): param_debit = { 'move_id': account_move.id, - 'account_id': 401, # uang muka persediaan barang dagang + 'account_id': 669, # uang muka persediaan barang dagang 'partner_id': partner_id, 'currency_id': 12, 'debit': order.amount_total, diff --git a/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py index f9120290..96c2f676 100644 --- a/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py +++ b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py @@ -68,7 +68,7 @@ class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): param_credit = { 'move_id': account_move.id, - 'account_id': 449, # uang muka penjualan + 'account_id': 668, # penerimaan belum alokasi 'partner_id': partner_id, 'currency_id': 12, 'debit': 0, -- cgit v1.2.3 From ea81f5a5b5eedfffcfa15a3f752ccc81df6eed04 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 25 Jan 2025 10:34:13 +0700 Subject: CR automatic purchase brand stihl and mikasa --- indoteknik_custom/models/automatic_purchase.py | 141 +++++++++++++------------ 1 file changed, 73 insertions(+), 68 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 09d283eb..fbdf8dae 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -183,89 +183,94 @@ class AutomaticPurchase(models.Model): def create_po_by_vendor(self, vendor_id): current_time = datetime.now() - if not self.apo_type =='reordering': - name = "/PJ/" - else: - name = "/A/" + name = "/PJ/" if not self.apo_type == 'reordering' else "/A/" PRODUCT_PER_PO = 20 - auto_purchase_line = self.env['automatic.purchase.line'] - last_po = self.env['purchase.order'].search([ - ('partner_id', '=', vendor_id), - ('state', '=', 'done'), - ], order='id desc', limit=1) - - param_header = { - 'partner_id': vendor_id, - 'currency_id': 12, - 'user_id': self.env.user.id, - 'company_id': 1, # indoteknik dotcom gemilang - 'picking_type_id': 28, # indoteknik bandengan receipts - 'date_order': current_time, - 'from_apo': True, - 'note_description': 'Automatic PO' - } - + # Domain untuk semua baris dengan vendor_id tertentu domain = [ ('automatic_purchase_id', '=', self.id), ('partner_id', '=', vendor_id), ('qty_purchase', '>', 0) ] - products_len = auto_purchase_line.search_count(domain) - page = math.ceil(products_len / PRODUCT_PER_PO) - - # i start from zero (0) - for i in range(page): - new_po = self.env['purchase.order'].create([param_header]) - new_po.payment_term_id = new_po.partner_id.property_supplier_payment_term_id - new_po.name = new_po.name + name + str(i + 1) + # Tambahkan domain khusus untuk brand_id 22 dan 564 + special_brand_domain = domain + [('brand_id', 'in', [22, 564])] + regular_domain = domain + [('brand_id', 'not in', [22, 564])] + + # Fungsi untuk membuat PO berdasarkan domain tertentu + def create_po_for_domain(domain, special_payment_term=False): + products_len = auto_purchase_line.search_count(domain) + page = math.ceil(products_len / PRODUCT_PER_PO) + + for i in range(page): + # Buat PO baru + param_header = { + 'partner_id': vendor_id, + 'currency_id': 12, + 'user_id': self.env.user.id, + 'company_id': 1, # indoteknik dotcom gemilang + 'picking_type_id': 28, # indoteknik bandengan receipts + 'date_order': current_time, + 'from_apo': True, + 'note_description': 'Automatic PO' + } - self.env['automatic.purchase.match'].create([{ - 'automatic_purchase_id': self.id, - 'order_id': new_po.id - }]) + new_po = self.env['purchase.order'].create([param_header]) - lines = auto_purchase_line.search( - domain, - offset=i * PRODUCT_PER_PO, - limit=PRODUCT_PER_PO - ) + # Set payment_term_id khusus jika diperlukan + if special_payment_term: + new_po.payment_term_id = 29 + else: + new_po.payment_term_id = new_po.partner_id.property_supplier_payment_term_id - lines = auto_purchase_line.search( - domain, - offset=i * PRODUCT_PER_PO, - limit=PRODUCT_PER_PO - ) + new_po.name = new_po.name + name + str(i + 1) + self.env['automatic.purchase.match'].create([{ + 'automatic_purchase_id': self.id, + 'order_id': new_po.id + }]) + + # Ambil baris sesuai halaman + lines = auto_purchase_line.search( + domain, + offset=i * PRODUCT_PER_PO, + limit=PRODUCT_PER_PO + ) + + for line in lines: + product = line.product_id + sales_match = self.env['automatic.purchase.sales.match'].search([ + ('automatic_purchase_id', '=', self.id), + ('product_id', '=', product.id), + ]) + param_line = { + 'order_id': new_po.id, + 'product_id': product.id, + 'product_qty': line.qty_purchase, + 'qty_available_store': product.qty_available_bandengan, + 'suggest': product._get_po_suggest(line.qty_purchase), + 'product_uom_qty': line.qty_purchase, + 'price_unit': line.last_price, + 'ending_price': line.last_price, + 'taxes_id': [line.taxes_id.id] if line.taxes_id else None, + 'so_line_id': sales_match[0].sale_line_id.id if sales_match else None, + 'so_id': sales_match[0].sale_id.id if sales_match else None + } + new_po_line = self.env['purchase.order.line'].create([param_line]) + line.current_po_id = new_po.id + line.current_po_line_id = new_po_line.id + + self.create_purchase_order_sales_match(new_po) + + # Buat PO untuk special brand + if vendor_id == 23: + create_po_for_domain(special_brand_domain, special_payment_term=True) + + # Buat PO untuk regular domain + create_po_for_domain(regular_domain, "") - for line in lines: - product = line.product_id - sales_match = self.env['automatic.purchase.sales.match'].search([ - ('automatic_purchase_id', '=', self.id), - ('product_id', '=', product.id), - ]) - param_line = { - 'order_id': new_po.id, - 'product_id': product.id, - 'product_qty': line.qty_purchase, - 'qty_available_store': product.qty_available_bandengan, - 'suggest': product._get_po_suggest(line.qty_purchase), - 'product_uom_qty': line.qty_purchase, - 'price_unit': line.last_price, - 'ending_price': line.last_price, - 'taxes_id': [line.taxes_id.id] if line.taxes_id else None, - 'so_line_id': sales_match[0].sale_line_id.id if sales_match else None, - 'so_id': sales_match[0].sale_id.id if sales_match else None - } - new_po_line = self.env['purchase.order.line'].create([param_line]) - line.current_po_id = new_po.id - line.current_po_line_id = new_po_line.id - # self.update_purchase_price_so_line(line) - - self.create_purchase_order_sales_match(new_po) def update_purchase_price_so_line(self, apo): sales_match = self.env['automatic.purchase.sales.match'].search([ -- cgit v1.2.3 From 364eb8f589e5070c06e10bb5895e20e69dad8249 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 28 Jan 2025 15:23:38 +0700 Subject: add shipping_method_picking on sale order --- indoteknik_custom/models/sale_order.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 48195b77..98468c4b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -144,6 +144,15 @@ class SaleOrder(models.Model): ('PNR', 'Pareto Non Repeating'), ('NP', 'Non Pareto') ]) + shipping_method_picking = fields.Char(string='Shipping Method Picking', compute='_compute_shipping_method_picking') + + def _compute_shipping_method_picking(self): + for order in self: + if order.picking_ids: + carrier_names = order.picking_ids.mapped('carrier_id.name') + order.shipping_method_picking = ', '.join(filter(None, carrier_names)) + else: + order.shipping_method_picking = False @api.onchange('payment_status') def _is_continue_transaction(self): -- cgit v1.2.3 From 888c71b3a5fe4ff4a338a2d13718b8624b1348d6 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 30 Jan 2025 09:32:05 +0700 Subject: update ambil tempo duration tempo --- indoteknik_custom/models/user_pengajuan_tempo_request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index 8023dfa7..29cf391c 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -71,7 +71,7 @@ class UserPengajuanTempoRequest(models.Model): website_tempo = fields.Char(string='Website', related='pengajuan_tempo_id.website_tempo', store=True, tracking=True, readonly=False) portal = fields.Boolean(string='Portal Website', related='pengajuan_tempo_id.portal', store=True, tracking=True, readonly=False) estimasi_tempo = fields.Char(string='Estimasi Pembelian Pertahun', related='pengajuan_tempo_id.estimasi_tempo', store=True, tracking=True, readonly=False) - tempo_duration_origin = fields.Many2one('account.payment.term', string='Durasi Tempo', related='pengajuan_tempo_id.tempo_duration', store=True, tracking=True, readonly=False, domain=[('id', 'in', [24, 25, 29, 32])]) + tempo_duration_origin = fields.Many2one('account.payment.term', string='Durasi Tempo', related='tempo_duration', store=True, tracking=True, readonly=False, domain=[('id', 'in', [24, 25, 29, 32])]) tempo_limit_origin = fields.Char(string='Limit Tempo', related='pengajuan_tempo_id.tempo_limit' , store=True, tracking=True, readonly=False) category_produk_ids = fields.Many2many('product.public.category', string='Kategori Produk yang Digunakan', related='pengajuan_tempo_id.category_produk_ids', readonly=False) @@ -596,7 +596,7 @@ class UserPengajuanTempoRequest(models.Model): attachment_ids=[self.user_company_id.dokumen_tempat_bekerja.id]) # self.user_company_id.active = True # user.send_company_request_approve_mail() - self.user_company_id.property_payment_term_id = self.pengajuan_tempo_id.tempo_duration.id + self.user_company_id.property_payment_term_id = self.tempo_duration.id self.user_company_id.active_limit = True self.user_company_id.warning_stage = float(limit_tempo) - (float(limit_tempo)/2) self.user_company_id.blocking_stage = limit_tempo -- cgit v1.2.3 From dcbd88ea9ea1977c047425e31559fb2e5cee3de2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 10:53:45 +0700 Subject: add validation on write and create function --- indoteknik_custom/models/product_template.py | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 29608297..d4b0abf4 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -67,6 +67,23 @@ class ProductTemplate(models.Model): print_barcode = fields.Boolean(string='Print Barcode', default=True) # qr_code = fields.Binary("QR Code", compute='_compute_qr_code') + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductTemplate, self).create(vals) + return result + + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductTemplate, self).write(values) + return result + # def _compute_qr_code(self): # for rec in self.product_variant_ids: # qr = qrcode.QRCode( @@ -403,6 +420,23 @@ class ProductProduct(models.Model): merchandise_ok = fields.Boolean(string='Product Promotion') qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductProduct, self).create(vals) + return result + + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductProduct, self).write(values) + return result + def _compute_qr_code_variant(self): for rec in self: # Skip inactive variants -- cgit v1.2.3 From f50f7d570eaa66552e6e91cfd9a29942a7ea3c36 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 11:00:36 +0700 Subject: fix bug --- indoteknik_custom/models/product_template.py | 60 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index d4b0abf4..151513e8 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -67,22 +67,22 @@ class ProductTemplate(models.Model): print_barcode = fields.Boolean(string='Print Barcode', default=True) # qr_code = fields.Binary("QR Code", compute='_compute_qr_code') - @api.model - def create(self, vals): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa membuat Product') - result = super(ProductTemplate, self).create(vals) - return result + # @api.model + # def create(self, vals): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa membuat Product') + # result = super(ProductTemplate, self).create(vals) + # return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductTemplate, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductTemplate, self).write(values) + # return result # def _compute_qr_code(self): # for rec in self.product_variant_ids: @@ -420,22 +420,22 @@ class ProductProduct(models.Model): merchandise_ok = fields.Boolean(string='Product Promotion') qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') - @api.model - def create(self, vals): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa membuat Product') - result = super(ProductProduct, self).create(vals) - return result + # @api.model + # def create(self, vals): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa membuat Product') + # result = super(ProductProduct, self).create(vals) + # return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductProduct, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductProduct, self).write(values) + # return result def _compute_qr_code_variant(self): for rec in self: -- cgit v1.2.3 From 2ceef7e7e73a91ee513787071ba4537c7c263349 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 11:37:15 +0700 Subject: fix bug validation create and write --- indoteknik_custom/models/product_template.py | 64 +++++++++++++++------------- 1 file changed, 34 insertions(+), 30 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 151513e8..99a89d74 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -67,22 +67,24 @@ class ProductTemplate(models.Model): print_barcode = fields.Boolean(string='Print Barcode', default=True) # qr_code = fields.Binary("QR Code", compute='_compute_qr_code') - # @api.model - # def create(self, vals): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa membuat Product') - # result = super(ProductTemplate, self).create(vals) - # return result + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + active_model = self.env.context.get('active_model') + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductTemplate, self).create(vals) + return result - # def write(self, values): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa mengedit Product') - # result = super(ProductTemplate, self).write(values) - # return result + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + active_model = self.env.context.get('active_model') + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductTemplate, self).write(values) + return result # def _compute_qr_code(self): # for rec in self.product_variant_ids: @@ -420,22 +422,24 @@ class ProductProduct(models.Model): merchandise_ok = fields.Boolean(string='Product Promotion') qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') - # @api.model - # def create(self, vals): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa membuat Product') - # result = super(ProductProduct, self).create(vals) - # return result + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + active_model = self.env.context.get('active_model') + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductProduct, self).create(vals) + return result - # def write(self, values): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa mengedit Product') - # result = super(ProductProduct, self).write(values) - # return result + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + active_model = self.env.context.get('active_model') + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductProduct, self).write(values) + return result def _compute_qr_code_variant(self): for rec in self: -- cgit v1.2.3 From b0152e913e55d4061abe1a0e96c558f62a99a830 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 13:48:19 +0700 Subject: cr on account move line and add tracking on shipping paid by and shipping covered by on sale order --- indoteknik_custom/models/account_move_line.py | 6 ++++++ indoteknik_custom/models/sale_order.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index a4b25109..c4a65209 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -7,6 +7,12 @@ class AccountMoveLine(models.Model): cost_centre_id = fields.Many2one('cost.centre', string='Cost Centre') is_required = fields.Boolean(string='Is Required', compute='_compute_is_required') analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account') + line_no = fields.Integer('No', default=0, compute='_compute_line_no') + + def _compute_line_no(self): + if self.move_id: + for index, line in enumerate(self.move_id.invoice_line_ids, start=1): + line.line_no = index @api.onchange('account_id') def _onchange_account_id(self): diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 98468c4b..132aa397 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -28,11 +28,11 @@ class SaleOrder(models.Model): shipping_cost_covered = fields.Selection([ ('indoteknik', 'Indoteknik'), ('customer', 'Customer') - ], string='Shipping Covered by', help='Siapa yang menanggung biaya ekspedisi?', copy=False) + ], string='Shipping Covered by', help='Siapa yang menanggung biaya ekspedisi?', copy=False, tracking=3) shipping_paid_by = fields.Selection([ ('indoteknik', 'Indoteknik'), ('customer', 'Customer') - ], string='Shipping Paid by', help='Siapa yang talangin dulu Biaya ekspedisi-nya?', copy=False) + ], string='Shipping Paid by', help='Siapa yang talangin dulu Biaya ekspedisi-nya?', copy=False, tracking=3) sales_tax_id = fields.Many2one('account.tax', string='Tax', domain=['|', ('active', '=', False), ('active', '=', True)]) have_outstanding_invoice = fields.Boolean('Have Outstanding Invoice', compute='_have_outstanding_invoice') have_outstanding_picking = fields.Boolean('Have Outstanding Picking', compute='_have_outstanding_picking') -- cgit v1.2.3 From f1927a4220d546756bc3a1cc5666aa2ef2c8d816 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 14:59:15 +0700 Subject: fix bug --- indoteknik_custom/models/product_template.py | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 99a89d74..efacb95f 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -77,14 +77,14 @@ class ProductTemplate(models.Model): result = super(ProductTemplate, self).create(vals) return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - active_model = self.env.context.get('active_model') - if self.env.user.id not in users_in_group.mapped('id') and active_model == None: - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductTemplate, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # active_model = self.env.context.get('active_model') + # if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductTemplate, self).write(values) + # return result # def _compute_qr_code(self): # for rec in self.product_variant_ids: @@ -432,14 +432,14 @@ class ProductProduct(models.Model): result = super(ProductProduct, self).create(vals) return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - active_model = self.env.context.get('active_model') - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id') and active_model == None: - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductProduct, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # active_model = self.env.context.get('active_model') + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductProduct, self).write(values) + # return result def _compute_qr_code_variant(self): for rec in self: -- cgit v1.2.3 From b547143489e5bef27425199b36a9dd3984429421 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 15:35:20 +0700 Subject: label entries line same with ref move entry --- indoteknik_custom/models/account_move.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 85ed1d54..7760c69d 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -65,6 +65,13 @@ class AccountMove(models.Model): other_subtotal = fields.Float(string="Other Subtotal", compute='compute_other_subtotal') other_taxes = fields.Float(string="Other Taxes", compute='compute_other_taxes') + def _update_line_name_from_ref(self): + """Update all account.move.line name fields with ref from account.move""" + for move in self: + if move.move_type == 'entry' and move.ref and move.line_ids: + for line in move.line_ids: + line.name = move.ref + def compute_other_taxes(self): for rec in self: rec.other_taxes = rec.other_subtotal * 0.12 @@ -107,6 +114,7 @@ class AccountMove(models.Model): def create(self, vals): vals['nomor_kwitansi'] = self.env['ir.sequence'].next_by_code('nomor.kwitansi') or '0' result = super(AccountMove, self).create(vals) + result._update_line_name_from_ref() return result def compute_so_shipping_paid_by(self): -- cgit v1.2.3 From d7a18a90adc0502831eabd1e5940677161ddd4bf Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 16:56:07 +0700 Subject: add filter searching picking on report logbook sj --- indoteknik_custom/models/report_logbook_sj.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py index a1b6299c..17119c12 100644 --- a/indoteknik_custom/models/report_logbook_sj.py +++ b/indoteknik_custom/models/report_logbook_sj.py @@ -29,6 +29,8 @@ class ReportLogbookSJ(models.Model): string='Status', tracking=True, ) + + sj_number = fields.Char(string='Picking', related='report_logbook_sj_line.name') count_line = fields.Char(string='Count Line', compute='_compute_count_line') -- cgit v1.2.3 From de4404c4b60b0859a4cbae836cc4c99d806bf697 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 31 Jan 2025 10:01:49 +0700 Subject: fix bug --- indoteknik_custom/models/account_move_line.py | 2 +- indoteknik_custom/models/stock_picking.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index c4a65209..9ab9620b 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -10,7 +10,7 @@ class AccountMoveLine(models.Model): line_no = fields.Integer('No', default=0, compute='_compute_line_no') def _compute_line_no(self): - if self.move_id: + if self.move_id and self.move_id.move_type == 'out_invoice': for index, line in enumerate(self.move_id.invoice_line_ids, start=1): line.line_no = index diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index cc86c451..9af74cd3 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -467,7 +467,7 @@ class StockPicking(models.Model): def check_state_reserve(self): pickings = self.search([ - ('state', 'not in', ['cancel', 'draft', 'done']), + ('state', 'not in', ['cancel', 'done']), ('picking_type_code', '=', 'outgoing') ]) -- cgit v1.2.3 From c131fcf6f0fd3aa8bd4d3a241aabe577bbf57137 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 31 Jan 2025 10:19:45 +0700 Subject: fix bug --- indoteknik_custom/models/account_move_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 9ab9620b..c4a65209 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -10,7 +10,7 @@ class AccountMoveLine(models.Model): line_no = fields.Integer('No', default=0, compute='_compute_line_no') def _compute_line_no(self): - if self.move_id and self.move_id.move_type == 'out_invoice': + if self.move_id: for index, line in enumerate(self.move_id.invoice_line_ids, start=1): line.line_no = index -- cgit v1.2.3 From 9b4b186d5ac43f1e823ddf37d60f37980f3e721c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 31 Jan 2025 10:27:51 +0700 Subject: fix bug --- indoteknik_custom/models/account_move_line.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index c4a65209..568c9b85 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -9,9 +9,10 @@ class AccountMoveLine(models.Model): analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account') line_no = fields.Integer('No', default=0, compute='_compute_line_no') + @api.depends('move_id.invoice_line_ids') def _compute_line_no(self): - if self.move_id: - for index, line in enumerate(self.move_id.invoice_line_ids, start=1): + for move in self.mapped('move_id'): + for index, line in enumerate(move.invoice_line_ids, start=1): line.line_no = index @api.onchange('account_id') -- cgit v1.2.3 From 8cba896edb13b2b2911e487aea562553d3b17025 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 31 Jan 2025 10:34:41 +0700 Subject: trying to fix bug --- indoteknik_custom/models/account_move_line.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 568c9b85..3c352560 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -12,9 +12,12 @@ class AccountMoveLine(models.Model): @api.depends('move_id.invoice_line_ids') def _compute_line_no(self): for move in self.mapped('move_id'): - for index, line in enumerate(move.invoice_line_ids, start=1): - line.line_no = index - + if move.move_type == 'out_invoice' and move.invoice_line_ids: + for index, line in enumerate(move.invoice_line_ids, start=1): + line.line_no = index + else: + for index, line in enumerate(move.line_ids, start=1): + line.line_no = index @api.onchange('account_id') def _onchange_account_id(self): for account in self: -- cgit v1.2.3 From 57b2ce27d2892f04e0503ac4543d23245bee639e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 31 Jan 2025 11:00:25 +0700 Subject: fix bug --- indoteknik_custom/models/account_move_line.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 3c352560..37f7c77c 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -7,17 +7,8 @@ class AccountMoveLine(models.Model): cost_centre_id = fields.Many2one('cost.centre', string='Cost Centre') is_required = fields.Boolean(string='Is Required', compute='_compute_is_required') analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account') - line_no = fields.Integer('No', default=0, compute='_compute_line_no') + line_no = fields.Integer('No', default=0) - @api.depends('move_id.invoice_line_ids') - def _compute_line_no(self): - for move in self.mapped('move_id'): - if move.move_type == 'out_invoice' and move.invoice_line_ids: - for index, line in enumerate(move.invoice_line_ids, start=1): - line.line_no = index - else: - for index, line in enumerate(move.line_ids, start=1): - line.line_no = index @api.onchange('account_id') def _onchange_account_id(self): for account in self: -- cgit v1.2.3 From b4249a4dbed1f982ce2355ea7b8245dd1c44da8d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 31 Jan 2025 11:20:33 +0700 Subject: fix send mail bills --- indoteknik_custom/models/stock_immediate_transfer.py | 1 - indoteknik_custom/models/stock_picking.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_immediate_transfer.py b/indoteknik_custom/models/stock_immediate_transfer.py index 4be0dff2..21210619 100644 --- a/indoteknik_custom/models/stock_immediate_transfer.py +++ b/indoteknik_custom/models/stock_immediate_transfer.py @@ -16,7 +16,6 @@ class StockImmediateTransfer(models.TransientModel): pickings_not_to_do |= line.picking_id for picking in pickings_to_do: - picking.send_mail_bills() # If still in draft => confirm and assign if picking.state == 'draft': picking.action_confirm() diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 9af74cd3..ce198be3 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -811,6 +811,7 @@ class StockPicking(models.Model): self.calculate_line_no() self.date_done = datetime.datetime.utcnow() self.state_reserve = 'done' + self.send_mail_bills() return res -- cgit v1.2.3 From dd0158651c5fa665cde6c534e7f4283f86adafc9 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 3 Feb 2025 14:46:38 +0700 Subject: add type on barcoding product --- indoteknik_custom/models/barcoding_product.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index 6bbf9fde..e1b8f41f 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -12,6 +12,14 @@ class BarcodingProduct(models.Model): barcoding_product_line = fields.One2many('barcoding.product.line', 'barcoding_product_id', string='Barcoding Product Lines', auto_join=True) product_id = fields.Many2one('product.product', string="Product", tracking=3) quantity = fields.Float(string="Quantity", tracking=3) + type = fields.Selection([('print', 'Print Barcode'), ('barcoding', 'Add Barcode To Product')], string='Type', default='print') + barcode = fields.Char(string="Barcode") + + @api.constrains('barcode') + def _send_barcode_to_product(self): + for record in self: + if record.barcode and not record.product_id.barcode: + record.product_id.barcode = record.barcode @api.onchange('product_id', 'quantity') def _onchange_product_or_quantity(self): -- cgit v1.2.3 From 8cf663b15d39a04df97b3ef13f76b407ca6b7004 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Tue, 4 Feb 2025 08:55:01 +0700 Subject: xoretax xml add code barang --- indoteknik_custom/models/coretax_fatur.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/coretax_fatur.py b/indoteknik_custom/models/coretax_fatur.py index ae6dd2ae..706a4f44 100644 --- a/indoteknik_custom/models/coretax_fatur.py +++ b/indoteknik_custom/models/coretax_fatur.py @@ -77,7 +77,7 @@ class CoretaxFaktur(models.Model): otherTaxBase = round(line.price_subtotal * (11/12)) if line.price_subtotal else 0 good_service = ET.SubElement(list_of_good_service, 'GoodService') ET.SubElement(good_service, 'Opt').text = 'A' - ET.SubElement(good_service, 'Code') + ET.SubElement(good_service, 'Code').text = '000000' ET.SubElement(good_service, 'Name').text = line.name ET.SubElement(good_service, 'Unit').text = 'UM.0018' ET.SubElement(good_service, 'Price').text = str(round(line.price_subtotal/line.quantity, 2)) if line.price_subtotal else '0' -- cgit v1.2.3 From 0bf3a1d1db07ee8306d81443cc4dba94b3740808 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 4 Feb 2025 15:35:41 +0700 Subject: update code sale order --- indoteknik_custom/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 132aa397..4bdd9f2c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -980,6 +980,7 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: + order.check_credit_limit() if self.validate_different_vendor() and not self.vendor_approval: return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') -- cgit v1.2.3 From 43d859b6c51697a8cff9f543154934ea045d1378 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 6 Feb 2025 10:06:40 +0700 Subject: ubah logic warning limit --- indoteknik_custom/models/user_pengajuan_tempo_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index 29cf391c..b6103bbb 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -598,8 +598,8 @@ class UserPengajuanTempoRequest(models.Model): # user.send_company_request_approve_mail() self.user_company_id.property_payment_term_id = self.tempo_duration.id self.user_company_id.active_limit = True - self.user_company_id.warning_stage = float(limit_tempo) - (float(limit_tempo)/2) self.user_company_id.blocking_stage = limit_tempo + self.user_company_id.warning_stage = float(limit_tempo) - (float(limit_tempo)/2) # Internal Notes comment = [] -- cgit v1.2.3 From f78fcf1c60160540221e240338acc54dfc9beb74 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 6 Feb 2025 11:22:06 +0700 Subject: add po count on po and add validation duplicate contact --- indoteknik_custom/models/purchase_order.py | 1 + indoteknik_custom/models/res_partner.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 12a94730..54d771ba 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -86,6 +86,7 @@ class PurchaseOrder(models.Model): total_cost_service = fields.Float(string='Total Cost Service') total_delivery_amt = fields.Float(string='Total Delivery Amt') store_name = fields.Char(string='Nama Toko') + purchase_order_count = fields.Integer('Purchase Order Count', related='partner_id.purchase_order_count') @api.onchange('total_cost_service') def _onchange_total_cost_service(self): diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 5322515a..3c5e0e05 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -183,6 +183,19 @@ class ResPartner(models.Model): # # raise UserError('You name it') # return res + + @api.constrains('name') + def _check_duplicate_name(self): + for record in self: + if record.name: + # Mencari partner lain yang memiliki nama sama (case-insensitive) + existing_partner = self.env['res.partner'].search([ + ('id', '!=', record.id), # Hindari mencocokkan diri sendiri + ('name', 'ilike', record.name) # Case-insensitive search + ], limit=1) + + if existing_partner: + raise ValidationError(f"Nama '{record.name}' sudah digunakan oleh partner lain!") def write(self, vals): # Fungsi rekursif untuk meng-update semua child, termasuk child dari child -- cgit v1.2.3 From 11ef44bdb2695125048fe7fcfea25dbf459a3d9e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 6 Feb 2025 13:14:25 +0700 Subject: add levenshtein to duplikat name contact alert --- indoteknik_custom/models/res_partner.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 3c5e0e05..844d47f9 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -188,14 +188,17 @@ class ResPartner(models.Model): def _check_duplicate_name(self): for record in self: if record.name: - # Mencari partner lain yang memiliki nama sama (case-insensitive) - existing_partner = self.env['res.partner'].search([ - ('id', '!=', record.id), # Hindari mencocokkan diri sendiri - ('name', 'ilike', record.name) # Case-insensitive search - ], limit=1) - - if existing_partner: - raise ValidationError(f"Nama '{record.name}' sudah digunakan oleh partner lain!") + query = """ + SELECT name FROM res_partner + WHERE id != %s + AND levenshtein(lower(name), lower(%s)) <= 1 + LIMIT 1 + """ + self.env.cr.execute(query, (record.id, record.name)) + duplicate = self.env.cr.fetchone() + + if duplicate: + raise ValidationError(f"Nama '{record.name}' mirip dengan '{duplicate[0]}', harap gunakan nama yang unik!") def write(self, vals): # Fungsi rekursif untuk meng-update semua child, termasuk child dari child -- cgit v1.2.3 From 1abbebda5ab707b014e8e01a7ab418861beef420 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 6 Feb 2025 16:40:34 +0700 Subject: cr validation duplicate contact --- indoteknik_custom/models/res_partner.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 844d47f9..7e574a72 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -188,17 +188,14 @@ class ResPartner(models.Model): def _check_duplicate_name(self): for record in self: if record.name: - query = """ - SELECT name FROM res_partner - WHERE id != %s - AND levenshtein(lower(name), lower(%s)) <= 1 - LIMIT 1 - """ - self.env.cr.execute(query, (record.id, record.name)) - duplicate = self.env.cr.fetchone() - - if duplicate: - raise ValidationError(f"Nama '{record.name}' mirip dengan '{duplicate[0]}', harap gunakan nama yang unik!") + # Mencari partner lain yang memiliki nama sama (case-insensitive) + existing_partner = self.env['res.partner'].search([ + ('id', '!=', record.id), # Hindari mencocokkan diri sendiri + ('name', '=', record.name) # Case-insensitive search + ], limit=1) + + if existing_partner: + raise ValidationError(f"Nama '{record.name}' sudah digunakan oleh partner lain!") def write(self, vals): # Fungsi rekursif untuk meng-update semua child, termasuk child dari child -- cgit v1.2.3 From 3187466a66abb41931e346e7865dfa6432f3da9e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 7 Feb 2025 14:24:02 +0700 Subject: add chek kredit limit tapi ditambah dengan so yang to invoice --- indoteknik_custom/models/sale_order.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 4bdd9f2c..0d2e42cb 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -768,6 +768,7 @@ class SaleOrder(models.Model): def sale_order_approve(self): self.check_credit_limit() + self.check_limit_so_to_invoice() if self.validate_different_vendor() and not self.vendor_approval: return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') self.check_due() @@ -826,6 +827,7 @@ class SaleOrder(models.Model): return self._create_approval_notification('Pimpinan') elif order._requires_approval_margin_manager(): self.check_credit_limit() + self.check_limit_so_to_invoice() order.approval_status = 'pengajuan1' return self._create_approval_notification('Sales Manager') @@ -932,6 +934,28 @@ class SaleOrder(models.Model): raise UserError(_("%s is in Blocking Stage, Remaining credit limit is %s, from %s and outstanding %s") % (rec.partner_id.name, remaining_credit_limit, block_stage, outstanding_amount)) + def check_limit_so_to_invoice(self): + for rec in self: + # Ambil jumlah outstanding_amount dan rec.amount_total sebagai current_total + outstanding_amount = rec.outstanding_amount + current_total = rec.amount_total + outstanding_amount + + # Ambil blocking stage dari partner + block_stage = rec.partner_id.parent_id.blocking_stage if rec.partner_id.parent_id else rec.partner_id.blocking_stage or 0 + + # Ambil jumlah nilai dari SO yang invoice_status masih 'to invoice' + so_to_invoice = 0 + for sale in rec.partner_id.sale_order_ids: + if sale.invoice_status == 'to invoice': + so_to_invoice = so_to_invoice + sale.amount_total + # Hitung remaining credit limit + remaining_credit_limit = block_stage - current_total - so_to_invoice + + # Validasi limit + if remaining_credit_limit <= 0: + raise UserError(_("The credit limit for %s will exceed the Blocking Stage if the Sale Order is confirmed. The remaining credit limit is %s, from %s and the outstanding amount is %s.") + % (rec.partner_id.name, block_stage - current_total, block_stage, outstanding_amount)) + def validate_different_vendor(self): if self.vendor_approval_id.filtered(lambda v: v.state == 'draft'): draft_names = ", ".join(self.vendor_approval_id.filtered(lambda v: v.state == 'draft').mapped('number')) @@ -981,6 +1005,7 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: order.check_credit_limit() + order.check_limit_so_to_invoice() if self.validate_different_vendor() and not self.vendor_approval: return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') -- cgit v1.2.3 From ae66937628c5431274df26183674cad52f90c029 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 7 Feb 2025 14:57:43 +0700 Subject: disallow some state while cancel sales order --- indoteknik_custom/models/sale_order.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 0d2e42cb..2f3871ad 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1067,9 +1067,14 @@ class SaleOrder(models.Model): if self.have_outstanding_invoice: raise UserError("Invoice harus di Cancel dahulu") + + disallow_states = ['draft', 'waiting', 'confirmed', 'assigned'] + for picking in self.picking_ids: + if picking.state in disallow_states: + raise UserError("DO yang draft, waiting, confirmed, atau assigned harus di-cancel oleh Logistik") for line in self.order_line: if line.qty_delivered > 0: - raise UserError("DO harus di-cancel terlebih dahulu.") + raise UserError("DO yang done harus di-Return oleh Logistik") if not self.web_approval: self.web_approval = 'company' -- cgit v1.2.3 From e960a38aa69fbd7a75b6f06a3b30967d8b20ddd5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 10 Feb 2025 09:45:03 +0700 Subject: fix bug create payment link --- indoteknik_custom/models/sale_order.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 2f3871ad..5c223beb 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -549,22 +549,22 @@ class SaleOrder(models.Model): redirect_url = json.loads(lookup_json)['redirect_url'] self.payment_link_midtrans = str(redirect_url) - # Generate QR code - qr = qrcode.QRCode( - version=1, - error_correction=qrcode.constants.ERROR_CORRECT_L, - box_size=10, - border=4, - ) - qr.add_data(redirect_url) - qr.make(fit=True) - img = qr.make_image(fill_color="black", back_color="white") - - buffer = BytesIO() - img.save(buffer, format="PNG") - qr_code_img = base64.b64encode(buffer.getvalue()).decode() - - self.payment_qr_code = qr_code_img + if 'redirect_url' in response: + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + qr.add_data(redirect_url) + qr.make(fit=True) + img = qr.make_image(fill_color="black", back_color="white") + + buffer = BytesIO() + img.save(buffer, format="PNG") + qr_code_img = base64.b64encode(buffer.getvalue()).decode() + + self.payment_qr_code = qr_code_img @api.model def _generate_so_access_token(self, limit=50): -- cgit v1.2.3 From 3d5e57a2d892551965bcf079f7c728d00989af8e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 10 Feb 2025 14:05:12 +0700 Subject: update make contak from tempo --- .../models/user_pengajuan_tempo_request.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index b6103bbb..81509df4 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -507,10 +507,20 @@ class UserPengajuanTempoRequest(models.Model): # Buat kontak baru untuk company_id for contact_data in contacts_data: - self.env['res.partner'].create({ - "parent_id": self.user_company_id.id, # Hubungkan ke perusahaan - **contact_data, # Tambahkan data kontak - }) + existing_contact = self.env['res.partner'].search([ + ('parent_id', '=', self.user_company_id.id), + ('name', '=', contact_data['name']) + ], limit=1) + + if existing_contact: + # Perbarui data yang ada + existing_contact.write(contact_data) + else: + # Buat kontak baru jika belum ada + self.env['res.partner'].create({ + "parent_id": self.user_company_id.id, # Hubungkan ke perusahaan + **contact_data, # Tambahkan data kontak + }) # Pengiriman self.user_company_id.pic_name = self.pengajuan_tempo_id.pic_name -- cgit v1.2.3 From 8a29d6ef46d15fbce033b94464e139cabb8aeb68 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 10 Feb 2025 14:23:02 +0700 Subject: update yg sama --- indoteknik_custom/models/user_pengajuan_tempo_request.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index 81509df4..3f960e58 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -513,8 +513,9 @@ class UserPengajuanTempoRequest(models.Model): ], limit=1) if existing_contact: - # Perbarui data yang ada - existing_contact.write(contact_data) + # Perbarui hanya field yang tidak menyebabkan konflik + update_data = {k: v for k, v in contact_data.items() if k != 'name'} + existing_contact.write(update_data) else: # Buat kontak baru jika belum ada self.env['res.partner'].create({ -- cgit v1.2.3 From 1ff643c37772d573b5bf4c1814c85cf442de1863 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 10 Feb 2025 15:05:14 +0700 Subject: update logic add contact tempo(revisi) --- .../models/user_pengajuan_tempo_request.py | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index 3f960e58..0b77cc87 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -513,11 +513,28 @@ class UserPengajuanTempoRequest(models.Model): ], limit=1) if existing_contact: - # Perbarui hanya field yang tidak menyebabkan konflik - update_data = {k: v for k, v in contact_data.items() if k != 'name'} - existing_contact.write(update_data) + # Pastikan tidak ada duplikasi nama dalam perusahaan yang sama + duplicate_check = self.env['res.partner'].search([ + ('name', '=', contact_data['name']), + ('id', '!=', existing_contact.id) # Hindari update yang menyebabkan duplikasi global + ], limit=1) + + if not duplicate_check: + # Perbarui hanya field yang tidak menyebabkan konflik + update_data = {k: v for k, v in contact_data.items() if k != 'name'} + existing_contact.write(update_data) + else: + raise UserError(f"Skipping update for {contact_data['name']} due to existing duplicate.") else: - # Buat kontak baru jika belum ada + # Pastikan tidak ada partner lain dengan nama yang sama sebelum membuat baru + duplicate_check = self.env['res.partner'].search([ + ('name', '=', contact_data['name']) + ], limit=1) + + if duplicate_check: + # Jika nama sudah ada tetapi di perusahaan lain, tambahkan nama perusahaan + contact_data['name'] = f"{contact_data['name']} ({self.user_company_id.name})" + self.env['res.partner'].create({ "parent_id": self.user_company_id.id, # Hubungkan ke perusahaan **contact_data, # Tambahkan data kontak -- cgit v1.2.3 From 84c259bb2c579a0ad1f1593d7d3d7bf57fb732f0 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 10 Feb 2025 16:55:44 +0700 Subject: add tracking reason reject tempo --- indoteknik_custom/models/user_pengajuan_tempo_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index 0b77cc87..e2c08cb2 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -7,7 +7,7 @@ class RejectReasonWizard(models.TransientModel): _description = 'Wizard for Reject Reason' request_id = fields.Many2one('user.pengajuan.tempo.request', string='Request') - reason_reject = fields.Text(string='Reason for Rejection', required=True) + reason_reject = fields.Text(string='Reason for Rejection', required=True, tracking=True) def confirm_reject(self): tempo = self.request_id -- cgit v1.2.3 From e7eadc269299d03f6eb0702459147a2900b982b4 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 11 Feb 2025 09:03:25 +0700 Subject: update code blocking state --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5c223beb..9631fe6e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -952,7 +952,7 @@ class SaleOrder(models.Model): remaining_credit_limit = block_stage - current_total - so_to_invoice # Validasi limit - if remaining_credit_limit <= 0: + if remaining_credit_limit <= 0 and block_stage > 0: raise UserError(_("The credit limit for %s will exceed the Blocking Stage if the Sale Order is confirmed. The remaining credit limit is %s, from %s and the outstanding amount is %s.") % (rec.partner_id.name, block_stage - current_total, block_stage, outstanding_amount)) -- cgit v1.2.3 From 751645803b13cbc96d4a554a9c9d8a63cd991486 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 11 Feb 2025 13:45:07 +0700 Subject: fix bug state reserve --- indoteknik_custom/models/stock_picking.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index ce198be3..b1b1bdb8 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -467,19 +467,19 @@ class StockPicking(models.Model): def check_state_reserve(self): pickings = self.search([ - ('state', 'not in', ['cancel', 'done']), + ('state', 'not in', ['cancel', 'draft', 'done']), ('picking_type_code', '=', 'outgoing') ]) for picking in pickings: - fullfillments = self.env['sales.order.fullfillment'].search([ - ('sales_order_id', '=', picking.sale_id.id) + fullfillments = self.env['sales.order.fulfillment.v2'].search([ + ('sale_order_id', '=', picking.sale_id.id) ]) picking.state_reserve = 'ready' picking.date_reserved = picking.date_reserved or datetime.datetime.utcnow() - if any(rec.reserved_from not in ['Inventory On Hand', 'Reserved from stock', 'Free Stock'] for rec in fullfillments): + if any(rec.so_qty != rec.reserved_stock_qty for rec in fullfillments): picking.state_reserve = 'waiting' picking.date_reserved = '' -- cgit v1.2.3 From eeff963c94f4d933b89308f40b387fd67ef881c4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 11 Feb 2025 16:18:57 +0700 Subject: fix bug backorder state reserve --- indoteknik_custom/models/stock_picking.py | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index b1b1bdb8..f49c493c 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -470,6 +470,38 @@ class StockPicking(models.Model): ('state', 'not in', ['cancel', 'draft', 'done']), ('picking_type_code', '=', 'outgoing') ]) + + count = self.search_count([ + ('state', 'not in', ['cancel', 'draft', 'done']), + ('picking_type_code', '=', 'outgoing') + ]) + + for picking in pickings: + fullfillments = self.env['sales.order.fulfillment.v2'].search([ + ('sale_order_id', '=', picking.sale_id.id) + ]) + + picking.state_reserve = 'ready' + picking.date_reserved = picking.date_reserved or datetime.datetime.utcnow() + + if any(rec.so_qty != rec.reserved_stock_qty for rec in fullfillments): + picking.state_reserve = 'waiting' + picking.date_reserved = '' + + self.check_state_reserve_backorder() + + def check_state_reserve_backorder(self): + pickings = self.search([ + ('backorder_id', '!=', False), + ('picking_type_code', '=', 'outgoing'), + ('state', 'not in', ['cancel', 'draft', 'done']) + ]) + + count = self.search_count([ + ('backorder_id', '!=', False), + ('picking_type_code', '=', 'outgoing'), + ('state', 'not in', ['cancel', 'draft', 'done']) + ]) for picking in pickings: fullfillments = self.env['sales.order.fulfillment.v2'].search([ -- cgit v1.2.3 From ee106a0245fe05c3b5341e7c0f2606d7c5adb8de Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 11 Feb 2025 16:40:46 +0700 Subject: add tracking reason reject and reset to draft --- indoteknik_custom/models/user_pengajuan_tempo_request.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index e2c08cb2..4a1994fb 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -55,7 +55,14 @@ class UserPengajuanTempoRequest(models.Model): ('approval_director', 'Approved by Director'), ('reject', 'Rejected'), ], string='Status', readonly=True, copy=False, index=True, track_visibility='onchange', default='draft') - reason_reject = fields.Char(string='Limit Tempo') + last_state_tempo = fields.Selection([ + ('draft', 'Pengajuan Tempo'), + ('approval_sales', 'Approved by Sales Manager'), + ('approval_finance', 'Approved by Finance'), + ('approval_director', 'Approved by Director'), + ('reject', 'Rejected'), + ], string='Status',) + reason_reject = fields.Char(string='Reason Reaject', tracking=True, track_visibility='onchange') # informasi perusahaan name_tempo = fields.Many2one('res.partner', string='Nama Perusahaan', related='pengajuan_tempo_id.name_tempo', store=True, tracking=True, readonly=False) @@ -409,6 +416,9 @@ class UserPengajuanTempoRequest(models.Model): 'target': 'new', 'context': {'default_request_id': self.id}, } + def button_draft(self): + for tempo in self: + tempo.state_tempo = tempo.last_state_tempo if tempo.last_state_tempo else 'draft' def write(self, vals): is_approve = True if self.state_tempo == 'approval_director' or vals.get('state_tempo') == 'approval_director' else False -- cgit v1.2.3 From 1c42539aeb53207b07bde3030d2316b58c2cf81e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 12 Feb 2025 09:41:59 +0700 Subject: trying to fix bug state reserve --- indoteknik_custom/models/stock_picking.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index f49c493c..49e66786 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -468,7 +468,8 @@ class StockPicking(models.Model): def check_state_reserve(self): pickings = self.search([ ('state', 'not in', ['cancel', 'draft', 'done']), - ('picking_type_code', '=', 'outgoing') + ('picking_type_code', '=', 'outgoing'), + ('name', 'ilike', 'BU/OUT/'), ]) count = self.search_count([ @@ -493,6 +494,7 @@ class StockPicking(models.Model): def check_state_reserve_backorder(self): pickings = self.search([ ('backorder_id', '!=', False), + ('name', 'ilike', 'BU/OUT/'), ('picking_type_code', '=', 'outgoing'), ('state', 'not in', ['cancel', 'draft', 'done']) ]) -- cgit v1.2.3 From 3a53992e940724ccb1fbd72329c2db810b8fc83d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 13 Feb 2025 10:43:29 +0700 Subject: fix delete create company when reject company request --- indoteknik_custom/models/user_company_request.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py index af8a86ba..9216e8eb 100644 --- a/indoteknik_custom/models/user_company_request.py +++ b/indoteknik_custom/models/user_company_request.py @@ -104,9 +104,9 @@ class UserCompanyRequest(models.Model): self.user_company_id.active = True user.send_company_switch_approve_mail() if vals.get('is_switch_account') == True else user.send_company_request_approve_mail() else: - new_company = self.env['res.partner'].create({ - 'name': self.user_input - }) + # new_company = self.env['res.partner'].create({ + # 'name': self.user_input + # }) # self.user_id.parent_id = new_company.id user.send_company_request_reject_mail() return super(UserCompanyRequest, self).write(vals) -- cgit v1.2.3 From 3474af21127db27f1b63ddb879e26da232e2e3d0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 13 Feb 2025 11:05:51 +0700 Subject: cr get validate purchase price --- indoteknik_custom/models/sale_order_line.py | 36 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index aed95aab..abf10f42 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -159,7 +159,7 @@ class SaleOrderLine(models.Model): # [('vendor_id', '=', self.product_id.x_manufacture.override_vendor_id.id), # ('product_id', '=', self.product_id.id)], # limit=1, order='count_trx_po desc, count_trx_po_vendor desc') - price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id) + price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id, manual=True) self.purchase_price = price self.purchase_tax_id = taxes # else: @@ -205,37 +205,46 @@ class SaleOrderLine(models.Model): def _get_purchase_price(self, product_id): purchase_price = self.env['purchase.pricelist'].search( [('product_id', '=', product_id.id), - ('is_winner', '=', True)], + # ('is_winner', '=', True) + ], limit=1) + + vendor_id = purchase_price.brand_id.override_vendor_id + if vendor_id: + return self._get_purchase_price_by_vendor(product_id, vendor_id) + return self._get_valid_purchase_price(purchase_price) - def _get_purchase_price_by_vendor(self, product_id, vendor_id): + def _get_purchase_price_by_vendor(self, product_id, vendor_id, manual=False): purchase_price = self.env['purchase.pricelist'].search( [('product_id', '=', product_id.id), - ('vendor_id', '=', vendor_id.id), - # ('is_winner', '=', True) - ], - limit=1) + ('vendor_id', '=', vendor_id.id)], + limit=1 + ) + + if purchase_price: + return self._get_valid_purchase_price(purchase_price, manual) + + # Return default values when no purchase_price is found + return 0, '', None # Ensure 3 values are always returned - return self._get_valid_purchase_price(purchase_price) - def _get_valid_purchase_price(self, purchase_price): + def _get_valid_purchase_price(self, purchase_price, manual): current_time = datetime.now() delta_time = current_time - timedelta(days=365) # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') price = 0 taxes = '' - vendor_id = '' + vendor_id = purchase_price.vendor_id.id or '' human_last_update = purchase_price.human_last_update or datetime.min system_last_update = purchase_price.system_last_update or datetime.min if purchase_price.taxes_product_id.type_tax_use == 'purchase': price = purchase_price.product_price taxes = purchase_price.taxes_product_id.id - vendor_id = purchase_price.vendor_id.id - if delta_time > human_last_update: + if delta_time > human_last_update or (not purchase_price.brand_id.override_vendor_id and manual == False): price = 0 taxes = '' vendor_id = '' @@ -244,8 +253,7 @@ class SaleOrderLine(models.Model): if purchase_price.taxes_system_id.type_tax_use == 'purchase': price = purchase_price.system_price taxes = purchase_price.taxes_system_id.id - vendor_id = purchase_price.vendor_id.id - if delta_time > system_last_update: + if delta_time > human_last_update or (not purchase_price.brand_id.override_vendor_id and manual == False): price = 0 taxes = '' vendor_id = '' -- cgit v1.2.3 From dce36bb896e89a763b182924b0cfa9cec4f39735 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 13 Feb 2025 12:34:21 +0700 Subject: fix bug --- indoteknik_custom/models/sale_order_line.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index abf10f42..af521c2c 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -202,19 +202,19 @@ class SaleOrderLine(models.Model): # self.price_unit = selling_price # self.tax_id = tax_id - def _get_purchase_price(self, product_id): + def _get_purchase_price(self, product_id, manual=False): purchase_price = self.env['purchase.pricelist'].search( - [('product_id', '=', product_id.id), - # ('is_winner', '=', True) - ], - limit=1) + [('product_id', '=', product_id.id)], + limit=1 + ) vendor_id = purchase_price.brand_id.override_vendor_id if vendor_id: - return self._get_purchase_price_by_vendor(product_id, vendor_id) - - return self._get_valid_purchase_price(purchase_price) + return self._get_purchase_price_by_vendor(product_id, vendor_id, manual) + + return self._get_valid_purchase_price(purchase_price, manual) + def _get_purchase_price_by_vendor(self, product_id, vendor_id, manual=False): purchase_price = self.env['purchase.pricelist'].search( -- cgit v1.2.3 From 78a7df26d09b64fb9b3b45084212cbf19c1907a1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 13 Feb 2025 13:51:36 +0700 Subject: returns the code to the beginning --- indoteknik_custom/models/sale_order_line.py | 44 ++++++++++++----------------- 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index af521c2c..aed95aab 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -159,7 +159,7 @@ class SaleOrderLine(models.Model): # [('vendor_id', '=', self.product_id.x_manufacture.override_vendor_id.id), # ('product_id', '=', self.product_id.id)], # limit=1, order='count_trx_po desc, count_trx_po_vendor desc') - price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id, manual=True) + price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id) self.purchase_price = price self.purchase_tax_id = taxes # else: @@ -202,49 +202,40 @@ class SaleOrderLine(models.Model): # self.price_unit = selling_price # self.tax_id = tax_id - def _get_purchase_price(self, product_id, manual=False): + def _get_purchase_price(self, product_id): purchase_price = self.env['purchase.pricelist'].search( - [('product_id', '=', product_id.id)], - limit=1 - ) - - vendor_id = purchase_price.brand_id.override_vendor_id - - if vendor_id: - return self._get_purchase_price_by_vendor(product_id, vendor_id, manual) - - return self._get_valid_purchase_price(purchase_price, manual) + [('product_id', '=', product_id.id), + ('is_winner', '=', True)], + limit=1) + return self._get_valid_purchase_price(purchase_price) - def _get_purchase_price_by_vendor(self, product_id, vendor_id, manual=False): + def _get_purchase_price_by_vendor(self, product_id, vendor_id): purchase_price = self.env['purchase.pricelist'].search( [('product_id', '=', product_id.id), - ('vendor_id', '=', vendor_id.id)], - limit=1 - ) - - if purchase_price: - return self._get_valid_purchase_price(purchase_price, manual) - - # Return default values when no purchase_price is found - return 0, '', None # Ensure 3 values are always returned + ('vendor_id', '=', vendor_id.id), + # ('is_winner', '=', True) + ], + limit=1) + return self._get_valid_purchase_price(purchase_price) - def _get_valid_purchase_price(self, purchase_price, manual): + def _get_valid_purchase_price(self, purchase_price): current_time = datetime.now() delta_time = current_time - timedelta(days=365) # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') price = 0 taxes = '' - vendor_id = purchase_price.vendor_id.id or '' + vendor_id = '' human_last_update = purchase_price.human_last_update or datetime.min system_last_update = purchase_price.system_last_update or datetime.min if purchase_price.taxes_product_id.type_tax_use == 'purchase': price = purchase_price.product_price taxes = purchase_price.taxes_product_id.id - if delta_time > human_last_update or (not purchase_price.brand_id.override_vendor_id and manual == False): + vendor_id = purchase_price.vendor_id.id + if delta_time > human_last_update: price = 0 taxes = '' vendor_id = '' @@ -253,7 +244,8 @@ class SaleOrderLine(models.Model): if purchase_price.taxes_system_id.type_tax_use == 'purchase': price = purchase_price.system_price taxes = purchase_price.taxes_system_id.id - if delta_time > human_last_update or (not purchase_price.brand_id.override_vendor_id and manual == False): + vendor_id = purchase_price.vendor_id.id + if delta_time > system_last_update: price = 0 taxes = '' vendor_id = '' -- cgit v1.2.3 From 9bd46f112fdfb4fb7f56866b4e260efbd26c6daa Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 17 Feb 2025 08:36:01 +0700 Subject: renca req tempo status --- indoteknik_custom/models/user_pengajuan_tempo_request.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index 4a1994fb..be4293a0 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -63,6 +63,19 @@ class UserPengajuanTempoRequest(models.Model): ('reject', 'Rejected'), ], string='Status',) reason_reject = fields.Char(string='Reason Reaject', tracking=True, track_visibility='onchange') + state_tempo_text = fields.Char(string="Status", compute="_compute_state_tempo_text") + + @api.depends('state_tempo') + def _compute_state_tempo_text(self): + for record in self: + status_mapping = { + 'draft': "Menunggu Approve Manager", + 'approval_sales': "Menunggu Approve Finance", + 'approval_finance': "Menunggu Approve Direktur", + 'approval_director': "Approved", + 'reject': "Rejected", + } + record.state_tempo_text = status_mapping.get(record.state_tempo, "Unknown") # informasi perusahaan name_tempo = fields.Many2one('res.partner', string='Nama Perusahaan', related='pengajuan_tempo_id.name_tempo', store=True, tracking=True, readonly=False) -- cgit v1.2.3 From b2f39b75e96ef7c80f32ddd7cec86de1eb6c7279 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 17 Feb 2025 08:54:23 +0700 Subject: add logic if cbd not validasi limit --- indoteknik_custom/models/sale_order.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 9631fe6e..8a851a69 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -942,6 +942,7 @@ class SaleOrder(models.Model): # Ambil blocking stage dari partner block_stage = rec.partner_id.parent_id.blocking_stage if rec.partner_id.parent_id else rec.partner_id.blocking_stage or 0 + is_cbd = rec.partner_id.parent_id.property_payment_term_id.id == 26 if rec.partner_id.parent_id else rec.partner_id.property_payment_term_id.id == 26 or False # Ambil jumlah nilai dari SO yang invoice_status masih 'to invoice' so_to_invoice = 0 @@ -952,7 +953,7 @@ class SaleOrder(models.Model): remaining_credit_limit = block_stage - current_total - so_to_invoice # Validasi limit - if remaining_credit_limit <= 0 and block_stage > 0: + if remaining_credit_limit <= 0 and block_stage > 0 and not is_cbd: raise UserError(_("The credit limit for %s will exceed the Blocking Stage if the Sale Order is confirmed. The remaining credit limit is %s, from %s and the outstanding amount is %s.") % (rec.partner_id.name, block_stage - current_total, block_stage, outstanding_amount)) -- cgit v1.2.3 From 5f14f6eb9256a7bbdbab8b5ba5482939a479f59a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 18 Feb 2025 08:27:26 +0700 Subject: CR back margin leader approval to 13% --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 8a851a69..24b1d85c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1119,7 +1119,7 @@ class SaleOrder(models.Model): return False def _requires_approval_margin_leader(self): - return self.total_percent_margin <= 13 and not self.env.user.is_leader + return self.total_percent_margin <= 15 and not self.env.user.is_leader def _requires_approval_margin_manager(self): return self.total_percent_margin <= 20 and not self.env.user.is_leader and not self.env.user.is_sales_manager -- cgit v1.2.3 From cbe7af2817b0a18097ace08e63e32e02d7ce4c26 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 18 Feb 2025 09:16:09 +0700 Subject: CR margin approve leader jadi < 15% not <= 15 --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 24b1d85c..430b4526 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1119,7 +1119,7 @@ class SaleOrder(models.Model): return False def _requires_approval_margin_leader(self): - return self.total_percent_margin <= 15 and not self.env.user.is_leader + return self.total_percent_margin < 15 and not self.env.user.is_leader def _requires_approval_margin_manager(self): return self.total_percent_margin <= 20 and not self.env.user.is_leader and not self.env.user.is_sales_manager -- cgit v1.2.3 From 80c56615d5c605f6e96cc3567a6b3d0332152957 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 18 Feb 2025 13:16:20 +0700 Subject: CR customer commision --- indoteknik_custom/models/commision.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 48f1c7f6..3f035e2f 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -153,6 +153,10 @@ class CustomerCommision(models.Model): bank_account = fields.Char(string='Account No', tracking=3) note_transfer = fields.Char(string='Keterangan') brand_ids = fields.Many2many('x_manufactures', string='Brands') + payment_status = fields.Selection([ + ('pending', 'Pending'), + ('payment', 'Payment'), + ], string='Payment Status', copy=False, readonly=True, tracking=3, default='pending') # add status for type of commision, fee, rebate / cashback # include child or not? @@ -228,6 +232,15 @@ class CustomerCommision(models.Model): raise UserError('Harus di approved oleh yang bersangkutan') return + def action_confirm_customer_payment(self): + group_id = self.env.ref('indoteknik_custom.group_role_fat').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya bisa dikonfirmasi oleh FAT') + else: + self.payment_status = 'payment' + return + def generate_customer_commision(self): if self.commision_lines: raise UserError('Line sudah ada, tidak bisa di generate ulang') -- cgit v1.2.3 From a9abc6b63f1bafb1e007da4446636ec2da10d493 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 18 Feb 2025 13:19:43 +0700 Subject: back to original before CR customer commision --- indoteknik_custom/models/commision.py | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 3f035e2f..48f1c7f6 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -153,10 +153,6 @@ class CustomerCommision(models.Model): bank_account = fields.Char(string='Account No', tracking=3) note_transfer = fields.Char(string='Keterangan') brand_ids = fields.Many2many('x_manufactures', string='Brands') - payment_status = fields.Selection([ - ('pending', 'Pending'), - ('payment', 'Payment'), - ], string='Payment Status', copy=False, readonly=True, tracking=3, default='pending') # add status for type of commision, fee, rebate / cashback # include child or not? @@ -232,15 +228,6 @@ class CustomerCommision(models.Model): raise UserError('Harus di approved oleh yang bersangkutan') return - def action_confirm_customer_payment(self): - group_id = self.env.ref('indoteknik_custom.group_role_fat').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya bisa dikonfirmasi oleh FAT') - else: - self.payment_status = 'payment' - return - def generate_customer_commision(self): if self.commision_lines: raise UserError('Line sudah ada, tidak bisa di generate ulang') -- cgit v1.2.3 From 10c0cd096353397ce26ad13b6967a35d13072fb6 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Feb 2025 09:39:25 +0700 Subject: label in move line same with ref in entries --- indoteknik_custom/models/account_move_line.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 37f7c77c..31950f4c 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -23,3 +23,11 @@ class AccountMoveLine(models.Model): else: account.is_required = False + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if 'move_id' in vals: + move = self.env['account.move'].browse(vals['move_id']) + if move.move_type == 'entry': + vals['name'] = move.ref + return super().create(vals_list) \ No newline at end of file -- cgit v1.2.3 From 45f6f270ae76b5e2d811f4ef04e9b64ba5b7f143 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Feb 2025 09:41:06 +0700 Subject: fix error --- indoteknik_custom/models/account_move_line.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 31950f4c..6b394da3 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -24,10 +24,10 @@ class AccountMoveLine(models.Model): account.is_required = False @api.model_create_multi - def create(self, vals_list): - for vals in vals_list: - if 'move_id' in vals: - move = self.env['account.move'].browse(vals['move_id']) - if move.move_type == 'entry': - vals['name'] = move.ref - return super().create(vals_list) \ No newline at end of file + def create(self, vals_list): + for vals in vals_list: + if 'move_id' in vals: + move = self.env['account.move'].browse(vals['move_id']) + if move.move_type == 'entry': + vals['name'] = move.ref + return super().create(vals_list) \ No newline at end of file -- cgit v1.2.3 From bf61388fb16a59dcf954cd288c830f00c62efee5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Feb 2025 09:42:12 +0700 Subject: fix error --- indoteknik_custom/models/account_move_line.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 6b394da3..a4386157 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -21,13 +21,4 @@ class AccountMoveLine(models.Model): if account.account_id.code and account.account_id.code[0] in ['6', '7']: account.is_required = True else: - account.is_required = False - - @api.model_create_multi - def create(self, vals_list): - for vals in vals_list: - if 'move_id' in vals: - move = self.env['account.move'].browse(vals['move_id']) - if move.move_type == 'entry': - vals['name'] = move.ref - return super().create(vals_list) \ No newline at end of file + account.is_required = False \ No newline at end of file -- cgit v1.2.3 From 62636c80dcc2078eed18810e7958f41fd5b13fdc Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Feb 2025 09:42:39 +0700 Subject: fix error --- indoteknik_custom/models/account_move_line.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index a4386157..6b394da3 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -21,4 +21,13 @@ class AccountMoveLine(models.Model): if account.account_id.code and account.account_id.code[0] in ['6', '7']: account.is_required = True else: - account.is_required = False \ No newline at end of file + account.is_required = False + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if 'move_id' in vals: + move = self.env['account.move'].browse(vals['move_id']) + if move.move_type == 'entry': + vals['name'] = move.ref + return super().create(vals_list) \ No newline at end of file -- cgit v1.2.3 From 66901cd03a1494e6c84893e14083dcd1fbe737a5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Feb 2025 14:01:44 +0700 Subject: fix bug account move --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/account_move.py | 3 +- indoteknik_custom/models/account_move_line.py | 2 +- .../models/account_payment_register.py | 48 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 indoteknik_custom/models/account_payment_register.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index ddbe16f1..dea3eeea 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -142,3 +142,4 @@ from . import stock_immediate_transfer from . import coretax_fatur from . import ir_actions_report from . import barcoding_product +from . import account_payment_register diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 7760c69d..b2ac47c2 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -64,6 +64,7 @@ class AccountMove(models.Model): nomor_kwitansi = fields.Char(string="Nomor Kwitansi") other_subtotal = fields.Float(string="Other Subtotal", compute='compute_other_subtotal') other_taxes = fields.Float(string="Other Taxes", compute='compute_other_taxes') + is_hr = fields.Boolean(string="Is HR?", default=False) def _update_line_name_from_ref(self): """Update all account.move.line name fields with ref from account.move""" @@ -114,7 +115,7 @@ class AccountMove(models.Model): def create(self, vals): vals['nomor_kwitansi'] = self.env['ir.sequence'].next_by_code('nomor.kwitansi') or '0' result = super(AccountMove, self).create(vals) - result._update_line_name_from_ref() + # result._update_line_name_from_ref() return result def compute_so_shipping_paid_by(self): diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 6b394da3..7c95d4ef 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -28,6 +28,6 @@ class AccountMoveLine(models.Model): for vals in vals_list: if 'move_id' in vals: move = self.env['account.move'].browse(vals['move_id']) - if move.move_type == 'entry': + if move.move_type == 'entry' and move.is_hr == True: vals['name'] = move.ref return super().create(vals_list) \ No newline at end of file diff --git a/indoteknik_custom/models/account_payment_register.py b/indoteknik_custom/models/account_payment_register.py new file mode 100644 index 00000000..4ebb7e4e --- /dev/null +++ b/indoteknik_custom/models/account_payment_register.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields, api, _ +from odoo.exceptions import UserError + + +class AccountPaymentRegister(models.TransientModel): + _inherit = 'account.payment.register' + def _create_payment_vals_from_wizard(self): + payment_vals = { + 'date': self.payment_date, + 'amount': self.amount, + 'payment_type': self.payment_type, + 'partner_type': self.partner_type, + 'ref': self.communication, + 'journal_id': self.journal_id.id, + 'is_hr': True, + 'currency_id': self.currency_id.id, + 'partner_id': self.partner_id.id, + 'partner_bank_id': self.partner_bank_id.id, + 'payment_method_id': self.payment_method_id.id, + 'destination_account_id': self.line_ids[0].account_id.id + } + + if not self.currency_id.is_zero(self.payment_difference) and self.payment_difference_handling == 'reconcile': + payment_vals['write_off_line_vals'] = { + 'name': self.writeoff_label, + 'amount': self.payment_difference, + 'account_id': self.writeoff_account_id.id, + } + return payment_vals + + def _create_payment_vals_from_batch(self, batch_result): + batch_values = self._get_wizard_values_from_batch(batch_result) + return { + 'date': self.payment_date, + 'amount': batch_values['source_amount_currency'], + 'payment_type': batch_values['payment_type'], + 'partner_type': batch_values['partner_type'], + 'ref': self._get_batch_communication(batch_result), + 'journal_id': self.journal_id.id, + 'is_hr': True, + 'currency_id': batch_values['source_currency_id'], + 'partner_id': batch_values['partner_id'], + 'partner_bank_id': batch_result['key_values']['partner_bank_id'], + 'payment_method_id': self.payment_method_id.id, + 'destination_account_id': batch_result['lines'][0].account_id.id + } -- cgit v1.2.3 From 38f8ddd9aaaad58c8d7ea27235cd109ba288693d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 19 Feb 2025 15:02:35 +0700 Subject: change logic solr is_in_bu from available to qty_free_bandengan --- indoteknik_custom/models/solr/product_template.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 87e8370f..8afff6e3 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -76,8 +76,11 @@ class ProductTemplate(models.Model): ('product_id', 'in', template.product_variant_ids.ids), ('location_id', 'in', target_locations), ]) - - is_in_bu = any(quant.available_quantity > 0 for quant in stock_quant) + is_in_bu = False + for quant in stock_quant: + if quant.product_id.qty_free_bandengan > 0: + is_in_bu = True + break cleaned_desc = BeautifulSoup(template.website_description or '', "html.parser").get_text() website_description = template.website_description if cleaned_desc else '' -- cgit v1.2.3