From 8978868864925683d02342112020e7fc047a4acf Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 2 Feb 2024 13:32:55 +0700 Subject: logbook sj and mark as cancel po --- indoteknik_custom/__manifest__.py | 11 +++ indoteknik_custom/models/__init__.py | 11 +++ indoteknik_custom/models/logbook_sj.py | 117 +++++++++++++++++++++++++ indoteknik_custom/models/po_multi_cancel.py | 22 +++++ indoteknik_custom/models/purchase_order.py | 19 ++++ indoteknik_custom/models/report_logbook_sj.py | 34 +++++++ indoteknik_custom/security/ir.model.access.csv | 17 +++- indoteknik_custom/views/logbook_sj.xml | 52 +++++++++++ indoteknik_custom/views/po_multi_cancel.xml | 31 +++++++ indoteknik_custom/views/purchase_order.xml | 9 ++ indoteknik_custom/views/report_logbook_sj.xml | 90 +++++++++++++++++++ 11 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/logbook_sj.py create mode 100644 indoteknik_custom/models/po_multi_cancel.py create mode 100644 indoteknik_custom/models/report_logbook_sj.py create mode 100644 indoteknik_custom/views/logbook_sj.xml create mode 100644 indoteknik_custom/views/po_multi_cancel.xml create mode 100644 indoteknik_custom/views/report_logbook_sj.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index c7e65b37..689103d8 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -107,6 +107,17 @@ 'views/purchase_order_multi_update.xml', 'views/purchase_order_multi_confirm.xml', 'views/invoice_reklas_penjualan.xml', +<<<<<<< Updated upstream +<<<<<<< Updated upstream + 'views/po_multi_cancel.xml', +======= + 'views/logbook_sj.xml', + 'views/report_logbook_sj.xml', +>>>>>>> Stashed changes +======= + 'views/logbook_sj.xml', + 'views/report_logbook_sj.xml', +>>>>>>> Stashed changes 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 76387ff8..4b29e71d 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -98,3 +98,14 @@ from . import purchase_order_multi_update from . import invoice_reklas_penjualan from . import purchase_order_multi_confirm from . import stock_quant +<<<<<<< Updated upstream +<<<<<<< Updated upstream +from . import po_multi_cancel +======= +from . import logbook_sj +from . import report_logbook_sj +>>>>>>> Stashed changes +======= +from . import logbook_sj +from . import report_logbook_sj +>>>>>>> Stashed changes diff --git a/indoteknik_custom/models/logbook_sj.py b/indoteknik_custom/models/logbook_sj.py new file mode 100644 index 00000000..567f1ae3 --- /dev/null +++ b/indoteknik_custom/models/logbook_sj.py @@ -0,0 +1,117 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import UserError +from pytz import timezone +from datetime import datetime + +class LogbookSJ(models.TransientModel): + _name = 'logbook.sj' + + name = fields.Char(string='Name', default='Logbook SJ') + logbook_sj_line = fields.One2many( + comodel_name='logbook.sj.line', + inverse_name='logbook_sj_id', + string='Logbook SJ Line' + ) + + def create_logbook_sj(self): + logbook_line = self.logbook_sj_line + + current_time = datetime.utcnow() + report_logbook_ids = [] + for line in logbook_line: + nomor_sj = line.name + picking = self.env['stock.picking'].search([ + ('picking_code', '=', nomor_sj), + ]) + parameters_header = { + 'name': nomor_sj, + 'date': current_time, + 'name_picking': picking.name, + 'partner_id': picking.partner_id.id, + } + + report_logbook = self.env['report.logbook.sj'].create([parameters_header]) + + + for stock in picking.move_line_ids_without_package: + data = { + 'product_id': stock.product_id.id, + 'location_id': stock.location_id.id, + 'product_uom_qty': stock.product_uom_qty, + 'qty_done': stock.qty_done, + 'product_uom_id': stock.product_uom_id.id, + 'report_logbook_sj_id': report_logbook.id + } + self.env['report.logbook.sj.line'].create([data]) + + report_logbook_ids.append(report_logbook.id) + line.unlink() + + self.unlink() + return { + 'name': _('Report Logbook SJ'), + 'view_mode': 'tree,form', + 'res_model': 'report.logbook.sj', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', 'in', report_logbook_ids)], + } + +class LogbookSJLine(models.TransientModel): + _name = 'logbook.sj.line' + + name = fields.Char(string='SJ Number') + driver_id = fields.Many2one(comodel_name='res.users', string='Driver') + departure_date = fields.Char(string='Departure Date') + arrival_date = fields.Char(string='Arrival Date') + carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method') + tracking_no = fields.Char(string='Tracking No') + logbook_sj_id = fields.Many2one('logbook.sj', string='Logbook SJ') + partner_id = fields.Many2one('res.partner', string='Customer') + + @api.onchange('name') + def onchange_name(self): + current_time = datetime.now(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + + if self.name: + if len(self.name) == 13: + self.name = self.name[:-1] + picking = self.env['stock.picking'].search([('picking_code', '=', self.name)], limit=1) + if picking: + if picking.driver_id: + self.driver_id = picking.driver_id + else: + self.driver_id = self.env.uid + + sale_order = False + if picking.origin: + sale_order = self.env['sale.order'].search([('name', '=', picking.origin)], limit=1) + + if sale_order.carrier_id: + self.carrier_id = sale_order.carrier_id + + self.tracking_no = picking.delivery_tracking_no + + self.partner_id = picking.partner_id + + delivery_type = self.get_delivery_type(picking.driver_departure_date, picking.driver_arrival_date) + if delivery_type != 'departure': + self.departure_date = picking.driver_departure_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + + if delivery_type == 'departure': + self.departure_date = current_time + elif delivery_type == 'arrival': + self.arrival_date = current_time + else: + self.arrival_date = picking.driver_arrival_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + else: + raise UserError('Nomor DO tidak ditemukan') + + def get_delivery_type(self, driver_departure_date, driver_arrival_date): + delivery_type = 'departure' + if driver_departure_date: + delivery_type = 'arrival' + if driver_arrival_date: + delivery_type = False + + return delivery_type diff --git a/indoteknik_custom/models/po_multi_cancel.py b/indoteknik_custom/models/po_multi_cancel.py new file mode 100644 index 00000000..52c156b5 --- /dev/null +++ b/indoteknik_custom/models/po_multi_cancel.py @@ -0,0 +1,22 @@ +from odoo import models, fields +import logging + +_logger = logging.getLogger(__name__) + + +class PoMultiCancel(models.TransientModel): + _name = 'po.multi.cancel' + + def save_multi_cancel_po(self): + purchase_ids = self._context['purchase_ids'] + purchase = self.env['purchase.order'].browse(purchase_ids) + purchase.button_cancel() + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': 'Notification', + 'message': 'Status berhasil diubah', + 'next': {'type': 'ir.actions.act_window_close'}, + } + } \ No newline at end of file diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 67299d2c..dc654196 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -53,6 +53,25 @@ class PurchaseOrder(models.Model): status_paid_cbd = fields.Boolean(string='Paid Status', tracking=3, help='Field ini diisi secara manual oleh Finance AP dan hanya untuk status PO CBD') revisi_po = fields.Boolean(string='Revisi', tracking=3) + @api.model + def action_multi_cancel(self): + for purchase in self: + purchase.update({ + 'state': 'cancel', + }) + + if purchase.state == 'cancel': + purchase.update({ + 'approval_status': False, + }) + + def open_form_multi_cancel(self): + action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_po_multi_cancel') + action['context'] = { + 'purchase_ids': [x.id for x in self] + } + return action + def delete_line(self): lines_to_delete = self.order_line.filtered(lambda line: line.suggest == 'masih cukup') if not lines_to_delete: diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py new file mode 100644 index 00000000..d2008608 --- /dev/null +++ b/indoteknik_custom/models/report_logbook_sj.py @@ -0,0 +1,34 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError +from pytz import timezone +from datetime import datetime + +class ReportLogbookSJ(models.Model): + _name = 'report.logbook.sj' + + name = fields.Char(string='Nomor SJ', default='Logbook SJ') + date = fields.Datetime(string='Date') + name_picking = fields.Char(string='Picking Name') + partner_id = fields.Many2one('res.partner', string='Customer') + approve_by_finance = fields.Boolean(string='Approve By Finance') + report_logbook_sj_line = fields.One2many( + comodel_name='report.logbook.sj.line', + inverse_name='report_logbook_sj_id', + string='Logbook SJ Line' + ) + + def approve(self): + if self.env.user.is_accounting: + self.approve_by_finance = True + else: + raise UserError('Hanya Accounting yang bisa Approve') + +class ReportLogbookSJLine(models.Model): + _name = 'report.logbook.sj.line' + + product_id = fields.Many2one(comodel_name='product.product', string='Product') + location_id = fields.Many2one(comodel_name='stock.location', string='From') + product_uom_qty = fields.Float(string='Reserved') + qty_done = fields.Float(string='Done') + product_uom_id = fields.Many2one('uom.uom', string='Unit of Measure') + report_logbook_sj_id = fields.Many2one('report.logbook.sj', string='Logbook SJ') \ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 8d014b69..c2bfaa10 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -88,4 +88,19 @@ access_sale_advance_payment_inv,access.sale.advance.payment.inv,model_sale_advan access_purchase_order_multi_update,access.purchase.order.multi_update,model_purchase_order_multi_update,,1,1,1,1 access_invoice_reklas_penjualan,access.invoice.reklas.penjualan,model_invoice_reklas_penjualan,,1,1,1,1 access_invoice_reklas_penjualan_line,access.invoice.reklas.penjualan.line,model_invoice_reklas_penjualan_line,,1,1,1,1 -access_purchase_order_multi_confirm,access.purchase.order.multi_confirm,model_purchase_order_multi_confirm,,1,1,1,1 \ No newline at end of file +access_purchase_order_multi_confirm,access.purchase.order.multi_confirm,model_purchase_order_multi_confirm,,1,1,1,1 +<<<<<<< Updated upstream +<<<<<<< Updated upstream +access_po_multi_cancel,access.po.multi.cancel,model_po_multi_cancel,,1,1,1,1 +======= +access_logbook_sj,access.logbook.sj,model_logbook_sj,,1,1,1,1 +access_logbook_sj_line,access.logbook.sj.line,model_logbook_sj_line,,1,1,1,1 +access_report_logbook_sj,access.report.logbook.sj,model_report_logbook_sj,,1,1,1,1 +access_report_logbook_sj_line,access.report.logbook.sj.line,model_report_logbook_sj_line,,1,1,1,1 +>>>>>>> Stashed changes +======= +access_logbook_sj,access.logbook.sj,model_logbook_sj,,1,1,1,1 +access_logbook_sj_line,access.logbook.sj.line,model_logbook_sj_line,,1,1,1,1 +access_report_logbook_sj,access.report.logbook.sj,model_report_logbook_sj,,1,1,1,1 +access_report_logbook_sj_line,access.report.logbook.sj.line,model_report_logbook_sj_line,,1,1,1,1 +>>>>>>> Stashed changes diff --git a/indoteknik_custom/views/logbook_sj.xml b/indoteknik_custom/views/logbook_sj.xml new file mode 100644 index 00000000..9eb9aa12 --- /dev/null +++ b/indoteknik_custom/views/logbook_sj.xml @@ -0,0 +1,52 @@ + + + + Logbook SJ + logbook.sj + +
+ + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Logbook SJ + logbook.sj + ir.actions.act_window + form + + new + + + +
\ No newline at end of file diff --git a/indoteknik_custom/views/po_multi_cancel.xml b/indoteknik_custom/views/po_multi_cancel.xml new file mode 100644 index 00000000..c17fc5a7 --- /dev/null +++ b/indoteknik_custom/views/po_multi_cancel.xml @@ -0,0 +1,31 @@ + + + + + PO Multi Cancel + po.multi.cancel + +
+ + + Apakah Anda Yakin Ingin Mengubah Status Menjadi Cancel? + + +
+
+
+
+
+ + + PO Multi Cancel + po.multi.cancel + ir.actions.act_window + form + + new + +
+
\ No newline at end of file diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 52e98787..a6f28ffa 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -213,4 +213,13 @@ action = records.open_form_multi_confirm_po() + + + Cancel PO + + + code + action = records.open_form_multi_cancel() + + \ No newline at end of file diff --git a/indoteknik_custom/views/report_logbook_sj.xml b/indoteknik_custom/views/report_logbook_sj.xml new file mode 100644 index 00000000..52e00d17 --- /dev/null +++ b/indoteknik_custom/views/report_logbook_sj.xml @@ -0,0 +1,90 @@ + + + + report.logbook.sj.tree + report.logbook.sj + + + + + + + + + + + + + report.logbook.sj.line.tree + report.logbook.sj.line + + + + + + + + + + + + + report.logbook.sj.form + report.logbook.sj + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + Report Logbook SJ + ir.actions.act_window + report.logbook.sj + tree,form + + + + \ No newline at end of file -- cgit v1.2.3