diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-08-13 14:08:29 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-08-13 14:08:29 +0700 |
| commit | 7772fcd29c37b03ba0b23c233aa8e030a82a0d81 (patch) | |
| tree | 0de5a561389902af5a0d420f707954b1564e98c0 | |
| parent | 1fb90f4b0ea75ca0b9eb723924a2ba4ea27a5a65 (diff) | |
approval date doc
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/approval_date_doc.py | 49 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/approval_date_doc.xml | 61 | ||||
| -rw-r--r-- | indoteknik_custom/views/ir_sequence.xml | 10 |
6 files changed, 123 insertions, 0 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 32678ef5..b3c3bc5d 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -139,6 +139,7 @@ 'views/report_logbook_bill.xml', 'views/sale_order_multi_uangmuka_penjualan.xml', 'views/shipment_group.xml', + 'views/approval_date_doc.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 116354d6..e9ce587c 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -124,3 +124,4 @@ from . import report_logbook_bill from . import sale_order_multi_uangmuka_penjualan from . import shipment_group from . import sales_order_reject +from . import approval_date_doc diff --git a/indoteknik_custom/models/approval_date_doc.py b/indoteknik_custom/models/approval_date_doc.py new file mode 100644 index 00000000..e00b7416 --- /dev/null +++ b/indoteknik_custom/models/approval_date_doc.py @@ -0,0 +1,49 @@ +from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import timedelta, date, datetime +import logging + +_logger = logging.getLogger(__name__) + +class ApprovalDateDoc(models.Model): + _name = "approval.date.doc" + _description = "Approval Date Doc" + _rec_name = 'number' + + picking_id = fields.Many2one('stock.picking', string='Picking') + number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True) + driver_departure_date = fields.Datetime( + string='Driver Departure Date', + copy=False + ) + state = fields.Selection([('draft', 'Draft'), ('done', 'Done')], string='State', default='draft', tracking=True) + approve_date = fields.Datetime(string='Approve Date', copy=False) + approve_by = fields.Many2one('res.users', string='Approve By', copy=False) + sale_id = fields.Many2one('sale.order', string='Sale Order') + + @api.onchange('picking_id') + def onchange_picking_id(self): + if self.picking_id: + self.sale_id = self.picking_id.sale_id.id + + def check_invoice_so_picking(self): + for rec in self: + invoice = self.env['account.move'].search_count([('sale_id', '=', rec.picking_id.sale_id.id)]) + + if invoice < 1: + raise UserError("Sales Order Belum Memiliki Invoice, Anda Bisa Edit Di DO nya langsung") + + def button_approve(self): + if not self.env.user.is_accounting: + raise UserError("Hanya Accounting Yang Bisa Approve") + self.check_invoice_so_picking + self.picking_id.driver_departure_date = self.driver_departure_date + self.state = 'done' + self.approve_date = datetime.utcnow() + self.approve_by = self.env.user.id + + @api.model + def create(self, vals): + vals['number'] = self.env['ir.sequence'].next_by_code('approval.date.doc') or '0' + result = super(ApprovalDateDoc, self).create(vals) + return result diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 95ad57f0..5e7554a5 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -133,3 +133,4 @@ access_sale_order_multi_uangmuka_penjualan,access.sale.order.multi_uangmuka_penj access_shipment_group,access.shipment.group,model_shipment_group,,1,1,1,1 access_shipment_group_line,access.shipment.group.line,model_shipment_group_line,,1,1,1,1 access_sales_order_reject,access.sales.order.reject,model_sales_order_reject,,1,1,1,1 +access_approval_date_doc,access.approval.date.doc,model_approval_date_doc,,1,1,1,1 diff --git a/indoteknik_custom/views/approval_date_doc.xml b/indoteknik_custom/views/approval_date_doc.xml new file mode 100644 index 00000000..d6a70763 --- /dev/null +++ b/indoteknik_custom/views/approval_date_doc.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <record id="approval_date_doc_tree" model="ir.ui.view"> + <field name="name">approval.date.doc.tree</field> + <field name="model">approval.date.doc</field> + <field name="arch" type="xml"> + <tree> + <field name="number"/> + <field name="picking_id"/> + <field name="sale_id"/> + <field name="driver_departure_date"/> + <field name="state"/> + <field name="approve_date"/> + <field name="approve_by"/> + </tree> + </field> + </record> + + <record id="approval_date_doc_form" model="ir.ui.view"> + <field name="name">approval.date.doc.form</field> + <field name="model">approval.date.doc</field> + <field name="arch" type="xml"> + <form> + <header> + <button name="button_approve" + string="Approve" + type="object" + attrs="{'invisible': [('state', '=', 'done')]}" + /> + </header> + <sheet string="Approval Date Doc"> + <group> + <group> + <field name="number"/> + <field name="picking_id"/> + <field name="sale_id"/> + <field name="driver_departure_date"/> + <field name="approve_date"/> + <field name="approve_by"/> + <field name="state" readonly="1"/> + </group> + </group> + </sheet> + </form> + </field> + </record> + + <record id="approval_date_doc_action" model="ir.actions.act_window"> + <field name="name">Approval Date Doc</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">approval.date.doc</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_approval_date_doc" name="Approval Date Doc" + parent="account.menu_finance_receivables" + action="approval_date_doc_action" + sequence="100" + /> + +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index b4fb5c0c..b2768c71 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -11,6 +11,16 @@ <field name="number_increment">1</field> </record> + <record id="sequence_date_doc" model="ir.sequence"> + <field name="name">Approval Date Doc</field> + <field name="code">approval.date.doc</field> + <field name="active">TRUE</field> + <field name="prefix">ADD/%(year)s/</field> + <field name="padding">5</field> + <field name="number_next">1</field> + <field name="number_increment">1</field> + </record> + <record id="sequence_logbook_sj" model="ir.sequence"> <field name="name">Logbook SJ</field> <field name="code">report.logbook.sj</field> |
