diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-12 10:26:48 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-12 10:26:48 +0700 |
| commit | f03e6dc2ee2f3cd34eca15e81cd8964c07089ef4 (patch) | |
| tree | c871a3f5f2403eed9c2857a40e2ff5e5333d3609 | |
| parent | 82f0467cd3f014761fd35bd04eecc485ed8addda (diff) | |
new window
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/approval_unreserve.py | 69 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/approval_unreserve.xml | 75 | ||||
| -rw-r--r-- | indoteknik_custom/views/ir_sequence.xml | 10 |
6 files changed, 158 insertions, 0 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 8d8e8cec..e1a67592 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -142,6 +142,7 @@ 'views/approval_date_doc.xml', 'views/partner_payment_term.xml', 'views/vendor_payment_term.xml', + 'views/approval_unreserve.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 e9ce587c..fe3e02d4 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -125,3 +125,4 @@ from . import sale_order_multi_uangmuka_penjualan from . import shipment_group from . import sales_order_reject from . import approval_date_doc +from . import approval_unreserve diff --git a/indoteknik_custom/models/approval_unreserve.py b/indoteknik_custom/models/approval_unreserve.py new file mode 100644 index 00000000..4feb51fa --- /dev/null +++ b/indoteknik_custom/models/approval_unreserve.py @@ -0,0 +1,69 @@ +from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import timedelta, date +import logging + +_logger = logging.getLogger(__name__) + +class ApprovalUnreserve(models.Model): + _name = "approval.unreserve" + _description = "Approval Unreserve" + _inherit = ['mail.thread'] + _rec_name = 'number' + + number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True, default='New') + approval_line = fields.One2many('approval.unreserve.line', 'approval_id', string='Approval Unreserve Lines', auto_join=True) + state = fields.Selection([ + ('draft', 'Draft'), + ('waiting_approval', 'Waiting for Approval'), + ('approved', 'Approved'), + ('rejected', 'Rejected') + ], string="Status", default='draft', tracking=True) + request_date = fields.Date(string="Request Date", default=fields.Date.today, tracking=True) + approved_by = fields.Many2one('res.users', string="Approved By", readonly=True, tracking=True) + rejection_reason = fields.Text(string="Rejection Reason", tracking=True) + + @api.model + def create(self, vals): + if vals.get('number', 'New') == 'New': + vals['number'] = self.env['ir.sequence'].next_by_code('approval.unreserve') or 'New' + return super(ApprovalUnreserve, self).create(vals) + + def action_submit_for_approval(self): + self.write({'state': 'waiting_approval'}) + + def action_approve(self): + if self.state != 'waiting_approval': + raise UserError("Approval can only be done in 'Waiting for Approval' state") + self.write({ + 'state': 'approved', + 'approved_by': self.env.user.id + }) + # Trigger the unreserve function + self._trigger_unreserve() + + def action_reject(self, reason): + if self.state != 'waiting_approval': + raise UserError("Rejection can only be done in 'Waiting for Approval' state") + self.write({ + 'state': 'rejected', + 'rejection_reason': reason + }) + + def _trigger_unreserve(self): + # Get the related stock moves and perform the unreserve for approved lines + stock_move_obj = self.env['stock.move'] + for line in self.approval_line: + move = stock_move_obj.browse(line.move_id.id) + # Use the custom _do_unreserve method you defined earlier + move._do_unreserve(product=line.product_id, quantity=line.unreserve_qty) + +class ApprovalUnreserveLine(models.Model): + _name = 'approval.unreserve.line' + _description = 'Approval Unreserve Line' + _order = 'approval_id, id' + + approval_id = fields.Many2one('approval.unreserve', string='Approval Reference', required=True, ondelete='cascade', index=True, copy=False) + move_id = fields.Many2one('stock.move', string="Stock Move", required=True) + product_id = fields.Many2one('product.product', string="Product", related='move_id.product_id', readonly=True) + unreserve_qty = fields.Float(string="Quantity to Unreserve", required=True) diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 5e7554a5..f017545d 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -134,3 +134,5 @@ 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 +access_approval_unreserve,access.approval.unreserve,model_approval_unreserve,,1,1,1,1 +access_approval_unreserve_line,access.approval.unreserve.line,model_approval_unreserve_line,,1,1,1,1 diff --git a/indoteknik_custom/views/approval_unreserve.xml b/indoteknik_custom/views/approval_unreserve.xml new file mode 100644 index 00000000..cd238125 --- /dev/null +++ b/indoteknik_custom/views/approval_unreserve.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<odoo> + <record id="view_approval_unreserve_tree" model="ir.ui.view"> + <field name="name">approval.unreserve.tree</field> + <field name="model">approval.unreserve</field> + <field name="arch" type="xml"> + <tree string="Approval Unreserve"> + <field name="number"/> + <field name="request_date"/> + <field name="state"/> + <field name="approved_by"/> + </tree> + </field> + </record> + + <record id="approval_unreserve_line_tree" model="ir.ui.view"> + <field name="name">approval.unreserve.line.tree</field> + <field name="model">approval.unreserve.line</field> + <field name="arch" type="xml"> + <tree> + <field name="move_id"/> + <field name="product_id"/> + <field name="unreserve_qty"/> + </tree> + </field> + </record> + + <record id="approval_unreserve_form" model="ir.ui.view"> + <field name="name">approval.unreserve.form</field> + <field name="model">approval.unreserve</field> + <field name="arch" type="xml"> + <form create="false"> + <header> + <button name="action_submit_for_approval" type="object" string="Submit for Approval" attrs="{'invisible': [('state', '!=', 'draft')]}"/> + <button name="action_approve" type="object" string="Approve" attrs="{'invisible': [('state', '!=', 'waiting_approval')]}"/> + <button name="action_reject" type="object" string="Reject" attrs="{'invisible': [('state', '!=', 'waiting_approval')]}"/> + </header> + <sheet> + <group> + <group> + <field name="number"/> + <field name="request_date"/> + <field name="state"/> + <field name="approved_by"/> + </group> + </group> + <notebook> + <page string="Lines"> + <field name="approval_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="approval_unreserve_action" model="ir.actions.act_window"> + <field name="name">Approval Unreserve</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">approval.unreserve</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem + id="menu_approval_unreserve" + name="Approval Unreserve" + parent="sale.product_menu_catalog" + sequence="4" + action="approval_unreserve_action" + /> +</odoo> diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index b2768c71..dd501d8c 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_approval_unreserve" model="ir.sequence"> + <field name="name">Approval Unreserve</field> + <field name="code">approval.unreserve</field> + <field name="active">TRUE</field> + <field name="prefix">AU/%(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> |
