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

[16.0][MIG] purchase_stock_picking_invoice_link: Migration to 16.0 #1198

Merged
Merged
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
101 changes: 101 additions & 0 deletions purchase_stock_picking_invoice_link/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
===================================
Purchase Stock Picking Invoice Link
===================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/15.0/purchase_stock_picking_invoice_link
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-15-0/stock-logistics-workflow-15-0-purchase_stock_picking_invoice_link
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/154/15.0
:alt: Try me on Runbot

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

This module adds a link between purchases, pickings and invoices as well as
on the lines. Invoices are generated from purchase orders. With this module,
you can find back which deliveries an invoice relates to.

This module improves **stock_picking_invoice_link** module by linking
purchases, pickings and invoices.

**Table of contents**

.. contents::
:local:

Usage
=====

* Create a Purchase Order and confirm.
* Deliver its pickings totally or partially.
* Create an invoice of the goods delivered.
* If you open invoice form, you must see a smart-button labeled *Delivery*.
* Click on this smart-button to see the linked pickings.

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

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

* Tecnativa

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

* `Tecnativa <https://www.tecnativa.com>`_

* Vicent Cubells
* Ernesto Tejeda
* Pedro M. Baeza
* Carlos Roca
* Stefan Ungureanu

* `Obertix <https://www.obertix.net>`_

* Vicent Cubells <[email protected]>

* `Solvos <https://www.solvos.es>`_

* David Alonso <[email protected]>

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/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/15.0/purchase_stock_picking_invoice_link>`_ 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_stock_picking_invoice_link/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions purchase_stock_picking_invoice_link/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2019 Vicent Cubells <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Purchase Stock Picking Invoice Link",
"version": "16.0.1.0.0",
"category": "Warehouse Management",
"summary": "Adds link between purchases, pickings and invoices",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"license": "AGPL-3",
"depends": ["stock_picking_invoice_link", "purchase"],
"installable": True,
}
51 changes: 51 additions & 0 deletions purchase_stock_picking_invoice_link/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_stock_picking_invoice_link
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-07 11:40+0000\n"
"PO-Revision-Date: 2019-02-07 11:40+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_stock_picking_invoice_link
#: model:ir.model.fields,field_description:purchase_stock_picking_invoice_link.field_purchase_order_line__display_name
#: model:ir.model.fields,field_description:purchase_stock_picking_invoice_link.field_stock_move__display_name
msgid "Display Name"
msgstr ""

#. module: purchase_stock_picking_invoice_link
#: model:ir.model.fields,field_description:purchase_stock_picking_invoice_link.field_purchase_order_line__id
#: model:ir.model.fields,field_description:purchase_stock_picking_invoice_link.field_stock_move__id
msgid "ID"
msgstr ""

#. module: purchase_stock_picking_invoice_link
#: model:ir.model.fields,field_description:purchase_stock_picking_invoice_link.field_purchase_order_line____last_update
#: model:ir.model.fields,field_description:purchase_stock_picking_invoice_link.field_stock_move____last_update
msgid "Last Modified on"
msgstr ""

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

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

#~ msgid "Invoice"
#~ msgstr "Factura"

#~ msgid "Invoice Line"
#~ msgstr "Línea de factura"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_stock_picking_invoice_link
#
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_picking_invoice_link
#: model:ir.model,name:purchase_stock_picking_invoice_link.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: purchase_stock_picking_invoice_link
#: model:ir.model,name:purchase_stock_picking_invoice_link.model_stock_move
msgid "Stock Move"
msgstr ""
2 changes: 2 additions & 0 deletions purchase_stock_picking_invoice_link/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import purchase_order
from . import stock_move
65 changes: 65 additions & 0 deletions purchase_stock_picking_invoice_link/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2022 Tecnativa - Carlos Roca
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import models
from odoo.tools import float_compare, float_is_zero


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

def get_stock_moves_link_invoice(self):
moves_linked = self.env["stock.move"]
if self.product_id.purchase_method == "purchase":
to_invoice = self.product_qty - self.qty_invoiced
else:
to_invoice = self.qty_received - self.qty_invoiced
for stock_move in self.move_ids.sorted(
lambda m: (m.write_date, m.id), reverse=True
):
if (
stock_move.state != "done"
or stock_move.scrapped
or (
stock_move.location_id.usage != "supplier"
and (
stock_move.location_dest_id.usage != "supplier"
or not stock_move.to_refund
)
)
):
continue
if not stock_move.invoice_line_ids:
to_invoice -= (
stock_move.quantity_done
if not stock_move.to_refund
else -stock_move.quantity_done
)
moves_linked += stock_move
continue
elif float_is_zero(
to_invoice, precision_rounding=self.product_uom.rounding
):
break
to_invoice -= (
stock_move.quantity_done
if not stock_move.to_refund
else -stock_move.quantity_done
)
moves_linked += stock_move
return moves_linked

def _prepare_account_move_line(self, move=False):
vals = super()._prepare_account_move_line(move=move)
stock_moves = self.get_stock_moves_link_invoice()
# Invoice returned moves marked as to_refund
if (
float_compare(
self.product_qty - self.qty_invoiced,
0.0,
precision_rounding=self.currency_id.rounding,
)
< 0
):
stock_moves = stock_moves.filtered("to_refund")
vals["move_line_ids"] = [(4, m.id) for m in stock_moves]
return vals
41 changes: 41 additions & 0 deletions purchase_stock_picking_invoice_link/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2021 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


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

def write(self, vals):
"""Method used to associate the stock.move with the created account.move.line
when the invoicing method of the product is 'purchase' and the invoice is done
before receiving the products.
"""
res = super().write(vals)
if vals.get("state", "") == "done":
stock_moves = self.get_moves_link_invoice()
for stock_move in stock_moves.filtered(
lambda sm: sm.purchase_line_id
and sm.product_id.purchase_method == "purchase"
):
inv_type = stock_move.to_refund and "in_refund" or "in_invoice"
inv_line = self.env["account.move.line"].search(
[
("purchase_line_id", "=", stock_move.purchase_line_id.id),
("move_id.move_type", "=", inv_type),
]
)
if inv_line:
stock_move.invoice_line_ids = [(4, m.id) for m in inv_line]
return res

def get_moves_link_invoice(self):
return self.filtered(
lambda x: x.state == "done"
and not x.scrapped
and (
x.location_id.usage == "supplier"
or (x.location_dest_id.usage == "supplier" and x.to_refund)
)
)
15 changes: 15 additions & 0 deletions purchase_stock_picking_invoice_link/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* `Tecnativa <https://www.tecnativa.com>`_

* Vicent Cubells
* Ernesto Tejeda
* Pedro M. Baeza
* Carlos Roca
* Stefan Ungureanu

* `Obertix <https://www.obertix.net>`_

* Vicent Cubells <[email protected]>

* `Solvos <https://www.solvos.es>`_

* David Alonso <[email protected]>
6 changes: 6 additions & 0 deletions purchase_stock_picking_invoice_link/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module adds a link between purchases, pickings and invoices as well as
on the lines. Invoices are generated from purchase orders. With this module,
you can find back which deliveries an invoice relates to.

This module improves **stock_picking_invoice_link** module by linking
purchases, pickings and invoices.
5 changes: 5 additions & 0 deletions purchase_stock_picking_invoice_link/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Create a Purchase Order and confirm.
* Deliver its pickings totally or partially.
* Create an invoice of the goods delivered.
* If you open invoice form, you must see a smart-button labeled *Delivery*.
* Click on this smart-button to see the linked pickings.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading