summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/logbook_bill.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-06-27 15:29:16 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-06-27 15:29:16 +0700
commite33f2d321ee4db6a6e6a86e35243100b9f107f22 (patch)
tree54da1eeaced0bf1894be9fa4fa00a5f16c76388c /indoteknik_custom/models/logbook_bill.py
parent98fd3104060a92991569a206aabf6c7c20b190e3 (diff)
logbook bill & send email efaktur document
Diffstat (limited to 'indoteknik_custom/models/logbook_bill.py')
-rw-r--r--indoteknik_custom/models/logbook_bill.py103
1 files changed, 103 insertions, 0 deletions
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')