cancel mrp order
This commit is contained in:
parent
e00e71bd3d
commit
c9949af167
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#############################################################################
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
#
|
||||
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
||||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
||||
#
|
||||
# You can modify it under the terms of the GNU AFFERO
|
||||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
# (AGPL v3) along with this program.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#############################################################################
|
||||
from . import models
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
{
|
||||
'name': 'Cancel Manufacturing Order',
|
||||
'category': 'Manufacturing',
|
||||
'summary': 'Allows users to cancel manufacturing order by clicking '
|
||||
'the button "CANCEL"',
|
||||
'description': 'Allow users to cancel manufacturing orders'
|
||||
'by clicking on "CANCEL" button. Also able to cancel '
|
||||
'multiple manufacturing orders from tree view by clicking '
|
||||
'on the Cancel Manufacturing Order" from Action menu',
|
||||
'author': 'Raman',
|
||||
'depends': ['base', 'mrp'],
|
||||
'data': [
|
||||
'security/cancel_mrp_order_groups.xml',
|
||||
'views/mrp_production_views.xml',
|
||||
],
|
||||
'license': 'LGPL-3',
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'application': False,
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
## Module <cancel_mrp_order>
|
||||
|
||||
#### 27.05.2025
|
||||
#### Version 18.0.1.0.0
|
||||
#### ADD
|
||||
|
||||
- Initial Commit for Cancel Manufacturing Order
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#############################################################################
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
#
|
||||
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
||||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
||||
#
|
||||
# You can modify it under the terms of the GNU AFFERO
|
||||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
# (AGPL v3) along with this program.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#############################################################################
|
||||
from . import mrp_production
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#############################################################################
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
#
|
||||
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
||||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
||||
#
|
||||
# You can modify it under the terms of the GNU AFFERO
|
||||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
# (AGPL v3) along with this program.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#############################################################################
|
||||
from odoo import models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import float_round
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
"""Inherit manufacturing order to add some function """
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
def checking_access(self, rec):
|
||||
"""Warning for cancel button in action"""
|
||||
if self.state == 'done':
|
||||
rec.action_cancel_manufacturing_order()
|
||||
else:
|
||||
raise UserError(_(
|
||||
"You cannot cancel an order that is not in Done state!"))
|
||||
|
||||
def _create_move_from_existing_move(self, move, factor, location_id,
|
||||
location_dest_id):
|
||||
"""Create a stock move while creating a manufacturing order"""
|
||||
return self.env['stock.move'].create({
|
||||
'name': move.name,
|
||||
'date': move.create_date,
|
||||
'product_id': move.product_id.id,
|
||||
'product_uom_qty': move.product_uom_qty * factor,
|
||||
'product_uom': move.product_uom.id,
|
||||
'procure_method': 'make_to_stock',
|
||||
'location_dest_id': location_dest_id.id,
|
||||
'location_id': location_id.id,
|
||||
'warehouse_id': location_dest_id.warehouse_id.id,
|
||||
'company_id': move.company_id.id,
|
||||
})
|
||||
|
||||
def action_cancel_manufacturing_order(self):
|
||||
"""To cancel manufacturing order while clicking the button cancel """
|
||||
consume_moves = self.env['stock.move']
|
||||
produce_moves = self.env['stock.move']
|
||||
factor = self.product_qty / self.product_uom_id._compute_quantity(
|
||||
self.product_qty, self.product_uom_id)
|
||||
finished_moves = self.move_finished_ids.filtered(lambda l: l.state == 'done')
|
||||
raw_moves = self.move_raw_ids.filtered(lambda l: l.state == 'done')
|
||||
for finished_move in finished_moves:
|
||||
consume_moves += self._create_move_from_existing_move(finished_move, factor, finished_move.location_dest_id,
|
||||
finished_move.location_id)
|
||||
for raw_move in raw_moves:
|
||||
produce_moves += self._create_move_from_existing_move(raw_move, factor, raw_move.location_dest_id,
|
||||
self.location_dest_id)
|
||||
if consume_moves:
|
||||
consume_moves._action_confirm()
|
||||
if produce_moves:
|
||||
produce_moves._action_confirm()
|
||||
finished_moves = consume_moves.filtered(lambda m: m.product_id == self.product_id)
|
||||
consume_moves -= finished_moves
|
||||
for finished_move in finished_moves:
|
||||
if finished_move.has_tracking != 'none':
|
||||
self.env['stock.move.line'].create({
|
||||
'move_id': finished_move.id,
|
||||
'quantity': finished_move.product_uom_qty,
|
||||
'product_id': finished_move.product_id.id,
|
||||
'product_uom_id': finished_move.product_uom.id,
|
||||
'location_id': finished_move.location_id.id,
|
||||
'location_dest_id': finished_move.location_dest_id.id,
|
||||
})
|
||||
else:
|
||||
finished_move.quantity = finished_move.product_uom_qty
|
||||
qty_already_used = defaultdict(float)
|
||||
for move in produce_moves | consume_moves:
|
||||
if move.has_tracking != 'none':
|
||||
original_move = move in produce_moves and self.move_raw_ids or self.move_finished_ids
|
||||
moves_lines = original_move.filtered(lambda m: m.product_id == move.product_id).mapped('move_line_ids')
|
||||
for move_line in moves_lines:
|
||||
taken_quantity = min(move.product_uom_qty,move_line.quantity - qty_already_used[move_line])
|
||||
if taken_quantity:
|
||||
self.env['stock.move.line'].create({
|
||||
'move_id': move.id,
|
||||
'lot_id': move_line.lot_id.id,
|
||||
'quantity': taken_quantity,
|
||||
'product_id': move.product_id.id,
|
||||
'product_uom_id': move_line.product_uom_id.id,
|
||||
'location_id': move.location_id.id,
|
||||
'location_dest_id': move.location_dest_id.id,
|
||||
})
|
||||
move.product_uom_qty -= taken_quantity
|
||||
qty_already_used[move_line] += taken_quantity
|
||||
else:
|
||||
move.quantity = float_round(
|
||||
move.product_uom_qty,
|
||||
precision_rounding=move.product_uom.rounding)
|
||||
stock_quant = self.env['stock.quant'].search([
|
||||
('product_id', '=', move.product_id.id),
|
||||
('location_id', 'in', [self.location_src_id.id])
|
||||
])
|
||||
for quant in stock_quant:
|
||||
quant.sudo().write({'quantity': quant.quantity + move.product_qty})
|
||||
|
||||
for line in finished_moves:
|
||||
stock_quant = self.env['stock.quant'].search([
|
||||
('product_id', '=', line.product_id.id),
|
||||
('location_id', 'in', [self.location_dest_id.id])
|
||||
])
|
||||
for quant in stock_quant:
|
||||
quant.sudo().write({'quantity': quant.quantity - line.product_qty})
|
||||
finished_moves.write({'state': 'done'})
|
||||
consume_moves.write({'state': 'done'})
|
||||
produce_moves.write({'state': 'done'})
|
||||
produced_move_line_ids = produce_moves.mapped('move_line_ids').filtered(lambda ml: ml.quantity > 0)
|
||||
consume_moves.mapped('move_line_ids').write({'produce_line_ids': [(6, 0, produced_move_line_ids.ids)]})
|
||||
raw_moves.sudo().write({'state': 'cancel'})
|
||||
raw_moves.mapped('move_line_ids').sudo().write({'state': 'cancel'})
|
||||
if self.sudo().mapped('workorder_ids'):
|
||||
self.sudo().mapped('workorder_ids').write({'state': 'cancel'})
|
||||
self.write({'state': 'cancel'})
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<!-- Group for cancel the manufacturing order-->
|
||||
<record id="cancel_mrp_order_group_cancel_manufacturing_order"
|
||||
model="res.groups">
|
||||
<field name="name">Cancel Manufacturing Orders</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding='UTF-8'?>
|
||||
<odoo>
|
||||
<!--Inherit view of mrp production to add a button cancel-->
|
||||
<record id="mrp_production_form_view" model="ir.ui.view">
|
||||
<field name="name">mrp.production.view.form.inherit.cancel.mrp.order</field>
|
||||
<field name="model">mrp.production</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='button_unbuild']" position="after">
|
||||
<button name="action_cancel_manufacturing_order" groups="cancel_mrp_order.cancel_mrp_order_group_cancel_manufacturing_order"
|
||||
invisible=" state not in ('done')"
|
||||
type="object"
|
||||
string="Cancel"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<!-- To add a button cancel manufacturing order under action menu-->
|
||||
<record id="action_production_order_cancel" model="ir.actions.server">
|
||||
<field name="name">Cancel Manufacturing Order</field>
|
||||
<field name="model_id" ref="mrp.model_mrp_production"/>
|
||||
<field name="binding_model_id" ref="mrp.model_mrp_production"/>
|
||||
<field name="binding_view_types">list</field>
|
||||
<field name="groups_id" eval="[(4, ref('cancel_mrp_order.cancel_mrp_order_group_cancel_manufacturing_order'))]"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
if records:
|
||||
for rec in records:
|
||||
rec.checking_access(rec)
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue