Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0] [ADD] stock_ux: Wizard to cancel mass stock remaining. #259

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion stock_ux/__manifest__.py
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Stock UX',
'version': '13.0.1.4.0',
'version': '13.0.1.5.0',
'category': 'Warehouse Management',
'sequence': 14,
'summary': '',
Expand Down Expand Up @@ -49,6 +49,7 @@
'views/report_deliveryslip.xml',
'wizards/stock_operation_wizard_views.xml',
'wizards/res_config_settings_views.xml',
'wizards/stock_mass_cancel_remaining_wizard_views.xml',
'report/stock_ux_report.xml',
],
'demo': [
Expand Down
1 change: 1 addition & 0 deletions stock_ux/wizards/__init__.py
Expand Up @@ -4,3 +4,4 @@
##############################################################################
from . import res_config_settings
from . import stock_operation_wizard
from . import stock_mass_cancel_remaining_wizard
53 changes: 53 additions & 0 deletions stock_ux/wizards/stock_mass_cancel_remaining_wizard.py
@@ -0,0 +1,53 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api, _
from odoo.exceptions import UserError


class StockMassCancelRemainingWizard(models.TransientModel):
_name = "stock.mass.cancel.remaining.wizard"
_description = "Stock mass cancel remaining wizard"

move_ids = fields.Many2many('stock.move', readonly=True)
model = fields.Char()

@api.model
def default_get(self, fields):
vals = super().default_get(fields)
moves_ids = self.env.context.get('moves_ids')
model = self.env.context.get('model')
if model and moves_ids:
vals['move_ids'] = [(6, 0, moves_ids)]
vals['model'] = model
return vals

def action_confirm(self):
if self.model == 'sale.order.line':
orders = self.move_ids.mapped('sale_line_id')
elif self.model == 'purchase.order.line':
orders = self.move_ids.mapped('purchase_line_id')
else:
raise UserError("This operation it's Only for Sale/Purchase moves")
bom_enable = 'bom_ids' in self.env['product.template']._fields
for line in orders.filtered('product_id'):
if bom_enable:
bom = self.env['mrp.bom']._bom_find(
product=line.product_id)
if bom.type == 'phantom':
raise UserError(_(
"Cancel remaining can't be called for Kit Products "
"(products with a bom of type kit)."))
old_product_uom_qty = line.product_uom_qty
line.with_context(
bypass_protecion=True).product_uom_qty = line.qty_delivered
to_cancel_moves = line.move_ids.filtered(
lambda x: x.state not in ['done', 'cancel'])
to_cancel_moves._cancel_quantity()
line.order_id.message_post(
body=_(
'Cancel remaining call for line "%s" (id %s), line '
'qty updated from %s to %s') % (
line.name, line.id,
old_product_uom_qty, line.product_uom_qty))
27 changes: 27 additions & 0 deletions stock_ux/wizards/stock_mass_cancel_remaining_wizard_views.xml
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<odoo>

<record id="view_stock_operation_wizard_form" model="ir.ui.view">
<field name="name">stock.mass.cancel.remaining.wizard.form</field>
<field name="model">stock.mass.cancel.remaining.wizard</field>
<field name="arch" type="xml">
<form string="Cancel Remaining">
<div class="alert alert-warning" colspan="4" role="alert">
<p>
Note that this action cannot be undone and check the list of movements below.
</p>
</div>
<group>
<group string="Moves">
<field name="move_ids" nolabel="1"/>
</group>
</group>
<footer>
<button string="Confirm" name="action_confirm" type="object" class="oe_highlight"/>
<button string="Cancel" class="btn-secondary" special="cancel" />
</footer>
</form>
</field>
</record>

</odoo>