Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
107 changes: 107 additions & 0 deletions mrp_primecontractor_raw_material/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
================================
MRP Primecontractor Raw Material
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:972fc369d7bc264bb37ed18b3ffd186fb94dacce9567befe05699b9a16b114d2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| 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
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/18.0/mrp_primecontractor_raw_material
:alt: OCA/manufacture
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-18-0/manufacture-18-0-mrp_primecontractor_raw_material
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module helps managing as a subcontractor raw materials comming from
the prime contractor. It adds on the warehouse a new location view
(../PRM/) that will contain the raw material locations (one per prime
contractor).

Manufactued products from a Bill Of Material with configurated prime
contractor raw materials will take these raw materials from the
subcontractor location.

These locations can be resupplied from a configurated orderpoint and
will generate a receipt picking with a specific type (../PRM/) and the
prime contractor as partner.

**Table of contents**

.. contents::
:local:

Usage
=====

This module is activated on a warehouse by checking the "Primecontractor
Raw Material" checkbox on the warehouse form view.

To set up a prime contractor, start by adding a new location with the
prime contractor view as parent and with the prime contractor partner as
"Primecontractor".

Next check the "Primecontractor Raw Material" checkbox on the Bill Of
Material lines corresponding to the raw materials coming from the prime
contractor.

Finally set up the Prime Contractor Location on the Reordering Rules of
these raw materials products. The associated procurement group will be
set automatically.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_primecontractor_raw_material%0Aversion:%2018.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
-------

* Akretion

Contributors
------------

- `Akretion <https://www.akretion.com>`__:

- Florian Mounier

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/18.0/mrp_primecontractor_raw_material>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mrp_primecontractor_raw_material/__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_primecontractor_raw_material/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Akretion (http://www.akretion.com).
# @author Florian Mounier <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "MRP Primecontractor Raw Material",
"summary": "This module helps to handle raw material stock and flow for "
"subcontracted products.",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Akretion,Odoo Community Association (OCA)",
"category": "Manufacturing",
"website": "https://github.com/OCA/manufacture",
"depends": ["mrp_sale_info"],
"data": [
"views/mrp_bom_views.xml",
"views/stock_location_views.xml",
"views/stock_warehouse_views.xml",
],
}
5 changes: 5 additions & 0 deletions mrp_primecontractor_raw_material/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import mrp_bom
from . import mrp_production
from . import stock_location
from . import stock_orderpoint
from . import stock_warehouse
13 changes: 13 additions & 0 deletions mrp_primecontractor_raw_material/models/mrp_bom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Akretion (http://www.akretion.com).
# @author Florian Mounier <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models


class MrpBomLine(models.Model):
_inherit = "mrp.bom.line"

primecontractor_raw_material = fields.Boolean(
help="Define if this material comes from the prime contractor",
default=False,
)
47 changes: 47 additions & 0 deletions mrp_primecontractor_raw_material/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2023 Akretion (http://www.akretion.com).
# @author Florian Mounier <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, models
from odoo.exceptions import UserError


class MrpProduction(models.Model):
_inherit = "mrp.production"

def _get_primecontractor_location_src_id(self):
self.ensure_one()
warehouse = self.picking_type_id.warehouse_id
return self.env["stock.location"].search(
[
(
"location_id",
"child_of",
warehouse.primecontractor_view_location_id.id,
),
("primecontractor_id", "=", self.partner_id.id),
]
)

def _get_move_raw_values(
self,
product_id,
product_uom_qty,
product_uom,
operation_id=False,
bom_line=False,
):
res = super()._get_move_raw_values(
product_id, product_uom_qty, product_uom, operation_id, bom_line
)
if bom_line and bom_line.primecontractor_raw_material:
location = self._get_primecontractor_location_src_id()
if not location:
raise UserError(
_(
"You must have a prime contractor source location "
"for this customer since you have defined a prime "
"contractor raw material in your BOM."
)
)
res.update({"location_id": location.id})
return res
62 changes: 62 additions & 0 deletions mrp_primecontractor_raw_material/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2023 Akretion (http://www.akretion.com).
# @author Florian Mounier <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class Location(models.Model):
_inherit = "stock.location"

primecontractor_id = fields.Many2one(
"res.partner",
"Primecontractor",
check_company=True,
)

primecontractor_raw_material_location = fields.Boolean(
"Prime Contractor Raw Material Location",
compute="_compute_primecontractor_raw_material_location",
store=True,
)

primecontractor_procurement_group_id = fields.Many2one(
"procurement.group", "Prime Contractor Procurement Group", copy=False
)

@api.depends("location_id")
def _compute_primecontractor_raw_material_location(self):
for location in self:
location.primecontractor_raw_material_location = bool(
self.env["stock.warehouse"].search(
[
(
"primecontractor_view_location_id",
"parent_of",
location.location_id.id,
)
],
limit=1,
)
)

@api.model
def _prepare_primecontractor_procurement_group_vals(self, values):
return {
"name": values["name"],
"partner_id": values["primecontractor_id"],
"move_type": "direct",
}

@api.model_create_multi
def create(self, values_list):
for data in values_list:
if data.get("primecontractor_id"):
if not data.get("primecontractor_procurement_group_id"):
procurement_group_vals = (
self._prepare_primecontractor_procurement_group_vals(data)
)
data["primecontractor_procurement_group_id"] = (
self.env["procurement.group"].create(procurement_group_vals).id
)

return super().create(values_list)
21 changes: 21 additions & 0 deletions mrp_primecontractor_raw_material/models/stock_orderpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 Akretion (http://www.akretion.com).
# @author Florian Mounier <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class StockWarehouseOrderpoint(models.Model):
_inherit = "stock.warehouse.orderpoint"

group_id = fields.Many2one(
compute="_compute_group_id",
readonly=False,
)

@api.depends("location_id")
def _compute_group_id(self):
for orderpoint in self:
if orderpoint.location_id and orderpoint.location_id.primecontractor_id:
orderpoint.group_id = (
orderpoint.location_id.primecontractor_procurement_group_id
)
Loading
Loading