mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[MIG] mrp_subcontracting_purchase: Adapt to OCA guidelines + initial work
This commit is contained in:
0
mrp_subcontracting_purchase/README.rst
Normal file
0
mrp_subcontracting_purchase/README.rst
Normal file
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Purchase and Subcontracting Management',
|
"name": "Purchase and Subcontracting Management",
|
||||||
'version': '0.1',
|
"version": "14.0.1.0.0",
|
||||||
'category': 'Manufacturing/Purchase',
|
"category": "Manufacturing/Purchase",
|
||||||
'description': """
|
"summary": """
|
||||||
This bridge module adds some smart buttons between Purchase and Subcontracting
|
This bridge module adds some smart buttons between Purchase and Subcontracting
|
||||||
""",
|
""",
|
||||||
'depends': ['mrp_subcontracting', 'purchase'],
|
"author": "Odoo S.A., Odoo Community Association (OCA)",
|
||||||
'data': [
|
"website": "https://github.com/OCA/manufacture",
|
||||||
'views/purchase_order_views.xml',
|
"depends": ["mrp_subcontracting", "purchase"],
|
||||||
'views/stock_picking_views.xml',
|
"data": [
|
||||||
|
"views/purchase_order_views.xml",
|
||||||
|
"views/stock_picking_views.xml",
|
||||||
],
|
],
|
||||||
'installable': True,
|
"installable": True,
|
||||||
'auto_install': True,
|
"auto_install": True,
|
||||||
'license': 'LGPL-3',
|
"license": "LGPL-3",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from . import stock_picking
|
from . import stock_picking
|
||||||
|
|||||||
@@ -1,25 +1,30 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from odoo import models, fields, api
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrder(models.Model):
|
class PurchaseOrder(models.Model):
|
||||||
_inherit = 'purchase.order'
|
_inherit = "purchase.order"
|
||||||
|
|
||||||
subcontracting_resupply_picking_count = fields.Integer(
|
subcontracting_resupply_picking_count = fields.Integer(
|
||||||
"Count of Subcontracting Resupply", compute='_compute_subcontracting_resupply_picking_count',
|
"Count of Subcontracting Resupply",
|
||||||
help="Count of Subcontracting Resupply for component")
|
compute="_compute_subcontracting_resupply_picking_count",
|
||||||
|
help="Count of Subcontracting Resupply for component",
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends('order_line.move_ids')
|
@api.depends("order_line.move_ids")
|
||||||
def _compute_subcontracting_resupply_picking_count(self):
|
def _compute_subcontracting_resupply_picking_count(self):
|
||||||
for purchase in self:
|
for purchase in self:
|
||||||
purchase.subcontracting_resupply_picking_count = len(purchase._get_subcontracting_resupplies())
|
purchase.subcontracting_resupply_picking_count = len(
|
||||||
|
purchase._get_subcontracting_resupplies()
|
||||||
|
)
|
||||||
|
|
||||||
def action_view_subcontracting_resupply(self):
|
def action_view_subcontracting_resupply(self):
|
||||||
return self._get_action_view_picking(self._get_subcontracting_resupplies())
|
return self._get_action_view_picking(self._get_subcontracting_resupplies())
|
||||||
|
|
||||||
def _get_subcontracting_resupplies(self):
|
def _get_subcontracting_resupplies(self):
|
||||||
moves_subcontracted = self.order_line.move_ids.filtered(lambda m: m.is_subcontract)
|
moves_subcontracted = self.order_line.move_ids.filtered(
|
||||||
|
lambda m: m.is_subcontract
|
||||||
|
)
|
||||||
subcontracted_productions = moves_subcontracted.move_orig_ids.production_id
|
subcontracted_productions = moves_subcontracted.move_orig_ids.production_id
|
||||||
return subcontracted_productions.picking_ids
|
return subcontracted_productions.picking_ids
|
||||||
|
|||||||
@@ -1,40 +1,49 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from odoo import models, fields, api, _
|
from odoo import _, api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class StockPicking(models.Model):
|
class StockPicking(models.Model):
|
||||||
_inherit = 'stock.picking'
|
_inherit = "stock.picking"
|
||||||
|
|
||||||
subcontracting_source_purchase_count = fields.Integer(
|
subcontracting_source_purchase_count = fields.Integer(
|
||||||
"Number of subcontracting PO Source", compute='_compute_subcontracting_source_purchase_count',
|
"Number of subcontracting PO Source",
|
||||||
help="Number of subcontracting Purchase Order Source")
|
compute="_compute_subcontracting_source_purchase_count",
|
||||||
|
help="Number of subcontracting Purchase Order Source",
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends('move_lines.move_dest_ids.raw_material_production_id')
|
@api.depends("move_lines.move_dest_ids.raw_material_production_id")
|
||||||
def _compute_subcontracting_source_purchase_count(self):
|
def _compute_subcontracting_source_purchase_count(self):
|
||||||
for picking in self:
|
for picking in self:
|
||||||
picking.subcontracting_source_purchase_count = len(picking._get_subcontracting_source_purchase())
|
picking.subcontracting_source_purchase_count = len(
|
||||||
|
picking._get_subcontracting_source_purchase()
|
||||||
|
)
|
||||||
|
|
||||||
def action_view_subcontracting_source_purchase(self):
|
def action_view_subcontracting_source_purchase(self):
|
||||||
purchase_order_ids = self._get_subcontracting_source_purchase().ids
|
purchase_order_ids = self._get_subcontracting_source_purchase().ids
|
||||||
action = {
|
action = {
|
||||||
'res_model': 'purchase.order',
|
"res_model": "purchase.order",
|
||||||
'type': 'ir.actions.act_window',
|
"type": "ir.actions.act_window",
|
||||||
}
|
}
|
||||||
if len(purchase_order_ids) == 1:
|
if len(purchase_order_ids) == 1:
|
||||||
action.update({
|
action.update(
|
||||||
'view_mode': 'form',
|
{
|
||||||
'res_id': purchase_order_ids[0],
|
"view_mode": "form",
|
||||||
})
|
"res_id": purchase_order_ids[0],
|
||||||
|
}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
action.update({
|
action.update(
|
||||||
'name': _("Source PO of %s", self.name),
|
{
|
||||||
'domain': [('id', 'in', purchase_order_ids)],
|
"name": _("Source PO of %s", self.name),
|
||||||
'view_mode': 'tree,form',
|
"domain": [("id", "in", purchase_order_ids)],
|
||||||
})
|
"view_mode": "tree,form",
|
||||||
|
}
|
||||||
|
)
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def _get_subcontracting_source_purchase(self):
|
def _get_subcontracting_source_purchase(self):
|
||||||
moves_subcontracted = self.move_lines.move_dest_ids.raw_material_production_id.move_finished_ids.move_dest_ids.filtered(lambda m: m.is_subcontract)
|
moves_subcontracted = self.move_lines.move_dest_ids.raw_material_production_id.move_finished_ids.move_dest_ids.filtered( # noqa
|
||||||
|
lambda m: m.is_subcontract
|
||||||
|
)
|
||||||
return moves_subcontracted.purchase_line_id.order_id
|
return moves_subcontracted.purchase_line_id.order_id
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import test_mrp_subcontracting_purchase
|
from . import test_mrp_subcontracting_purchase
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from odoo import Command
|
from odoo import Command
|
||||||
@@ -7,29 +6,38 @@ from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCom
|
|||||||
|
|
||||||
|
|
||||||
class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
|
class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
|
||||||
|
|
||||||
def test_count_smart_buttons(self):
|
def test_count_smart_buttons(self):
|
||||||
resupply_sub_on_order_route = self.env['stock.location.route'].search([('name', '=', 'Resupply Subcontractor on Order')])
|
resupply_sub_on_order_route = self.env["stock.location.route"].search(
|
||||||
(self.comp1 + self.comp2).write({'route_ids': [Command.link(resupply_sub_on_order_route.id)]})
|
[("name", "=", "Resupply Subcontractor on Order")]
|
||||||
|
)
|
||||||
|
(self.comp1 + self.comp2).write(
|
||||||
|
{"route_ids": [Command.link(resupply_sub_on_order_route.id)]}
|
||||||
|
)
|
||||||
|
|
||||||
# I create a draft Purchase Order for first in move for 10 kg at 50 euro
|
# I create a draft Purchase Order for first in move for 10 kg at 50 euro
|
||||||
po = self.env['purchase.order'].create({
|
po = self.env["purchase.order"].create(
|
||||||
'partner_id': self.subcontractor_partner1.id,
|
{
|
||||||
'order_line': [Command.create({
|
"partner_id": self.subcontractor_partner1.id,
|
||||||
'name': 'finished',
|
"order_line": [
|
||||||
'product_id': self.finished.id,
|
Command.create(
|
||||||
'product_qty': 1.0,
|
{
|
||||||
'product_uom': self.finished.uom_id.id,
|
"name": "finished",
|
||||||
'price_unit': 50.0}
|
"product_id": self.finished.id,
|
||||||
)],
|
"product_qty": 1.0,
|
||||||
})
|
"product_uom": self.finished.uom_id.id,
|
||||||
|
"price_unit": 50.0,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
po.button_confirm()
|
po.button_confirm()
|
||||||
|
|
||||||
self.assertEqual(po.subcontracting_resupply_picking_count, 1)
|
self.assertEqual(po.subcontracting_resupply_picking_count, 1)
|
||||||
action1 = po.action_view_subcontracting_resupply()
|
action1 = po.action_view_subcontracting_resupply()
|
||||||
picking = self.env[action1['res_model']].browse(action1['res_id'])
|
picking = self.env[action1["res_model"]].browse(action1["res_id"])
|
||||||
self.assertEqual(picking.subcontracting_source_purchase_count, 1)
|
self.assertEqual(picking.subcontracting_source_purchase_count, 1)
|
||||||
action2 = picking.action_view_subcontracting_source_purchase()
|
action2 = picking.action_view_subcontracting_source_purchase()
|
||||||
po_action2 = self.env[action2['res_model']].browse(action2['res_id'])
|
po_action2 = self.env[action2["res_model"]].browse(action2["res_id"])
|
||||||
self.assertEqual(po_action2, po)
|
self.assertEqual(po_action2, po)
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="purchase_order_form_mrp_subcontracting_purchase" model="ir.ui.view">
|
<record id="purchase_order_form_mrp_subcontracting_purchase" model="ir.ui.view">
|
||||||
<field name="name">purchase.order.inherited.form.mrp.subcontracting.purchase</field>
|
<field
|
||||||
|
name="name"
|
||||||
|
>purchase.order.inherited.form.mrp.subcontracting.purchase</field>
|
||||||
<field name="model">purchase.order</field>
|
<field name="model">purchase.order</field>
|
||||||
<field name="inherit_id" ref="purchase.purchase_order_form" />
|
<field name="inherit_id" ref="purchase.purchase_order_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//div[hasclass('oe_button_box')]/button[@name='action_view_picking']" position="before">
|
<xpath
|
||||||
|
expr="//div[hasclass('oe_button_box')]/button[@name='action_view_picking']"
|
||||||
|
position="before"
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
class="oe_stat_button" name="action_view_subcontracting_resupply"
|
class="oe_stat_button"
|
||||||
type="object" icon="fa-truck" attrs="{'invisible': [('subcontracting_resupply_picking_count', '=', 0)]}" groups="stock.group_stock_user">
|
name="action_view_subcontracting_resupply"
|
||||||
|
type="object"
|
||||||
|
icon="fa-truck"
|
||||||
|
attrs="{'invisible': [('subcontracting_resupply_picking_count', '=', 0)]}"
|
||||||
|
groups="stock.group_stock_user"
|
||||||
|
>
|
||||||
<div class="o_field_widget o_stat_info">
|
<div class="o_field_widget o_stat_info">
|
||||||
<span class="o_stat_value"><field name="subcontracting_resupply_picking_count"/></span>
|
<span class="o_stat_value"><field
|
||||||
|
name="subcontracting_resupply_picking_count"
|
||||||
|
/></span>
|
||||||
<span class="o_stat_text">Resupply</span>
|
<span class="o_stat_text">Resupply</span>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -7,10 +7,17 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
|
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
|
||||||
<button
|
<button
|
||||||
class="oe_stat_button" name="action_view_subcontracting_source_purchase"
|
class="oe_stat_button"
|
||||||
type="object" icon="fa-shopping-cart" attrs="{'invisible': [('subcontracting_source_purchase_count', '=', 0)]}" groups="stock.group_stock_user">
|
name="action_view_subcontracting_source_purchase"
|
||||||
|
type="object"
|
||||||
|
icon="fa-shopping-cart"
|
||||||
|
attrs="{'invisible': [('subcontracting_source_purchase_count', '=', 0)]}"
|
||||||
|
groups="stock.group_stock_user"
|
||||||
|
>
|
||||||
<div class="o_field_widget o_stat_info">
|
<div class="o_field_widget o_stat_info">
|
||||||
<span class="o_stat_value"><field name="subcontracting_source_purchase_count"/></span>
|
<span class="o_stat_value"><field
|
||||||
|
name="subcontracting_source_purchase_count"
|
||||||
|
/></span>
|
||||||
<span class="o_stat_text">Source PO</span>
|
<span class="o_stat_text">Source PO</span>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../mrp_subcontracting_purchase
|
||||||
6
setup/mrp_subcontracting_purchase/setup.py
Normal file
6
setup/mrp_subcontracting_purchase/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user