[IMP] stock: option to replenish product on scrap

Added a checkbox to run a replenishment of the scrapped quantities.
If the option is selected and replenishment is impossible, an error message is presented to the user upon trying to validate the scrap order.

Task: 2479234 (nr 11)
Community PR: https://github.com/odoo/odoo/pull/114315
Enterprise PR: https://github.com/odoo/enterprise/pull/37764

Part-of: odoo/odoo#114315
This commit is contained in:
Pieter Claeys (clpi)
2023-05-25 16:28:56 +02:00
parent a080337d7e
commit a7aff968b7
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -4,6 +4,7 @@
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_compare, float_is_zero
from odoo.tools.misc import clean_context
class StockScrap(models.Model):
@@ -52,6 +53,7 @@ class StockScrap(models.Model):
('done', 'Done')],
string='Status', default="draft", readonly=True, tracking=True)
date_done = fields.Datetime('Date', readonly=True)
should_replenish = fields.Boolean(string='Replenish Scrapped Quantities', states={'done': [('readonly', True)]})
@api.depends('product_id')
def _compute_product_uom_id(self):
@@ -143,8 +145,23 @@ class StockScrap(models.Model):
move.with_context(is_scrap=True)._action_done()
scrap.write({'state': 'done'})
scrap.date_done = fields.Datetime.now()
if scrap.should_replenish:
scrap.do_replenish()
return True
def do_replenish(self):
self.ensure_one()
self.with_context(clean_context(self.env.context)).env['procurement.group'].run([self.env['procurement.group'].Procurement(
self.product_id,
self.scrap_qty,
self.product_uom_id,
self.location_id,
self.name,
self.name,
self.company_id,
{}
)])
def action_get_stock_picking(self):
action = self.env['ir.actions.act_window']._for_xml_id('stock.action_picking_tree_all')
action['domain'] = [('id', '=', self.picking_id.id)]
+2
View File
@@ -70,6 +70,7 @@
<field name="date_done" attrs="{'invisible': [('state', '=', 'draft')]}"/>
<field name="picking_id" attrs="{'invisible': [('picking_id', '=', False)]}"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="should_replenish"/>
</group>
</group>
</sheet>
@@ -181,6 +182,7 @@
<field name="company_id" invisible="1"/>
<field name="location_id" groups="stock.group_stock_multi_locations" options="{'no_open': True, 'no_create': True}"/>
<field name="scrap_location_id" groups="stock.group_stock_multi_locations" options="{'no_open': True, 'no_create': True}" />
<field name="should_replenish"/>
</group>
</group>
<footer>