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

[ADD] mrp_workoder_production_lot_force_name #51

Open
wants to merge 4 commits into
base: 12.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions mrp_workorder_production_lot_force_name/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
===========================
Force lot name in Workorder
===========================

A checkbox in product category activates a field to force lot name when the workorder is executed.

.. |badge1| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

|badge1|

Adds a new level in products with the custom values specified in a order
line, manufacturing order or a lot.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/avanzosc/odoo-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/avanzosc/mrp-addons/issues/new?body=module:%20mrp_workorder_production_lot_force_name%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* AvanzOSC

Contributors
~~~~~~~~~~~~

* Mikel Arregi <[email protected]>
* Ana Juaristi <[email protected]>
1 change: 1 addition & 0 deletions mrp_workorder_production_lot_force_name/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions mrp_workorder_production_lot_force_name/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "force lot name in workorders",
"version": "12.0.1.0.0",
"license": "AGPL-3",
"depends": [
"mrp",
],
"author": "AvanzOSC",
"website": "http://www.avanzosc.es",
"category": "Tools",
"data": [
'views/product_category_view.xml',
'views/mrp_workorder_view.xml',
],
'demo': [],
'installable': True,
'auto_install': False,
}
2 changes: 2 additions & 0 deletions mrp_workorder_production_lot_force_name/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mrp_workorder
from . import product_category
24 changes: 24 additions & 0 deletions mrp_workorder_production_lot_force_name/models/mrp_workorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2020 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"

force_lot_name = fields.Char("Lot Name")
display_force_name = fields.Boolean(compute="_compute_force_field")

@api.depends('force_lot_name')
def _compute_force_field(self):
for order in self:
product = order.product_id
order.display_force_name = product.categ_id.force_lot_name \
and product.tracking != 'none'

def record_production(self):
for order in self:
if order.display_force_name:
order.final_lot_id.name = order.force_lot_name
order.force_lot_name = ""
return super().record_production()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2020 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models


class ProductCategory(models.Model):
_inherit = "product.category"

force_lot_name = fields.Boolean("Force Workorder Lot Name")
1 change: 1 addition & 0 deletions mrp_workorder_production_lot_force_name/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_mrp_workorder_production_lot_force_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2020 Mikel Arregi - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo.tests import common


@common.at_install(False)
@common.post_install(True)
class TestMrpWorkorder(common.SavepointCase):

@classmethod
def setUpClass(cls):
super(TestMrpWorkorder, cls).setUpClass()
cls.mrp_production_model = cls.env['mrp.production']
cls.bom_model = cls.env['mrp.bom']
cls.product_model = cls.env['product.product']
cls.product_categ_model = cls.env['product.category']
cls.lot_model = cls.env['stock.production.lot']
cls.route_model = cls.env['mrp.routing']
cls.workcenter_model = cls.env['mrp.workcenter']
cls.operation_model = cls.env['mrp.routing.workcenter']
unit_id = cls.env.ref('uom.product_uom_unit').id
cls.product_categ = cls.product_categ_model.create({
'name': 'Product Category',
'force_lot_name': True,
})
cls.bom_product = cls.product_model.create({
'name': 'BoM product',
'uom_id': unit_id,
'tracking': 'serial',
'categ_id': cls.product_categ.id,
})
cls.lot = cls.lot_model.create({
'name': 'lot',
'product_id': cls.bom_product.id
})
cls.component1 = cls.product_model.create({
'name': 'Component1',
'uom_id': unit_id,
})
cls.component2 = cls.product_model.create({
'name': 'Component2',
'uom_id': unit_id,
})
cls.workcenter = cls.workcenter_model.create({
'name': 'wc1',
'resource_calendar_id': cls.env.ref(
'resource.resource_calendar_std').id,
})
cls.route = cls.route_model.create({
'name': 'route',
'resource_calendar_id': cls.env.ref(
'resource.resource_calendar_std').id,
'operation_ids':
[(0, 0, {'name': 'op1',
'workcenter_id': cls.workcenter.id,
})]
})
vals = {
'product_tmpl_id': cls.bom_product.product_tmpl_id.id,
'product_id': cls.bom_product.id,
'routing_id': cls.route.id,
'bom_line_ids':
[(0, 0, {'product_id': cls.component1.id,
'product_qty': 1,
'operation_id': cls.route.operation_ids[0].id}),
(0, 0, {'product_id': cls.component2.id,
'product_qty': 1})],
}
cls.mrp_bom = cls.bom_model.create(vals)
cls.production = cls.mrp_production_model.create({
'product_id': cls.bom_product.id,
'product_uom_id': cls.bom_product.uom_id.id,
'bom_id': cls.mrp_bom.id,
'routiog_id': cls.route.id,
})

def test_force_lot_name(self):
self.production.button_plan()
workorder = self.env['mrp.workorder'].search([])[0]
workorder.button_start()
workorder.final_lot_id = self.lot.id
self.assertTrue(workorder.display_force_name)
self.assertEqual(workorder.final_lot_id.name, 'lot')
workorder.force_lot_name = 'changed_lot'
workorder.record_production()
self.assertEqual(self.lot.name, 'changed_lot')
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record model="ir.ui.view" id="mrp_workorder_force_lot_name_form">
<field name="name">mrp.workoder.force.lot.name.form</field>
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit" />
<field name="arch" type="xml">
<xpath expr="//field[@name='final_lot_id']" position="before">
<field name="display_force_name" invisible="1"/>
<field name="force_lot_name" attrs="{'invisible':[('display_force_name', '=', False)], 'required':[('display_force_name', '=', True), ('state', '=', 'progress')]}"/>
</xpath>
</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record model="ir.ui.view" id="product_category_force_lot_name_form">
<field name="name">product.category.force.lot.name.form</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view" />
<field name="arch" type="xml">
<xpath expr="//group[@name='first']" position="after">
<group name="force_lot_name">
<field name="force_lot_name" />
</group>
</xpath>
</field>
</record>
</odoo>