summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
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
parent98fd3104060a92991569a206aabf6c7c20b190e3 (diff)
logbook bill & send email efaktur document
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py2
-rw-r--r--indoteknik_custom/models/account_move.py12
-rw-r--r--indoteknik_custom/models/logbook_bill.py103
-rwxr-xr-xindoteknik_custom/models/purchase_order.py1
-rw-r--r--indoteknik_custom/models/report_logbook_bill.py98
5 files changed, 208 insertions, 8 deletions
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')