Skip to content

Commit

Permalink
Merge PR #1813 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 4, 2024
2 parents 112aad2 + a5e3f54 commit 77ec372
Show file tree
Hide file tree
Showing 17 changed files with 876 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_account_move_reset_to_draft/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
107 changes: 107 additions & 0 deletions stock_account_move_reset_to_draft/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
=================================
Stock account move reset to draft
=================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:607846dfb2ebfa561ccc45ab5422470475824616c748ea2ef707adc4ae5d7eb7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Faccount--invoicing-lightgray.png?logo=github
:target: https://github.com/OCA/account-invoicing/tree/16.0/stock_account_move_reset_to_draft
:alt: OCA/account-invoicing
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-invoicing-16-0/account-invoicing-16-0-stock_account_move_reset_to_draft
: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/account-invoicing&target_branch=16.0
:alt: Try me on Runboat

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

This module allows to restore a vendor bill to draft if SVLs linked to any invoice line
have been generated (stock_account not allowed).

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

When a purchase invoice is created for a different price than the one for which the
SVLs of the incoming picking were created and confirmed, SVLs are created for the
price difference, but from that moment on it is no longer possible to restore it
to draft (stock_account not allowed).

Usage
=====

#. Create a product category with Costing Method: Average Cost (AVCO)
#. Create a product linked to the category created before.
#. Create a purchase order and adds a product line with quantity 1 and price 10.
#. Confirms the purchase order and validates the incoming picking.
#. Creates an invoice from the purchase order.
#. Changes the invoice line price to 12 and confirm the invoice.
#. It is possible to reset the invoice to draft (the SVL of the difference will be removed).

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

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

* Tecnativa

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

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

* Víctor Martínez
* Pedro M. Baeza

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-victoralmau| image:: https://github.com/victoralmau.png?size=40px
:target: https://github.com/victoralmau
:alt: victoralmau

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

|maintainer-victoralmau|

This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/16.0/stock_account_move_reset_to_draft>`_ 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 stock_account_move_reset_to_draft/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions stock_account_move_reset_to_draft/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock account move reset to draft",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"version": "16.0.1.0.0",
# Real dependency is stock_account but we need purchase_stock in tests
"depends": ["purchase_stock"],
"license": "AGPL-3",
"category": "Warehouse Management",
"installable": True,
"maintainers": ["victoralmau"],
}
21 changes: 21 additions & 0 deletions stock_account_move_reset_to_draft/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_account_move_reset_to_draft
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-11 15:02+0000\n"
"PO-Revision-Date: 2024-10-11 15:02+0000\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: stock_account_move_reset_to_draft
#: model:ir.model,name:stock_account_move_reset_to_draft.model_account_move
msgid "Journal Entry"
msgstr "Asiento contable"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_account_move_reset_to_draft
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-11 15:02+0000\n"
"PO-Revision-Date: 2024-10-11 15:02+0000\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: stock_account_move_reset_to_draft
#: model:ir.model,name:stock_account_move_reset_to_draft.model_account_move
msgid "Journal Entry"
msgstr ""
3 changes: 3 additions & 0 deletions stock_account_move_reset_to_draft/models/__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 account_move
72 changes: 72 additions & 0 deletions stock_account_move_reset_to_draft/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_is_zero


class AccountMove(models.Model):
_inherit = "account.move"

def button_draft(self):
"""If it is a purchase invoice, we will create a new SVL for each line with
the sum of the value in opposite sign.
"""
for item in self.sudo().filtered(
lambda x: x.is_inbound
and any(line.stock_valuation_layer_ids for line in x.line_ids)
):
for line in item.line_ids.filtered("stock_valuation_layer_ids"):
origin_svls = line.stock_valuation_layer_ids.stock_valuation_layer_id
if (
len(
origin_svls.stock_valuation_layer_ids.account_move_line_id.filtered(
lambda x: x.parent_state == "posted"
)
)
> 1
):
raise UserError(
_(
"Inventory valuation records are intertwined for %(line_name)s.",
line_name=line.display_name,
)
)
for origin_svl in origin_svls:
if origin_svl.quantity != origin_svl.remaining_qty:
raise UserError(
_(
"The inventory has already been (partially) consumed "
"for %(line_name)s.",
line_name=line.display_name,
)
)
svls = origin_svl.stock_valuation_layer_ids
value = sum(svls.mapped("value"))
if not float_is_zero(
value, precision_rounding=line.currency_id.rounding
):
origin_svl.remaining_value -= value
revert_svl = svls[0].copy({"value": -value})
revert_svl._validate_accounting_entries()
product = line.product_id.with_company(item.company_id.id)
if product.cost_method == "average":
product.sudo().with_context(disable_auto_svl=True).write(
{"standard_price": product.value_svl / product.quantity_svl}
)
return super().button_draft()

def _compute_show_reset_to_draft_button(self):
"""Overwrite the value only if it is already posted and with SVLs.
We use the same fields for filtering that account uses for the
show_reset_to_draft_button field.
"""
_self = self.sudo().filtered(
lambda x: not x.restrict_mode_hash_table
and x.state in ("posted", "cancel")
and any(line.stock_valuation_layer_ids for line in x.line_ids)
)
for item in self:
item.show_reset_to_draft_button = True
return super(AccountMove, self - _self)._compute_show_reset_to_draft_button()
4 changes: 4 additions & 0 deletions stock_account_move_reset_to_draft/readme/CONTEXT.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
When a purchase invoice is created for a different price than the one for which the
SVLs of the incoming picking were created and confirmed, SVLs are created for the
price difference, but from that moment on it is no longer possible to restore it
to draft (stock_account not allowed).
4 changes: 4 additions & 0 deletions stock_account_move_reset_to_draft/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Víctor Martínez
* Pedro M. Baeza
2 changes: 2 additions & 0 deletions stock_account_move_reset_to_draft/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows to restore a vendor bill to draft if SVLs linked to any invoice line
have been generated (stock_account not allowed).
7 changes: 7 additions & 0 deletions stock_account_move_reset_to_draft/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#. Create a product category with Costing Method: Average Cost (AVCO)
#. Create a product linked to the category created before.
#. Create a purchase order and adds a product line with quantity 1 and price 10.
#. Confirms the purchase order and validates the incoming picking.
#. Creates an invoice from the purchase order.
#. Changes the invoice line price to 12 and confirm the invoice.
#. It is possible to reset the invoice to draft (the SVL of the difference will be removed).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 77ec372

Please sign in to comment.