From e33f2d321ee4db6a6e6a86e35243100b9f107f22 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 27 Jun 2024 15:29:16 +0700 Subject: logbook bill & send email efaktur document --- indoteknik_custom/__manifest__.py | 3 + indoteknik_custom/models/__init__.py | 2 + indoteknik_custom/models/account_move.py | 12 +-- indoteknik_custom/models/logbook_bill.py | 103 ++++++++++++++++++++++ indoteknik_custom/models/purchase_order.py | 1 + indoteknik_custom/models/report_logbook_bill.py | 98 ++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 5 ++ indoteknik_custom/views/ir_sequence.xml | 10 +++ indoteknik_custom/views/logbook_bill.xml | 55 ++++++++++++ indoteknik_custom/views/mail_template_efaktur.xml | 26 ++++++ indoteknik_custom/views/purchase_order.xml | 3 + indoteknik_custom/views/report_logbook_bill.xml | 97 ++++++++++++++++++++ 12 files changed, 407 insertions(+), 8 deletions(-) create mode 100644 indoteknik_custom/models/logbook_bill.py create mode 100644 indoteknik_custom/models/report_logbook_bill.py create mode 100644 indoteknik_custom/views/logbook_bill.xml create mode 100644 indoteknik_custom/views/mail_template_efaktur.xml create mode 100644 indoteknik_custom/views/report_logbook_bill.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 6b5bc8bb..9ffcd5ce 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -91,6 +91,7 @@ 'views/airway_bill.xml', 'views/product_attribute_value.xml', 'views/mail_template_po.xml', + 'views/mail_template_efaktur.xml', 'views/price_group.xml', 'views/mrp_production.xml', 'views/apache_solr.xml', @@ -131,6 +132,8 @@ 'views/def_cargo_district.xml', 'views/purchase_order_multi_uangmuka.xml', 'views/purchase_order_multi_uangmuka2.xml', + 'views/logbook_bill.xml', + 'views/report_logbook_bill.xml', '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 e6fefe2a..510b8b9d 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -117,3 +117,5 @@ from . import ged from . import account_move_multi_update_bills from . import def_cargo from . import purchase_order_multi_uangmuka2 +from . import logbook_bill +from . import report_logbook_bill diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index d81726e9..2996623c 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -66,7 +66,6 @@ class AccountMove(models.Model): @api.model def generate_attachment(self, record): # Fetch the binary field - # TODO nathan tolong rapihin file_content = record.efaktur_document file_name = "efaktur_document_{}.pdf".format(record.id) # Adjust the file extension if necessary @@ -79,21 +78,18 @@ class AccountMove(models.Model): }) return attachment - @api.model + @api.constrains('efaktur_document') def send_scheduled_email(self): # Get the records for which emails need to be sent - # records = self.search([]) # Adjust the domain as necessary - # TODO nathan tolong rapihin - records = self.env['account.move'].search([('id', '=', 194697)]) - # template = self.env.ref('my_module.email_template_example') - template = self.env['mail.template'].search([('id', '=', 8)]) + records = self.search([('id', 'in', self.ids)]) + template = self.env.ref('indoteknik_custom.mail_template_efaktur_document') for record in records: attachment = self.generate_attachment(record) email_values = { 'attachment_ids': [(4, attachment.id)] } - template.send_mail(record.id, email_values=email_values) + template.send_mail(record.id, email_values=email_values, force_send=True) @api.model def create(self, vals): diff --git a/indoteknik_custom/models/logbook_bill.py b/indoteknik_custom/models/logbook_bill.py new file mode 100644 index 00000000..578ad59b --- /dev/null +++ b/indoteknik_custom/models/logbook_bill.py @@ -0,0 +1,103 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import UserError +from pytz import timezone +from datetime import datetime + +class LogbookBill(models.TransientModel): + _name = 'logbook.bill' + + name = fields.Char(string='Name', default='Logbook Bill') + logbook_bill_line = fields.One2many( + comodel_name='logbook.bill.line', + inverse_name='logbook_bill_id', + string='Logbook Bill Line' + ) + + + def grand_total(self, picking): + total = 0 + for line in picking.move_ids_without_package: + po = self.env['purchase.order.line'].search([ + ('order_id', '=', picking.purchase_id.id), + ('product_id', '=', line.product_id.id), + ], order='id desc', limit=1) + total += line.quantity_done * po.price_unit + return total + + def create_logbook_bill(self): + logbook_line = self.logbook_bill_line + + current_time = datetime.utcnow() + report_logbook_ids = [] + parameters_header = { + 'date': current_time, + 'created_by': self.env.user.id, + } + + report_logbook = self.env['report.logbook.bill'].create([parameters_header]) + for line in logbook_line: + picking = self.env['stock.picking'].search([('name', '=', line.name)], limit=1) + stock = picking + parent_id = stock.partner_id.parent_id.id + parent_id = parent_id if parent_id else stock.partner_id.id + + data = { + 'purchase_id': stock.purchase_id.id, + 'name': stock.name, + 'grand_total': self.grand_total(picking), + 'partner_id': parent_id, + 'invoice': line.invoice, + 'surat_jalan': line.surat_jalan, + 'proforma_invoice': line.proforma_invoice, + 'faktur_pajak': line.faktur_pajak, + 'date_approve': stock.date_done, + 'report_logbook_bill_id': report_logbook.id, + 'note': line.note, + 'note_finance': line.note_finance + } + self.env['report.logbook.bill.line'].create([data]) + + report_logbook_ids.append(report_logbook.id) + line.unlink() + + self.unlink() + return { + 'name': _('Report Logbook Bill'), + 'view_mode': 'tree,form', + 'res_model': 'report.logbook.bill', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', 'in', report_logbook_ids)], + } + +class LogbookBillLine(models.TransientModel): + _name = 'logbook.bill.line' + + name = fields.Char(string='Name') + logbook_bill_id = fields.Many2one('logbook.bill', string='Logbook Bill') + partner_id = fields.Many2one('res.partner', string='Customer') + purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + invoice = fields.Boolean(string='Invoice') + faktur_pajak = fields.Boolean(string='Faktur Pajak') + surat_jalan = fields.Boolean(string='Surat Jalan') + proforma_invoice = fields.Boolean(string='Proforma Invoice') + date_approve = fields.Datetime(string='Date Approve', tracking=3) + note = fields.Char(string='Note Logistik') + note_finance = fields.Char(string='Note Finance') + + @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([('name', '=', self.name)], limit=1) + if picking: + self.partner_id = picking.partner_id + self.purchase_id = picking.purchase_id.id + + self.date_approve = picking.date_done + + else: + raise UserError('Nomor DO tidak ditemukan') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index db474895..6aec4074 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -60,6 +60,7 @@ class PurchaseOrder(models.Model): matches_so = fields.Many2many('sale.order', string='Matches SO', compute='_compute_matches_so') is_create_uangmuka = fields.Boolean(string='Uang Muka?') move_id = fields.Many2one('account.move', string='Account Move') + logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') def _prepare_invoice(self): """Prepare the dict of values to create the new invoice for a purchase order. diff --git a/indoteknik_custom/models/report_logbook_bill.py b/indoteknik_custom/models/report_logbook_bill.py new file mode 100644 index 00000000..9a7c1535 --- /dev/null +++ b/indoteknik_custom/models/report_logbook_bill.py @@ -0,0 +1,98 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError +from pytz import timezone +from datetime import datetime + +class ReportLogbookBill(models.Model): + _name = 'report.logbook.bill' + _description = "Logbook Bill" + _inherit = ['mail.thread'] + _rec_name = 'name' + + name = fields.Char(string='Name', default='Logbook Bill') + date = fields.Datetime(string='Date Created') + date_approve = fields.Datetime(string='Date Approve', tracking=3) + date_pengajuan = fields.Datetime(string='Date Pengajuan', tracking=3) + approve_by_finance = fields.Boolean(string='Approve By Finance', tracking=3) + pengajuan_by = fields.Many2one(comodel_name='res.users', string='Pengajuan By', tracking=3) + approve_by = fields.Many2one(comodel_name='res.users', string='Approve By', tracking=3) + created_by = fields.Many2one(comodel_name='res.users', string='Created By', tracking=3) + report_logbook_bill_line = fields.One2many( + comodel_name='report.logbook.bill.line', + inverse_name='report_logbook_bill_id', + string='Logbook Bill Line' + ) + state = fields.Selection( + [('belum_terima', 'Belum Terima'), + ('terima_sebagian', 'Terima Sebagian'), + ('terima_semua', 'Sudah di terima semua'), + ], + default='terima_semua', + string='Status', + tracking=True, + ) + + state_pengajuan = fields.Selection( + [('pengajuan', 'Pengajuan'), + ('diajukan', 'Sudah Diajukan'), + ], + default='pengajuan', + string='Status Pengajuan', + tracking=True, + ) + + count_line = fields.Char(string='Count Line', compute='_compute_count_line') + + @api.depends('report_logbook_bill_line') + def _compute_count_line(self): + for rec in self: + rec.count_line = len(rec.report_logbook_bill_line) + + @api.model + def create(self, vals): + vals['name'] = self.env['ir.sequence'].next_by_code('report.logbook.bill') or '0' + result = super(ReportLogbookBill, self).create(vals) + return result + + def approve(self): + current_time = datetime.utcnow() + if self.env.user.is_accounting: + self.approve_by_finance = True + self.date_approve = current_time + self.approve_by = self.env.user.id + if any(line.not_exist for line in self.report_logbook_bill_line): + if all(line.not_exist for line in self.report_logbook_bill_line): + self.state = 'belum_terima' + else: + self.state = 'terima_sebagian' + else: + self.state = 'terima_semua' + else: + if self.env.user.is_logistic_approver: + self.state_pengajuan = 'diajukan' + self.date_pengajuan = current_time + self.pengajuan_by = self.env.user.id + self.relation_po_to_logbook() + + def relation_po_to_logbook(self): + for line in self.report_logbook_bill_line: + line.purchase_id.logbook_bill_id = self.id + +class ReportLogbookBillLine(models.Model): + _name = 'report.logbook.bill.line' + + name = fields.Char(string='Name') + logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') + purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + invoice = fields.Boolean(string='Invoice') + faktur_pajak = fields.Boolean(string='FP') + surat_jalan = fields.Boolean(string='SJ') + purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + partner_id = fields.Many2one('res.partner', string='Customer') + proforma_invoice = fields.Boolean(string='Proforma Inv') + report_logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') + not_exist = fields.Boolean(string='Not Exist') + date_approve = fields.Datetime(string='Date Approve', tracking=3) + grand_total = fields.Float(string='Grand Total') + note = fields.Char(string='Note Logistik') + note_finance = fields.Char(string='Note Finance') diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index ae622ba4..d143c9e9 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -122,3 +122,8 @@ access_def_cargo_city,access.def.cargo.city,model_def_cargo_city,,1,1,1,1 access_def_cargo_district,access.def.cargo.district,model_def_cargo_district,,1,1,1,1 access_purchase_order_multi_uangmuka,access.purchase.order.multi_uangmuka,model_purchase_order_multi_uangmuka,,1,1,1,1 access_purchase_order_multi_uangmuka2,access.purchase.order.multi_uangmuka2,model_purchase_order_multi_uangmuka2,,1,1,1,1 +access_logbook_bill,access.logbook.sj,model_logbook_bill,,1,1,1,1 +access_logbook_bill_line,access.logbook.sj.line,model_logbook_bill_line,,1,1,1,1 +access_report_logbook_bill,access.report.logbook.sj,model_report_logbook_bill,,1,1,1,1 +access_report_logbook_bill_line,access.report.logbook.sj.line,model_report_logbook_bill_line,,1,1,1,1 +access_report_logbook_bill_line,access.report.logbook.sj.line,model_report_logbook_bill_line,,1,1,1,1 diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index af07ba38..40ce135c 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -20,6 +20,16 @@ 1 1 + + + Logbook Bill + report.logbook.bill + TRUE + LSB/%(year)s/ + 5 + 1 + 1 + Stock Picking Code diff --git a/indoteknik_custom/views/logbook_bill.xml b/indoteknik_custom/views/logbook_bill.xml new file mode 100644 index 00000000..25f1d704 --- /dev/null +++ b/indoteknik_custom/views/logbook_bill.xml @@ -0,0 +1,55 @@ + + + + Logbook Bill + logbook.bill + +
+ + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Logbook Bill + logbook.bill + ir.actions.act_window + form + + new + + + +
\ No newline at end of file diff --git a/indoteknik_custom/views/mail_template_efaktur.xml b/indoteknik_custom/views/mail_template_efaktur.xml new file mode 100644 index 00000000..ca0ea427 --- /dev/null +++ b/indoteknik_custom/views/mail_template_efaktur.xml @@ -0,0 +1,26 @@ + + + + + Invoice: Send mail efaktur document + + Your Invoice ${object.name} + sales@indoteknik.com + ${object.partner_id.email|safe} + +

