new module client_name_on_manufacturing_orders
This commit is contained in:
parent
ddce2423b8
commit
085ac55278
7 changed files with 153 additions and 0 deletions
1
client_name_on_manufacturing_orders/__init__.py
Normal file
1
client_name_on_manufacturing_orders/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import models
|
||||
34
client_name_on_manufacturing_orders/__manifest__.py
Normal file
34
client_name_on_manufacturing_orders/__manifest__.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#
|
||||
# Bemade Inc.
|
||||
#
|
||||
# Copyright (C) 2024-June Bemade Inc. (<https://www.bemade.org>).
|
||||
# Author: Marc Durepos (Contact : marc@bemade.org)
|
||||
#
|
||||
# This program is under the terms of the GNU Lesser General Public License,
|
||||
# version 3.
|
||||
#
|
||||
# For full license details, see https://www.gnu.org/licenses/lgpl-3.0.en.html.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
# DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
{
|
||||
'name': 'Client Name on Manufacturing Order',
|
||||
'version': '17.0.1.0.0',
|
||||
'summary': 'Show the customer name on manufacturing order views.',
|
||||
'category': 'Manufacturing',
|
||||
'author': 'Bemade Inc.',
|
||||
'website': 'http://www.bemade.org',
|
||||
'license': 'LGPL-3',
|
||||
'depends': ['sale_mrp'],
|
||||
'data': [
|
||||
'views/mrp_production_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False
|
||||
}
|
||||
1
client_name_on_manufacturing_orders/models/__init__.py
Normal file
1
client_name_on_manufacturing_orders/models/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import mrp_production
|
||||
21
client_name_on_manufacturing_orders/models/mrp_production.py
Normal file
21
client_name_on_manufacturing_orders/models/mrp_production.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
customer_ids = fields.Many2many(
|
||||
comodel_name='res.partner',
|
||||
compute="_compute_customers",
|
||||
string="Customers",
|
||||
)
|
||||
|
||||
@api.depends('procurement_group_id')
|
||||
def _compute_customers(self):
|
||||
for rec in self:
|
||||
rec.customer_ids = (rec.mapped('procurement_group_id').
|
||||
mapped('mrp_production_ids').
|
||||
mapped('move_dest_ids').
|
||||
mapped('group_id').
|
||||
mapped('sale_id').
|
||||
mapped('partner_id').ids)
|
||||
1
client_name_on_manufacturing_orders/tests/__init__.py
Normal file
1
client_name_on_manufacturing_orders/tests/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import test_mrp_production
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
from odoo.addons.sale_mrp.tests.test_sale_mrp_flow import TestSaleMrpFlowCommon
|
||||
from odoo.tests import Form, tagged
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestMrpProduction(TestSaleMrpFlowCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref=None):
|
||||
super().setUpClass(chart_template_ref)
|
||||
|
||||
def _setup_products(self):
|
||||
route_manufacture = self.company_data['default_warehouse'].manufacture_pull_id.route_id
|
||||
route_mto = self.company_data['default_warehouse'].mto_pull_id.route_id
|
||||
product_a = self._create_product('Product A', self.uom_unit, routes=[route_manufacture, route_mto])
|
||||
product_c = self._create_product('Product C', self.uom_kg)
|
||||
product_b = self._create_product('Product B', self.uom_dozen, routes=[route_manufacture, route_mto])
|
||||
product_d = self._create_product('Product D', self.uom_unit, routes=[route_manufacture, route_mto])
|
||||
# Bill of materials for Product A.
|
||||
with Form(self.env['mrp.bom']) as f:
|
||||
f.product_tmpl_id = product_a.product_tmpl_id
|
||||
f.product_qty = 2
|
||||
f.product_uom_id = self.uom_dozen
|
||||
with f.bom_line_ids.new() as line:
|
||||
line.product_id = product_b
|
||||
line.product_qty = 3
|
||||
line.product_uom_id = self.uom_unit
|
||||
with f.bom_line_ids.new() as line:
|
||||
line.product_id = product_c
|
||||
line.product_qty = 300.0
|
||||
line.product_uom_id = self.uom_gm
|
||||
with f.bom_line_ids.new() as line:
|
||||
line.product_id = product_d
|
||||
line.product_qty = 4
|
||||
line.product_uom_id = self.uom_unit
|
||||
return product_a
|
||||
|
||||
def _create_order(self, partner_name: str, product):
|
||||
order_form = Form(self.env['sale.order'])
|
||||
order_form.partner_id = self.env['res.partner'].create({'name': partner_name})
|
||||
with order_form.order_line.new() as line:
|
||||
line.product_id = product
|
||||
line.product_uom = self.uom_dozen
|
||||
line.product_uom_qty = 10
|
||||
return order_form.save()
|
||||
|
||||
def test_mo_single_client_correctly_listed(self):
|
||||
product_a = self._setup_products()
|
||||
|
||||
order = self._create_order('Test Partner', product_a)
|
||||
order.action_confirm()
|
||||
# A sales order creating an MO should have its partner listed in the MO's customer_ids field
|
||||
|
||||
self.assertNotEquals(order.mrp_production_count, 0)
|
||||
for mo in order.mrp_production_ids:
|
||||
self.assertIn(order.partner_id, mo.customer_ids)
|
||||
|
||||
def test_mo_multiple_so_clients_correctly_listed(self):
|
||||
product_a = self._setup_products()
|
||||
order1 = self._create_order('Test Partner 1', product_a)
|
||||
order2 = self._create_order('Test Partner 2', product_a)
|
||||
order1.action_confirm()
|
||||
order2.action_confirm()
|
||||
|
||||
# Merge the MOs together so that the resulting MO is linked to multiple SOs
|
||||
(order1.mrp_production_ids | order2.mrp_production_ids).action_merge()
|
||||
|
||||
self.assertTrue(order1.mrp_production_ids)
|
||||
self.assertTrue(order2.mrp_production_ids)
|
||||
self.assertEqual(order1.mrp_production_ids, order2.mrp_production_ids)
|
||||
for mo in order1.mrp_production_ids:
|
||||
self.assertIn(order1.partner_id, mo.customer_ids)
|
||||
self.assertIn(order2.partner_id, mo.customer_ids)
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="mrp_production_view_form_customer_name" model="ir.ui.view">
|
||||
<field name="name">mrp.production.view.form.customer_name</field>
|
||||
<field name="model">mrp.production</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='group_extra_info']//field[@name='user_id']" >
|
||||
<field name="customer_ids" widget="many2many_tags"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="mrp_production_view_tree_customer_name" model="ir.ui.view">
|
||||
<field name="name">mrp.production.view.form.customer_name</field>
|
||||
<field name="model">mrp.production</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="customer_ids" optional="show"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in a new issue