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
99 changes: 99 additions & 0 deletions purchase_stock_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=============================
Purchase Stock Operating Unit
=============================

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

.. |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%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/18.0/purchase_stock_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-18-0/operating-unit-18-0-purchase_stock_operating_unit
: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/operating-unit&target_branch=18.0
:alt: Try me on Runboat

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

This module is used to integrated between Purchase and Stock to send
Operating Unit in the warehouse that has been selected from Deliver To
to Stock Picking.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

1. Create a purchase order
2. Select Deliver To that have operating unit in warehouse
3. Confirm purchase order
4. you should have your operating unit on your stock picking

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/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/operating-unit/issues/new?body=module:%20purchase_stock_operating_unit%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
-------

* Ecosoft

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

- Saran Lim. <saranl@ecosoft.co.th>
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

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.

.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px
:target: https://github.com/Saran440
:alt: Saran440

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Saran440|

This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/18.0/purchase_stock_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions purchase_stock_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
16 changes: 16 additions & 0 deletions purchase_stock_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Purchase Stock Operating Unit",
"summary": "Copies the operating unit of purchase picking to the stock picking",
"version": "18.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Purchase Management",
"depends": ["purchase_operating_unit", "stock_operating_unit"],
"license": "AGPL-3",
"data": [],
"installable": True,
"maintainers": ["Saran440"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_stock_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: purchase_stock_operating_unit
#: code:addons/purchase_stock_operating_unit/models/purchase.py:0
#, python-format
msgid ""
"Configuration error. The Operating Unit in the Purchase and Deliver To must "
"be the same."
msgstr ""

#. module: purchase_stock_operating_unit
#: model:ir.model,name:purchase_stock_operating_unit.model_purchase_order
msgid "Purchase Order"
msgstr ""

#. module: purchase_stock_operating_unit
#: model:ir.model,name:purchase_stock_operating_unit.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""
4 changes: 4 additions & 0 deletions purchase_stock_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import purchase
from . import stock_rule
63 changes: 63 additions & 0 deletions purchase_stock_operating_unit/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.exceptions import UserError


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

picking_type_id = fields.Many2one(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional Test 👍

But I'm not sure. Should we use onchange instead compute with picking_type_id and operating_unit_id?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think onchange makes more sense. Maybe a constraint if there is inconsistency with the operating unit.

compute="_compute_picking_type_id", store=True, readonly=False
)
operating_unit_id = fields.Many2one(
compute="_compute_operating_unit_id",
store=True,
readonly=False,
)

@api.depends("operating_unit_id")
def _compute_picking_type_id(self):
for purchase in self:
if purchase.operating_unit_id:
purchase.picking_type_id = self.env["stock.picking.type"].search(
[
(
"warehouse_id.operating_unit_id",
"=",
purchase.operating_unit_id.id,
),
("code", "=", "incoming"),
],
limit=1,
)

@api.depends("picking_type_id")
def _compute_operating_unit_id(self):
for purchase in self:
if purchase.picking_type_id:
purchase.operating_unit_id = (
purchase.picking_type_id.warehouse_id.operating_unit_id
)

@api.constrains("operating_unit_id", "picking_type_id")
def _check_operating_unit_picking_type(self):
for rec in self:
if (
rec.operating_unit_id
and rec.picking_type_id.warehouse_id.operating_unit_id
and rec.operating_unit_id
!= rec.picking_type_id.warehouse_id.operating_unit_id
):
raise UserError(
self.env._(
"Configuration error. The Operating Unit in "
"the Purchase and Deliver To must be the same."
)
)

def _prepare_picking(self):
vals = super()._prepare_picking()
vals["operating_unit_id"] = self.operating_unit_id.id
return vals
14 changes: 14 additions & 0 deletions purchase_stock_operating_unit/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class StockRule(models.Model):
_inherit = "stock.rule"

def _prepare_purchase_order(self, company_id, origins, values):
res = super()._prepare_purchase_order(company_id, origins, values)
if self.operating_unit_id:
res["operating_unit_id"] = self.operating_unit_id.id
return res
3 changes: 3 additions & 0 deletions purchase_stock_operating_unit/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions purchase_stock_operating_unit/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Saran Lim. \<<saranl@ecosoft.co.th>\>
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
- Bhavesh Heliconia
3 changes: 3 additions & 0 deletions purchase_stock_operating_unit/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module is used to integrated between Purchase and Stock to send
Operating Unit in the warehouse that has been selected from Deliver To
to Stock Picking.
6 changes: 6 additions & 0 deletions purchase_stock_operating_unit/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this module, you need to:

1. Create a purchase order
2. Select Deliver To that have operating unit in warehouse
3. Confirm purchase order
4. you should have your operating unit on your stock picking
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading