mrp_usability: Allow to change the destination location until 'Mark as done'

Native behavior: it is only possible to change the destination stock
location of a production order in draft state.
This commit is contained in:
Alexis de Lattre
2024-04-09 19:27:07 +02:00
parent 2f784eb1a0
commit 2c794033b0
2 changed files with 26 additions and 6 deletions

View File

@@ -3,12 +3,26 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models from odoo import fields, models, Command
class MrpProduction(models.Model): class MrpProduction(models.Model):
_inherit = 'mrp.production' _inherit = 'mrp.production'
location_dest_id = fields.Many2one(tracking=True)
# Target: allow to modify location_dest_id until the button 'Mark as done' is pushed
# I didn't find a better implementation... feel free to improve if you find one
def _compute_move_finished_ids(self):
for prod in self:
if prod.state not in ('draft', 'done') and prod.location_dest_id:
vals = {'location_dest_id': prod.location_dest_id.id}
prod.move_finished_ids = [
Command.update(m.id, vals) for m in prod.move_finished_ids
if m.state != 'done'
]
super()._compute_move_finished_ids()
# Method used by the report, inherited in this module # Method used by the report, inherited in this module
# @api.model # @api.model
# def get_stock_move_sold_out_report(self, move): # def get_stock_move_sold_out_report(self, move):

View File

@@ -13,11 +13,17 @@
<field name="model">mrp.production</field> <field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/> <field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<!-- <field name="user_id" position="before">
<label for="product_qty" position="before"> <!-- I can't use position="move" because it would match another field in an embedded tree view -->
<field name="location_src_id" groups="stock.group_stock_multi_locations" options="{'no_create': True}" attrs="{'readonly': [('state', '!=', 'draft')]}" position="move"/> <field name="location_src_id" groups="stock.group_stock_multi_locations" options="{'no_create': True}" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="location_dest_id" groups="stock.group_stock_multi_locations" options="{'no_create': True}" attrs="{'readonly': [('state', '!=', 'draft')]}" position="move"/> <field name="location_dest_id" groups="stock.group_stock_multi_locations" options="{'no_create': True}" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"/>
</label> --> </field>
<!-- It is important to remove the original field location_dest_id
and not just set it as invisible because it cancels the changes -->
<xpath expr="//page[@name='miscellaneous']/group/group/field[@name='location_dest_id']" position="replace"/>
<xpath expr="//page[@name='miscellaneous']/group/group/field[@name='location_src_id']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//page[@name='miscellaneous']/group/group/field[@name='date_deadline']" position="after"> <xpath expr="//page[@name='miscellaneous']/group/group/field[@name='date_deadline']" position="after">
<field name="date_start"/> <field name="date_start"/>
<field name="date_finished"/> <field name="date_finished"/>