From eabd5ba32dfb4d7766b4eb32e0d413b8fea841b0 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Carreras Date: Wed, 20 Nov 2024 13:20:08 -0300 Subject: [PATCH] [ADD]sale_order_type_invoice_policy_invoice_link:new module X-original-commit: fb4e43a99c9c20d76596e54007956a4404863f57 --- .../README.rst | 70 +++++++++++++++++++ .../__init__.py | 5 ++ .../__manifest__.py | 41 +++++++++++ .../models/__init__.py | 5 ++ .../models/stock_move.py | 23 ++++++ 5 files changed, 144 insertions(+) create mode 100644 sale_order_type_invoice_policy_invoice_link/README.rst create mode 100644 sale_order_type_invoice_policy_invoice_link/__init__.py create mode 100644 sale_order_type_invoice_policy_invoice_link/__manifest__.py create mode 100644 sale_order_type_invoice_policy_invoice_link/models/__init__.py create mode 100644 sale_order_type_invoice_policy_invoice_link/models/stock_move.py diff --git a/sale_order_type_invoice_policy_invoice_link/README.rst b/sale_order_type_invoice_policy_invoice_link/README.rst new file mode 100644 index 000000000..7f8612e04 --- /dev/null +++ b/sale_order_type_invoice_policy_invoice_link/README.rst @@ -0,0 +1,70 @@ +.. |company| replace:: ADHOC SA + +.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png + :alt: ADHOC SA + :target: https://www.adhoc.com.ar + +.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png + +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +=========================================== +sale order type invoice policy invoice link +=========================================== + +Bridge module between sale_order_type_invoice_policy and stock_picking_invoice_link. + +Installation +============ + +To install this module, you need to: + +#. Only need to install the module + +Configuration +============= + +To configure this module, you need to: + +#. Only need to install the module + +Usage +===== + +To use this module, you need to: + +#. Go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: http://runbot.adhoc.com.ar/ + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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. + +Credits +======= + +Images +------ + +* |company| |icon| + +Contributors +------------ + +Maintainer +---------- + +|company_logo| + +This module is maintained by the |company|. + +To contribute to this module, please visit https://www.adhoc.com.ar. diff --git a/sale_order_type_invoice_policy_invoice_link/__init__.py b/sale_order_type_invoice_policy_invoice_link/__init__.py new file mode 100644 index 000000000..d03377692 --- /dev/null +++ b/sale_order_type_invoice_policy_invoice_link/__init__.py @@ -0,0 +1,5 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import models diff --git a/sale_order_type_invoice_policy_invoice_link/__manifest__.py b/sale_order_type_invoice_policy_invoice_link/__manifest__.py new file mode 100644 index 000000000..d8e89d360 --- /dev/null +++ b/sale_order_type_invoice_policy_invoice_link/__manifest__.py @@ -0,0 +1,41 @@ +############################################################################## +# +# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar) +# All Rights Reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'sale order type invoice policy invoice link', + 'version': "16.0.1.0.0", + 'category': 'Warehouse Management', + 'sequence': 14, + 'summary': '', + 'author': 'ADHOC SA', + 'website': 'www.adhoc.com.ar', + 'license': 'AGPL-3', + 'images': [ + ], + 'depends': [ + 'sale_order_type_invoice_policy','stock_picking_invoice_link' + ], + 'data': [ + ], + 'demo': [ + ], + 'installable': True, + 'auto_install': True, + 'application': False, +} diff --git a/sale_order_type_invoice_policy_invoice_link/models/__init__.py b/sale_order_type_invoice_policy_invoice_link/models/__init__.py new file mode 100644 index 000000000..0c1dc32ba --- /dev/null +++ b/sale_order_type_invoice_policy_invoice_link/models/__init__.py @@ -0,0 +1,5 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import stock_move diff --git a/sale_order_type_invoice_policy_invoice_link/models/stock_move.py b/sale_order_type_invoice_policy_invoice_link/models/stock_move.py new file mode 100644 index 000000000..88b081a69 --- /dev/null +++ b/sale_order_type_invoice_policy_invoice_link/models/stock_move.py @@ -0,0 +1,23 @@ + +from odoo.addons.stock_picking_invoice_link.models.stock_move import StockMove + + +def new_write(self, vals): + # monkey patch to take in consideration both module stock_picking_invoice_link and sale_order_type_invoice_policy + if "product_uom_qty" in vals and not self.env.context.get( + "bypass_stock_move_update_restriction" + ): + for move in self: + if move.state == "done" and move.invoice_line_ids: + raise UserError(_("You can not modify an invoiced stock move")) + res = super(StockMove, self).write(vals) + if vals.get("state", "") == 'done': + stock_moves = self.get_moves_delivery_link_invoice() + for stock_move in stock_moves.filtered(lambda sm: sm.sale_line_id and (sm.sale_line_id.order_id.type_id.invoice_policy == "order" or sm.sale_line_id.order_id.type_id.invoice_policy == "by_product" and sm.product_id.invoice_policy == "order")): + inv_type = stock_move.to_refund and "out_refund" or "out_invoice" + inv_line = (self.env["account.move.line"].sudo().search([('sale_line_ids','=',stock_move.sale_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 + +StockMove.write = new_write