Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] purchase_receipt_expectation_manual_split: Migration to version 16 #1906

Open
wants to merge 6 commits into
base: 16.0
Choose a base branch
from
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
87 changes: 87 additions & 0 deletions purchase_receipt_expectation_manual_split/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
==============================================
Purchase Receipt Expectation - Manual w/ Split
==============================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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_receipt_expectation_manual_split
: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_receipt_expectation_manual_split
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/142/16.0
:alt: Try me on Runbot

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

This module extends ``purchase_receipt_expectation_manual`` by splitting
received purchase lines.

**Table of contents**

.. contents::
:local:

Usage
=====

This module extends ``purchase_receipt_expectation_manual`` by splitting
received purchase lines.

When the manual receipt wizard is confirmed, new purchase lines are generated
with the wizard lines; then, the new PO lines are used to create the stock
moves for the picking.

Moreover, when the picking gets cancelled, the split lines are merged back into
their origin line.

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_receipt_expectation_manual_split%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
~~~~~~~

* Camptocamp SA

Contributors
~~~~~~~~~~~~

* Silvio Gregorini <silvio.gregorini@camptocamp.com>

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_receipt_expectation_manual_split>`_ project on GitHub.

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

from . import models
from . import wizards
15 changes: 15 additions & 0 deletions purchase_receipt_expectation_manual_split/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Purchase Receipt Expectation - Manual w/ Split",
"version": "16.0.1.0.0",
"category": "Purchase Management",
"author": "Camptocamp SA, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"license": "AGPL-3",
"depends": [
"purchase_receipt_expectation_manual",
],
"installable": True,
}
50 changes: 50 additions & 0 deletions purchase_receipt_expectation_manual_split/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_receipt_expectation_manual_split
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-10 15:41+0000\n"
"PO-Revision-Date: 2022-02-10 15:41+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model.fields,field_description:purchase_receipt_expectation_manual_split.field_purchase_order_line__manually_split_from_line_id
msgid "Manually Split From Line"
msgstr "Split manuel depuis la ligne"

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model.fields,field_description:purchase_receipt_expectation_manual_split.field_purchase_order_line__manually_split_into_line_ids
msgid "Manually Split Into Line"
msgstr "Split manuel sur la ligne"

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model,name:purchase_receipt_expectation_manual_split.model_purchase_order_manual_receipt_wizard_line
msgid "PO Manual Receipt Wizard Line"
msgstr "Wizard de réception manuelle des PO lines"

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model.fields,field_description:purchase_receipt_expectation_manual_split.field_purchase_order_line__product_qty_pre_split
msgid "Pre-split Original Qty"
msgstr "Quantité Originale Avant Pré-Split "

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model,name:purchase_receipt_expectation_manual_split.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Ligne de commande d'achat"

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model,name:purchase_receipt_expectation_manual_split.model_stock_move
msgid "Stock Move"
msgstr ""

#~ msgid "Transfer"
#~ msgstr "Transfert"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_receipt_expectation_manual_split
#
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_receipt_expectation_manual_split
#: model:ir.model.fields,field_description:purchase_receipt_expectation_manual_split.field_purchase_order_line__manually_split_from_line_id
msgid "Manually Split From Line"
msgstr ""

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model.fields,field_description:purchase_receipt_expectation_manual_split.field_purchase_order_line__manually_split_into_line_ids
msgid "Manually Split Into Line"
msgstr ""

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model,name:purchase_receipt_expectation_manual_split.model_purchase_order_manual_receipt_wizard_line
msgid "PO Manual Receipt Wizard Line"
msgstr ""

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model.fields,field_description:purchase_receipt_expectation_manual_split.field_purchase_order_line__product_qty_pre_split
msgid "Pre-split Original Qty"
msgstr ""

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model,name:purchase_receipt_expectation_manual_split.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: purchase_receipt_expectation_manual_split
#: model:ir.model,name:purchase_receipt_expectation_manual_split.model_stock_move
msgid "Stock Move"
msgstr ""
5 changes: 5 additions & 0 deletions purchase_receipt_expectation_manual_split/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import purchase_order_line
from . import stock_move
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.tools import float_is_zero


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

product_qty_pre_split = fields.Float(
digits="Product Unit of Measure",
string="Pre-split Original Qty",
readonly=True,
)
manually_split_from_line_id = fields.Many2one(
"purchase.order.line",
ondelete="restrict",
readonly=True,
)
manually_split_into_line_ids = fields.One2many(
"purchase.order.line",
"manually_split_from_line_id",
readonly=True,
)

def _unlink_except_purchase_or_done(self):
# OVERRIDE: this method is originally decorated with `api.ondelete()`,
# which makes Odoo trigger this method whenever a line is deleted, and
# will raise an error if the line's order is either 'done' or
# 'purchase'. However, this will make it impossible to merge PO lines
# when a manual picking is cancelled.
# While merging the split line into its original line, adding
# the `manually_split` flag will make sure everything will work
# correctly.
lines = self.filtered(lambda x: x.order_id.receipt_expectation != "manual")
return super(PurchaseOrderLine, lines)._unlink_except_purchase_or_done()

def _create_or_update_picking(self):
# OVERRIDE: the `purchase_stock` module introduces this method that
# is called whenever a PO line is created in a confirmed order, or
# when line's qty is changed in a confirmed order. This means that
# splitting a PO line from the wizard will call this method, that will
# create or update a picking which is not the one we're creating from
# the manual wizard. As a result, we'll find ourselves with unwanted
# data (a stock move qty might be changed, a new picking might be
# created, etc).
# While copying the old PO line to create the split line, adding
# the `manually_split` flag will make sure everything will work
# correctly.
lines = self.filtered(lambda x: x.order_id.receipt_expectation != "manual")
return super(PurchaseOrderLine, lines)._create_or_update_picking()

@api.depends("manually_split_from_line_id")
def _compute_feasible_for_manual_receipt(self):
# OVERRIDE: original line is feasible if delivery method is via stock
# moves; here, we'll also add the condition that the line should not
# have been split from another line
split = self.filtered("manually_split_from_line_id")
split.feasible_for_manual_receipt = False
return super(
PurchaseOrderLine, self - split
)._compute_feasible_for_manual_receipt()

def _split_purchase_line(self, copy_vals=None):
"""Splits purchase line in a new line"""
self.ensure_one()
copy_vals = dict(copy_vals or [])
# Before splitting: if the line has never been split before, set its
# current ordered qty as "pre-split qty"
if not self.manually_split_into_line_ids:
self.product_qty_pre_split = self.product_qty
# Copy the original line to a new line with wizard line data
new = self.copy(copy_vals)
# Remove the new line's qty from the original line's qty
to_remove = new.product_uom._compute_quantity(new.product_qty, self.product_uom)
self.product_qty = max(0, self.product_qty - to_remove)
return new

def _merge_back_into_original_line(self, quantity):
"""Reverts quantity from split lines to their origin lines"""
if not self.manually_split_from_line_id:
return
self.ensure_one()
origin = self.manually_split_from_line_id
origin.product_qty += self.product_uom._compute_quantity(
quantity, origin.product_uom
)
self.product_qty -= quantity
# Remove empty lines with no done moves attached
if float_is_zero(
self.product_qty, precision_rounding=self.product_uom.rounding
) and not any(move.state == "done" for move in self.move_ids):
self.unlink()
20 changes: 20 additions & 0 deletions purchase_receipt_expectation_manual_split/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class StockMove(models.Model):
_inherit = "stock.move"

def _action_cancel(self):
moves_to_cancel = self.filtered(lambda m: m.state != "cancel")
res = super()._action_cancel()
for move in moves_to_cancel:
if move.purchase_line_id:
move.purchase_line_id._merge_back_into_original_line(
move.product_uom._compute_quantity(
move.product_qty, move.purchase_line_id.product_uom
)
)
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Silvio Gregorini <silvio.gregorini@camptocamp.com>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends ``purchase_receipt_expectation_manual`` by splitting
received purchase lines.
9 changes: 9 additions & 0 deletions purchase_receipt_expectation_manual_split/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This module extends ``purchase_receipt_expectation_manual`` by splitting
received purchase lines.

When the manual receipt wizard is confirmed, new purchase lines are generated
with the wizard lines; then, the new PO lines are used to create the stock
moves for the picking.

Moreover, when the picking gets cancelled, the split lines are merged back into
their origin line.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading