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
79 changes: 79 additions & 0 deletions purchase_mto_owner/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
==================
Purchase MTO Owner
==================

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

.. |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%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_mto_owner
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_mto_owner
: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/purchase-workflow&target_branch=16.0
:alt: Try me on Runboat

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

This module propagates the owner_id from a source document to new
Purchase Order created by the stock rule.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/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/purchase-workflow/issues/new?body=module:%20purchase_mto_owner%0Aversion:%2016.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
-------

* Quartile

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

- `Quartile <https://www.quartile.co>`__:

- Aung Ko Ko Lin

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/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/16.0/purchase_mto_owner>`_ 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 purchase_mto_owner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions purchase_mto_owner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Purchase MTO Owner",
"version": "16.0.1.0.0",
"author": "Quartile, Odoo Community Association (OCA)",
"category": "Purchase Management",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase_order_owner"],
"license": "AGPL-3",
"installable": True,
}
1 change: 1 addition & 0 deletions purchase_mto_owner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_rule
36 changes: 36 additions & 0 deletions purchase_mto_owner/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


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

def _make_po_get_domain(self, company_id, values, partner):
domain = super()._make_po_get_domain(company_id, values, partner)
move_dest_recs = values.get("move_dest_ids")
if move_dest_recs:
origin_move = move_dest_recs[0]
if origin_move.restrict_partner_id:
domain += (("owner_id", "=", origin_move.restrict_partner_id.id),)
return domain

def _prepare_purchase_order(self, company_id, origins, values):
vals = super(StockRule, self)._prepare_purchase_order(
company_id, origins, values
)
values = values[0]
move_dest = values.get("move_dest_ids")
if move_dest:
# TODO: Should we simply get restrict_partner_id from move_dest?
if move_dest.picking_id.owner_id:
vals["owner_id"] = move_dest.picking_id.owner_id.id
else:
# Handle the case where mrp_production_ids exists
mrp_productions = getattr(
move_dest.group_id, "mrp_production_ids", None
)
if mrp_productions:
vals["owner_id"] = mrp_productions[0].owner_id.id
return vals
2 changes: 2 additions & 0 deletions purchase_mto_owner/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Quartile](https://www.quartile.co):
- Aung Ko Ko Lin
1 change: 1 addition & 0 deletions purchase_mto_owner/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module propagates the owner_id from a source document to new Purchase Order created by the stock rule.
Loading
Loading