diff options
| author | William Henrotin <whe@odoo.com> | 2020-04-27 11:56:02 +0200 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2020-06-15 16:59:41 +0200 |
| commit | 0e2765f5fd0ca0079f1f024ec3a1448b6d2ea3db (patch) | |
| tree | 90ea03d1aca1bf87a080775e7db07977b645c5cc /addons/mrp/wizard | |
| parent | 1b6421285c6bc4c61be3242cea30c2813251cbc7 (diff) | |
[REF] mrp: no more produce wizard
Use a view similar as the pickings one.
task-2241471
Diffstat (limited to 'addons/mrp/wizard')
| -rw-r--r-- | addons/mrp/wizard/__init__.py | 1 | ||||
| -rw-r--r-- | addons/mrp/wizard/mrp_product_produce.py | 154 | ||||
| -rw-r--r-- | addons/mrp/wizard/mrp_product_produce_views.xml | 134 |
3 files changed, 0 insertions, 289 deletions
diff --git a/addons/mrp/wizard/__init__.py b/addons/mrp/wizard/__init__.py index 8cbc2288366..5047d85ede2 100644 --- a/addons/mrp/wizard/__init__.py +++ b/addons/mrp/wizard/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import mrp_product_produce from . import change_production_qty from . import stock_warn_insufficient_qty from . import mrp_production_backorder diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py deleted file mode 100644 index 7e2b47ac8ab..00000000000 --- a/addons/mrp/wizard/mrp_product_produce.py +++ /dev/null @@ -1,154 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from datetime import datetime - -from odoo import api, fields, models, _ -from odoo.exceptions import UserError -from odoo.tools import float_compare - - -class MrpProductProduce(models.TransientModel): - _name = "mrp.product.produce" - _description = "Record Production" - _inherit = ["mrp.abstract.workorder"] - - @api.model - def default_get(self, fields): - res = super(MrpProductProduce, self).default_get(fields) - production = self.env['mrp.production'] - production_id = self.env.context.get('default_production_id') or self.env.context.get('active_id') - if production_id: - production = self.env['mrp.production'].browse(production_id) - if production.exists(): - serial_finished = (production.product_id.tracking == 'serial') - todo_uom = production.product_uom_id.id - todo_quantity = self._get_todo(production) - if serial_finished: - todo_quantity = 1.0 - if production.product_uom_id.uom_type != 'reference': - todo_uom = self.env['uom.uom'].search([('category_id', '=', production.product_uom_id.category_id.id), ('uom_type', '=', 'reference')]).id - if 'production_id' in fields: - res['production_id'] = production.id - if 'product_id' in fields: - res['product_id'] = production.product_id.id - if 'product_uom_id' in fields: - res['product_uom_id'] = todo_uom - if 'serial' in fields: - res['serial'] = bool(serial_finished) - if 'qty_producing' in fields: - res['qty_producing'] = todo_quantity - if 'consumption' in fields: - res['consumption'] = production.bom_id.consumption if production.bom_id else 'flexible' - return res - - serial = fields.Boolean('Requires Serial') - product_tracking = fields.Selection(related="product_id.tracking") - is_pending_production = fields.Boolean(compute='_compute_pending_production') - - move_raw_ids = fields.One2many(related='production_id.move_raw_ids', string="PO Components") - move_finished_ids = fields.One2many(related='production_id.move_finished_ids') - - raw_workorder_line_ids = fields.One2many('mrp.product.produce.line', - 'raw_product_produce_id', string='Components') - finished_workorder_line_ids = fields.One2many('mrp.product.produce.line', - 'finished_product_produce_id', string='By-products') - production_id = fields.Many2one('mrp.production', 'Manufacturing Order', - required=True, ondelete='cascade') - - @api.depends('qty_producing') - def _compute_pending_production(self): - """ Compute if it exits remaining quantity once the quantity on the - current wizard will be processed. The purpose is to display or not - button 'continue'. - """ - for product_produce in self: - remaining_qty = product_produce._get_todo(product_produce.production_id) - product_produce.is_pending_production = remaining_qty - product_produce.qty_producing > 0.0 - - def continue_production(self): - """ Save current wizard and directly opens a new. """ - self.ensure_one() - self._record_production() - action = self.production_id.open_produce_product() - action['context'] = {'default_production_id': self.production_id.id} - return action - - def action_generate_serial(self): - self.ensure_one() - product_produce_wiz = self.env.ref('mrp.view_mrp_product_produce_wizard', False) - self.finished_lot_id = self.env['stock.production.lot'].create({ - 'product_id': self.product_id.id, - 'company_id': self.production_id.company_id.id - }) - return { - 'name': _('Produce'), - 'type': 'ir.actions.act_window', - 'view_mode': 'form', - 'res_model': 'mrp.product.produce', - 'res_id': self.id, - 'view_id': product_produce_wiz.id, - 'target': 'new', - } - - def do_produce(self): - """ Save the current wizard and go back to the MO. """ - self.ensure_one() - self._record_production() - self._check_company() - return {'type': 'ir.actions.act_window_close'} - - def _get_todo(self, production): - """ This method will return remaining todo quantity of production. """ - main_product_moves = production.move_finished_ids.filtered(lambda x: x.product_id.id == production.product_id.id) - todo_quantity = production.product_qty - sum(main_product_moves.mapped('quantity_done')) - todo_quantity = todo_quantity if (todo_quantity > 0) else 0 - return todo_quantity - - def _record_production(self): - # Check all the product_produce line have a move id (the user can add product - # to consume directly in the wizard) - for line in self._workorder_line_ids(): - line._check_line_sn_uniqueness() - # because of an ORM limitation (fields on transient models are not - # recomputed by updates in non-transient models), the related fields on - # this model are not recomputed by the creations above - self.invalidate_cache(['move_raw_ids', 'move_finished_ids']) - - # Save product produce lines data into stock moves/move lines - quantity = self.qty_producing - if float_compare(quantity, 0, precision_rounding=self.product_uom_id.rounding) <= 0: - raise UserError(_("The production order for '%s' has no quantity specified.") % self.product_id.display_name) - - self._check_sn_uniqueness() - self._update_finished_move() - self._update_moves() - if self.production_id.state == 'confirmed': - self.production_id.write({ - 'date_start': datetime.now(), - }) - - -class MrpProductProduceLine(models.TransientModel): - _name = 'mrp.product.produce.line' - _inherit = ["mrp.abstract.workorder.line"] - _description = "Record production line" - - raw_product_produce_id = fields.Many2one('mrp.product.produce', 'Component in Produce wizard') - finished_product_produce_id = fields.Many2one('mrp.product.produce', 'Finished Product in Produce wizard') - - @api.model - def _get_raw_workorder_inverse_name(self): - return 'raw_product_produce_id' - - @api.model - def _get_finished_workoder_inverse_name(self): - return 'finished_product_produce_id' - - def _get_final_lots(self): - product_produce_id = self.raw_product_produce_id or self.finished_product_produce_id - return product_produce_id.finished_lot_id | product_produce_id.finished_workorder_line_ids.mapped('lot_id') - - def _get_production(self): - product_produce_id = self.raw_product_produce_id or self.finished_product_produce_id - return product_produce_id.production_id diff --git a/addons/mrp/wizard/mrp_product_produce_views.xml b/addons/mrp/wizard/mrp_product_produce_views.xml deleted file mode 100644 index a83950c123e..00000000000 --- a/addons/mrp/wizard/mrp_product_produce_views.xml +++ /dev/null @@ -1,134 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<odoo> - - <record id="view_mrp_product_produce_wizard" model="ir.ui.view"> - <field name="name">MRP Product Produce</field> - <field name="model">mrp.product.produce</field> - <field name="arch" type="xml"> - <form string="Produce"> - <group> - <group> - <field name="serial" invisible="1"/> - <field name="company_id" invisible="1"/> - <field name="production_id" invisible="1"/> - <field name="product_id" readonly="1"/> - <field name="is_pending_production" invisible="1"/> - <label for="qty_producing" string="Quantity"/> - <div class="o_row"> - <field name="qty_producing" attrs="{'readonly': [('serial', '=', True)]}"/> - <field name="product_uom_id" readonly="1" groups="uom.group_uom"/> - </div> - <field name="product_tracking" invisible="1"/> - <label for="finished_lot_id" attrs="{'invisible': [('product_tracking', '=', 'none')]}"/> - <div class="o_row"> - <field name="finished_lot_id" attrs="{'invisible': [('product_tracking', '=', 'none')], 'required': [('product_tracking', '!=', 'none'), ('finished_lot_id', '!=', False)]}" context="{'default_product_id': product_id, 'default_company_id': company_id}"/> - <button name="action_generate_serial" type="object" class="btn btn-primary fa fa-plus-square-o" aria-label="Creates a new serial/lot number" title="Creates a new serial/lot number" role="img" attrs="{'invisible': ['|', ('product_tracking', '=', 'none'), ('finished_lot_id', '!=', False)]}"/> - </div> - </group> - </group> - <h4 attrs="{'invisible': [('raw_workorder_line_ids', '=', [])]}">Components</h4> - <group> - <field name="raw_workorder_line_ids" attrs="{'invisible': [('raw_workorder_line_ids', '=', [])]}" nolabel="1" context="{'w_production': True, 'active_id': production_id, 'default_finished_lot_id': finished_lot_id}"> - <tree editable="bottom" delete="0" decoration-danger="(qty_to_consume < qty_done)"> - <field name="company_id" invisible="1"/> - <field name="product_id" attrs="{'readonly': [('move_id', '!=', False)]}" required="1" domain="[('id', '!=', parent.product_id), ('type', 'in', ['product', 'consu']), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]" force_save="1"/> - <field name="product_tracking" invisible="1"/> - <field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" context="{'default_product_id': product_id, 'active_mo_id': parent.production_id, 'default_company_id': parent.company_id}" groups="stock.group_production_lot"/> - <field name="qty_to_consume" readonly="1" force_save="1"/> - <field name="qty_reserved" readonly="1" force_save="1" optional="show"/> - <field name="qty_done"/> - <field name="product_uom_id" readonly="1" force_save="1" groups="uom.group_uom"/> - <field name="move_id" invisible="1"/> - </tree> - </field> - </group> - <h4 attrs="{'invisible': [('finished_workorder_line_ids', '=', [])]}">By-products</h4> - <group> - <field name="finished_workorder_line_ids" attrs="{'invisible': [('finished_workorder_line_ids', '=', [])]}" nolabel="1" context="{'w_production': True, 'active_id': production_id, 'default_finished_lot_id': finished_lot_id}"> - <tree editable="bottom" delete="0" decoration-danger="(qty_to_consume < qty_done)"> - <field name="company_id" invisible="1"/> - <field name="product_id" attrs="{'readonly': [('move_id', '!=', False)]}" required="1" domain="[('id', '!=', parent.product_id), ('type', 'in', ['product', 'consu']), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]" force_save="1"/> - <field name="product_tracking" invisible="1"/> - <field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" context="{'default_product_id': product_id, 'default_company_id': company_id}" groups="stock.group_production_lot"/> - <field name="qty_to_consume" string="To Produce" readonly="1" force_save="1"/> - <field name="qty_done" string="Produced"/> - <field name="product_uom_id" readonly="1" force_save="1" groups="uom.group_uom"/> - <field name="move_id" invisible="1"/> - </tree> - </field> - </group> - <footer> - <button name="continue_production" attrs="{'invisible':[('is_pending_production', '=', False)]}" type="object" string="Continue" class="btn-primary"/> - <button name="do_produce" type="object" string="Save" class="btn-default btn-secondary" attrs="{'invisible':[('is_pending_production', '=', False)]}"/> - <button name="do_produce" type="object" string="Save" class="btn-primary" attrs="{'invisible':[('is_pending_production', '=', True)]}"/> - <button string="Discard" class="btn-default btn-secondary" special="cancel"/> - </footer> - </form> - </field> - </record> - - <record id="mrp_product_produce_line_form" model="ir.ui.view"> - <field name="name">MRP Product Produce Line</field> - <field name="model">mrp.product.produce.line</field> - <field name="priority">100</field> - <field name="arch" type="xml"> - <form> - <group> - <group> - <field name="company_id" invisible="1"/> - <field name="product_id"/> - <field name="product_tracking" invisible="1"/> - <field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/> - <field name="qty_to_consume" readonly="1" force_save="1"/> - <field name="qty_reserved" readonly="1" force_save="1" optional="show"/> - <field name="qty_done"/> - <field name="product_uom_id" readonly="1" force_save="1" groups="uom.group_uom"/> - <field name="move_id" invisible="1"/> - </group> - </group> - </form> - </field> - </record> - - <record id="mrp_product_produce_line_kanban" model="ir.ui.view"> - <field name="name">MRP Product Produce Line</field> - <field name="model">mrp.product.produce.line</field> - <field name="priority">100</field> - <field name="arch" type="xml"> - <kanban class="o_kanban_mobile"> - <field name="product_id"/> - <field name="lot_id"/> - <field name="qty_to_consume"/> - <field name="qty_reserved"/> - <field name="qty_done"/> - <field name="product_uom_id"/> - <templates> - <t t-name="kanban-box"> - <div t-attf-class="oe_kanban_global_click"> - <div class="o_kanban_record_top"> - <div class="o_kanban_record_headings"> - <strong class="o_kanban_record_title"><span><field name="product_id"/></span></strong> - </div> - </div> - <div class="o_kanban_record_body"> - <span>Lot <field name="lot_id"/></span><br/> - <span>Quantity To Consume <field name="qty_to_consume"/></span><br/> - <span>Quantity Reserved <field name="qty_reserved"/></span><br/> - <span>Quantity Done <field name="qty_done"/></span><br/> - </div> - </div> - </t> - </templates> - </kanban> - </field> - </record> - - <record id="act_mrp_product_produce" model="ir.actions.act_window"> - <field name="name">Produce</field> - <field name="type">ir.actions.act_window</field> - <field name="res_model">mrp.product.produce</field> - <field name="view_mode">form</field> - <field name="context">{}</field> - <field name="target">new</field> - </record> -</odoo> |
