diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-06-27 15:29:16 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-06-27 15:29:16 +0700 |
| commit | e33f2d321ee4db6a6e6a86e35243100b9f107f22 (patch) | |
| tree | 54da1eeaced0bf1894be9fa4fa00a5f16c76388c | |
| parent | 98fd3104060a92991569a206aabf6c7c20b190e3 (diff) | |
logbook bill & send email efaktur document
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 12 | ||||
| -rw-r--r-- | indoteknik_custom/models/logbook_bill.py | 103 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/report_logbook_bill.py | 98 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 5 | ||||
| -rw-r--r-- | indoteknik_custom/views/ir_sequence.xml | 10 | ||||
| -rw-r--r-- | indoteknik_custom/views/logbook_bill.xml | 55 | ||||
| -rw-r--r-- | indoteknik_custom/views/mail_template_efaktur.xml | 26 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 3 | ||||
| -rw-r--r-- | indoteknik_custom/views/report_logbook_bill.xml | 97 |
12 files changed, 407 insertions, 8 deletions
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 @@ <field name="number_next">1</field> <field name="number_increment">1</field> </record> + + <record id="sequence_logbook_bill" model="ir.sequence"> + <field name="name">Logbook Bill</field> + <field name="code">report.logbook.bill</field> + <field name="active">TRUE</field> + <field name="prefix">LSB/%(year)s/</field> + <field name="padding">5</field> + <field name="number_next">1</field> + <field name="number_increment">1</field> + </record> <record id="sequence_stock_picking_code" model="ir.sequence"> <field name="name">Stock Picking Code</field> 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 @@ +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <record id="view_logbook_bill_form" model="ir.ui.view"> + <field name="name">Logbook Bill</field> + <field name="model">logbook.bill</field> + <field name="arch" type="xml"> + <form> + <sheet> + <field name="name" invisible="1"/> + <field + name="logbook_bill_line" + mode="tree" + > + <tree editable="bottom"> + <control> + <create name="add_logbook_bill_line_control" string="Add a logbook"/> + </control> + <field name="name" required="1"/> + <field name="partner_id" readonly="1"/> + <field name="purchase_id" readonly="1"/> + <field name="invoice"/> + <field name="faktur_pajak"/> + <field name="surat_jalan"/> + <field name="proforma_invoice"/> + <field name="date_approve" readonly="1"/> + <field name="note"/> + <field name="note_finance"/> + </tree> + </field> + </sheet> + <footer> + <button name="create_logbook_bill" string="Submit" type="object" default_focus="1" class="oe_highlight"/> + <button string="Cancel" class="btn btn-secondary" special="cancel" /> + </footer> + </form> + </field> + </record> + + <record id="action_logbook_bill" model="ir.actions.act_window"> + <field name="name">Logbook Bill</field> + <field name="res_model">logbook.bill</field> + <field name="type">ir.actions.act_window</field> + <field name="view_mode">form</field> + <field name="view_id" ref="view_logbook_bill_form"/> + <field name="target">new</field> + </record> + + <menuitem + action="action_logbook_bill" + id="logbook_bill" + parent="stock.menu_stock_warehouse_mgmt" + name="Logbook Bill" + sequence="1" + /> +</odoo>
\ 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 @@ +<?xml version="1.0" ?> +<odoo> + <data> + <record id="mail_template_efaktur_document" model="mail.template"> + <field name="name">Invoice: Send mail efaktur document</field> + <field name="model_id" ref="model_account_move" /> + <field name="subject">Your Invoice ${object.name}</field> + <field name="email_from">sales@indoteknik.com</field> + <field name="email_to">${object.partner_id.email|safe}</field> + <field name="body_html" type="html"> + <p>Dengan Hormat Bpk/Ibu ${object.partner_id.name},</p> + <p>Terlampir Faktur Pajak atas Invoice ${object.name}.</p> + <p><strong>Keterangan:</strong></p> + <p>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.</p> + <p>Mohon balas email ini jika sudah menerima, terima kasih.</p> + <p>Best Regards,<br /> + PT. Indoteknik Dotcom Gemilang<br /> + Jl. Bandengan Utara 85A No. 8-9 Penjaringan.<br /> + Kec. Penjaringan, Jakarta Utara - DKI Jakarta<br /> + Telp: 021-2933 8828 / 29 | GSM: 0813 9000 7430 / 31<br /> + Email: sales@indoteknik.com | Whatsapp: 0812 8080 622</p> + </field> + <field name="auto_delete" eval="True" /> + </record> + </data> +</odoo> 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 @@ <field name="status_paid_cbd"/> <field name="from_apo"/> <field name="approval_edit_line"/> + <field name="logbook_bill_id"/> </field> <field name="order_line" position="attributes"> @@ -136,6 +137,7 @@ <field name="responsible_ids" widget="many2many_tags" optional="hide"/> <field name="matches_so" widget="many2many_tags" optional="hide"/> <field name="is_create_uangmuka" optional="hide"/> + <field name="logbook_bill_id" optional="hide"/> </field> </field> </record> @@ -154,6 +156,7 @@ <field name="is_create_uangmuka" optional="hide"/> <field name="responsible_ids" widget="many2many_tags" optional="hide"/> <field name="matches_so" widget="many2many_tags" optional="hide"/> + <field name="logbook_bill_id" optional="hide"/> </field> </field> </record> 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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <record id="report_logbook_bill_tree" model="ir.ui.view"> + <field name="name">report.logbook.bill.tree</field> + <field name="model">report.logbook.bill</field> + <field name="arch" type="xml"> + <tree create="0" delete="0"> + <field name="name"/> + <field name="approve_by"/> + <field name="created_by"/> + <field name="date"/> + <field name="date_approve"/> + <field name="approve_by_finance"/> + <field name="state"/> + <field name="state_pengajuan"/> + </tree> + </field> + </record> + + <record id="report_logbook_bill_line_tree" model="ir.ui.view"> + <field name="name">report.logbook.bill.line.tree</field> + <field name="model">report.logbook.bill.line</field> + <field name="arch" type="xml"> + <tree editable="bottom"> + <field name="name"/> + <field name="partner_id"/> + <field name="purchase_id"/> + <field name="invoice"/> + <field name="faktur_pajak"/> + <field name="surat_jalan"/> + <field name="proforma_invoice"/> + <field name="date_approve"/> + <field name="grand_total"/> + <field name="not_exist"/> + <field name="note"/> + <field name="note_finance"/> + </tree> + </field> + </record> + + <record id="report_logbook_bill_form" model="ir.ui.view"> + <field name="name">report.logbook.bill.form</field> + <field name="model">report.logbook.bill</field> + <field name="arch" type="xml"> + <form> + <header> + <button name="approve" + string="Validate" + type="object" + /> + </header> + <sheet string="Report logbook Bill"> + <div class="oe_button_box" name="button_box"/> + <group> + <group> + <field name="name" readonly="1"/> + <field name="date" readonly="1"/> + <field name="date_approve" readonly="1"/> + <field name="state_pengajuan" readonly="1"/> + <field name="pengajuan_by" readonly="1"/> + <field name="date_pengajuan" readonly="1"/> + </group> + <group> + <field name="approve_by_finance" readonly="1"/> + <field name="state" readonly="1"/> + <field name="created_by" readonly="1"/> + <field name="approve_by" readonly="1"/> + <field name="count_line" readonly="1"/> + </group> + </group> + <notebook> + <page string="Line"> + <field name="report_logbook_bill_line"/> + </page> + </notebook> + </sheet> + <div class="oe_chatter"> + <field name="message_follower_ids" widget="mail_followers"/> + <field name="message_ids" widget="mail_thread"/> + </div> + </form> + </field> + </record> + + <record id="report_logbook_bill_action" model="ir.actions.act_window"> + <field name="name">Report Logbook Bill</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">report.logbook.bill</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_report_logbook_bill" + name="Report Logbook Bill" + action="report_logbook_bill_action" + parent="account.menu_finance_reports" + sequence="200"/> +</odoo>
\ No newline at end of file |