Dengan Hormat Bpk/Ibu ${object.partner_id.name},

+

Terlampir Faktur Pajak atas Invoice ${object.name}.

+

Keterangan:

+

Mohon dicek langsung faktur pajak terlampir, terutama informasi nomor NPWP dan alamat NPWP serta nama pembelian barang. Jika ada yang tidak sesuai, mohon segera menginformasikan kepada kami paling lambat 1 (satu) minggu dari tanggal email ini. Revisi faktur pajak tidak dapat kami proses apabila sudah melewati 1 (satu) minggu. Harap maklum.

+

Mohon balas email ini jika sudah menerima, terima kasih.

+

Best Regards,
+ PT. Indoteknik Dotcom Gemilang
+ Jl. Bandengan Utara 85A No. 8-9 Penjaringan.
+ Kec. Penjaringan, Jakarta Utara - DKI Jakarta
+ Telp: 021-2933 8828 / 29 | GSM: 0813 9000 7430 / 31
+ Email: sales@indoteknik.com | Whatsapp: 0812 8080 622

+
+ +
+
+
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 08ff7e84..2ae96d7e 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -92,6 +92,7 @@ + @@ -136,6 +137,7 @@ +
@@ -154,6 +156,7 @@ + diff --git a/indoteknik_custom/views/report_logbook_bill.xml b/indoteknik_custom/views/report_logbook_bill.xml new file mode 100644 index 00000000..fc461400 --- /dev/null +++ b/indoteknik_custom/views/report_logbook_bill.xml @@ -0,0 +1,97 @@ + + + + report.logbook.bill.tree + report.logbook.bill + + + + + + + + + + + + + + + + report.logbook.bill.line.tree + report.logbook.bill.line + + + + + + + + + + + + + + + + + + + + report.logbook.bill.form + report.logbook.bill + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + Report Logbook Bill + ir.actions.act_window + report.logbook.bill + tree,form + + + + \ No newline at end of file -- cgit v1.2.3