diff --git a/stock_account_change_qty_reason/README.rst b/stock_account_change_qty_reason/README.rst new file mode 100644 index 000000000..b25fc78ce --- /dev/null +++ b/stock_account_change_qty_reason/README.rst @@ -0,0 +1,88 @@ +==================================== +Stock Account Change Quantity Reason +==================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_account_change_qty_reason + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_account_change_qty_reason + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the product stock management and allows to assign specific account +to manage changes on product quantities, either from product wizard or inventory adjustments. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +For a properly usage of this module, you must: + +- Ensure: Inventory > Settings > Inventory Adjustment > Preset Change Qty Reason is enabled + +To allow an Stock Manager configure accounts in preset reasons easily, you should: + +- Select Stock Manager user on: Settings > Users +- Enable: Technical Settings > Manage Stock Change Qty Preset Reasons +- Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Héctor Villarreal +* Adrià Gil Sorribes + +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-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_account_change_qty_reason/__init__.py b/stock_account_change_qty_reason/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_account_change_qty_reason/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_account_change_qty_reason/__manifest__.py b/stock_account_change_qty_reason/__manifest__.py new file mode 100644 index 000000000..10c95bdb9 --- /dev/null +++ b/stock_account_change_qty_reason/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Stock Account Change Quantity Reason", + "summary": """ + Stock Account Change Quantity Reason """, + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse Management", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "depends": ["stock_account", "stock_change_qty_reason"], + "data": ["views/stock_inventory_line_reason_view.xml", "views/stock_move_view.xml"], + "installable": True, +} diff --git a/stock_account_change_qty_reason/i18n/stock_account_change_qty_reason.pot b/stock_account_change_qty_reason/i18n/stock_account_change_qty_reason.pot new file mode 100644 index 000000000..665308e49 --- /dev/null +++ b/stock_account_change_qty_reason/i18n/stock_account_change_qty_reason.pot @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_account_change_qty_reason +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: stock_account_change_qty_reason +#: model:ir.model.fields,field_description:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_input_id +msgid "Input Account for Stock Valuation" +msgstr "" + +#. module: stock_account_change_qty_reason +#: model:ir.model.fields,field_description:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_output_id +msgid "Output Account for Stock Valuation" +msgstr "" + +#. module: stock_account_change_qty_reason +#: model:ir.model,name:stock_account_change_qty_reason.model_stock_inventory_line_reason +msgid "Stock Inventory Line Reason" +msgstr "" + +#. module: stock_account_change_qty_reason +#: model:ir.model,name:stock_account_change_qty_reason.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_account_change_qty_reason +#: model:ir.model.fields,help:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_output_id +msgid "When set, it will be used as offsetting account when products are issued from the company." +msgstr "" + +#. module: stock_account_change_qty_reason +#: model:ir.model.fields,help:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_input_id +msgid "When set, it will be used as offsetting account when products are received into the company." +msgstr "" + diff --git a/stock_account_change_qty_reason/i18n/zh_CN.po b/stock_account_change_qty_reason/i18n/zh_CN.po new file mode 100644 index 000000000..e23ccc889 --- /dev/null +++ b/stock_account_change_qty_reason/i18n/zh_CN.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_account_change_qty_reason +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-09-19 16:33+0000\n" +"Last-Translator: 黎伟杰 <674416404@qq.com>\n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.8\n" + +#. module: stock_account_change_qty_reason +#: model:ir.model.fields,field_description:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_input_id +msgid "Input Account for Stock Valuation" +msgstr "库存计价进货科目" + +#. module: stock_account_change_qty_reason +#: model:ir.model.fields,field_description:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_output_id +msgid "Output Account for Stock Valuation" +msgstr "库存计价出货科目" + +#. module: stock_account_change_qty_reason +#: model:ir.model,name:stock_account_change_qty_reason.model_stock_inventory_line_reason +msgid "Stock Inventory Line Reason" +msgstr "库存盘点行原因" + +#. module: stock_account_change_qty_reason +#: model:ir.model,name:stock_account_change_qty_reason.model_stock_move +msgid "Stock Move" +msgstr "库存移动" + +#. module: stock_account_change_qty_reason +#: model:ir.model.fields,help:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_output_id +msgid "When set, it will be used as offsetting account when products are issued from the company." +msgstr "设置后,当产品从公司发出时,它将被用作冲销科目。" + +#. module: stock_account_change_qty_reason +#: model:ir.model.fields,help:stock_account_change_qty_reason.field_stock_inventory_line_reason__account_reason_input_id +msgid "When set, it will be used as offsetting account when products are received into the company." +msgstr "设置后,当产品被接收到公司时,它将被用作冲销科目。" diff --git a/stock_account_change_qty_reason/models/__init__.py b/stock_account_change_qty_reason/models/__init__.py new file mode 100644 index 000000000..426227a0b --- /dev/null +++ b/stock_account_change_qty_reason/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_inventory_line_reason +from . import stock_move diff --git a/stock_account_change_qty_reason/models/stock_inventory_line_reason.py b/stock_account_change_qty_reason/models/stock_inventory_line_reason.py new file mode 100644 index 000000000..7655568d9 --- /dev/null +++ b/stock_account_change_qty_reason/models/stock_inventory_line_reason.py @@ -0,0 +1,20 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class StockAccountInventoryChangeReason(models.Model): + _inherit = "stock.inventory.line.reason" + + account_reason_input_id = fields.Many2one( + "account.account", + string="Input Account for Stock Valuation", + help="When set, it will be used as offsetting account when " + "products are received into the company.", + ) + account_reason_output_id = fields.Many2one( + "account.account", + string="Output Account for Stock Valuation", + help="When set, it will be used as offsetting account when " + "products are issued from the company.", + ) diff --git a/stock_account_change_qty_reason/models/stock_move.py b/stock_account_change_qty_reason/models/stock_move.py new file mode 100644 index 000000000..1a4b5e710 --- /dev/null +++ b/stock_account_change_qty_reason/models/stock_move.py @@ -0,0 +1,19 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _get_accounting_data_for_valuation(self): + self.ensure_one() + journal_id, acc_src, acc_dest, acc_valuation = super( + StockMove, self + )._get_accounting_data_for_valuation() + if self.preset_reason_id: + if self.preset_reason_id.account_reason_input_id: + acc_src = self.preset_reason_id.account_reason_input_id.id + if self.preset_reason_id.account_reason_output_id: + acc_dest = self.preset_reason_id.account_reason_output_id.id + return journal_id, acc_src, acc_dest, acc_valuation diff --git a/stock_account_change_qty_reason/readme/CONFIGURE.rst b/stock_account_change_qty_reason/readme/CONFIGURE.rst new file mode 100644 index 000000000..3e9592d80 --- /dev/null +++ b/stock_account_change_qty_reason/readme/CONFIGURE.rst @@ -0,0 +1,9 @@ +For a properly usage of this module, you must: + +- Ensure: Inventory > Settings > Inventory Adjustment > Preset Change Qty Reason is enabled + +To allow an Stock Manager configure accounts in preset reasons easily, you should: + +- Select Stock Manager user on: Settings > Users +- Enable: Technical Settings > Manage Stock Change Qty Preset Reasons +- Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons diff --git a/stock_account_change_qty_reason/readme/CONTRIBUTORS.rst b/stock_account_change_qty_reason/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..12be34944 --- /dev/null +++ b/stock_account_change_qty_reason/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Héctor Villarreal +* Adrià Gil Sorribes diff --git a/stock_account_change_qty_reason/readme/DESCRIPTION.rst b/stock_account_change_qty_reason/readme/DESCRIPTION.rst new file mode 100644 index 000000000..9c311ce3d --- /dev/null +++ b/stock_account_change_qty_reason/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the product stock management and allows to assign specific account +to manage changes on product quantities, either from product wizard or inventory adjustments. diff --git a/stock_account_change_qty_reason/static/description/icon.png b/stock_account_change_qty_reason/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_account_change_qty_reason/static/description/icon.png differ diff --git a/stock_account_change_qty_reason/static/description/index.html b/stock_account_change_qty_reason/static/description/index.html new file mode 100644 index 000000000..2cb8fcbad --- /dev/null +++ b/stock_account_change_qty_reason/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +Stock Account Change Quantity Reason + + + +
+

Stock Account Change Quantity Reason

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

This module extends the product stock management and allows to assign specific account +to manage changes on product quantities, either from product wizard or inventory adjustments.

+

Table of contents

+ +
+

Configuration

+

For a properly usage of this module, you must:

+
    +
  • Ensure: Inventory > Settings > Inventory Adjustment > Preset Change Qty Reason is enabled
  • +
+

To allow an Stock Manager configure accounts in preset reasons easily, you should:

+
    +
  • Select Stock Manager user on: Settings > Users
  • +
  • Enable: Technical Settings > Manage Stock Change Qty Preset Reasons
  • +
  • Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons
  • +
+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_account_change_qty_reason/tests/__init__.py b/stock_account_change_qty_reason/tests/__init__.py new file mode 100644 index 000000000..74917fe54 --- /dev/null +++ b/stock_account_change_qty_reason/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_account_change_qty_reason diff --git a/stock_account_change_qty_reason/tests/test_stock_account_change_qty_reason.py b/stock_account_change_qty_reason/tests/test_stock_account_change_qty_reason.py new file mode 100644 index 000000000..887a04d99 --- /dev/null +++ b/stock_account_change_qty_reason/tests/test_stock_account_change_qty_reason.py @@ -0,0 +1,169 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import SavepointCase + + +class TestStockAccountChangeQtyReason(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestStockAccountChangeQtyReason, cls).setUpClass() + + # MODELS + cls.product_product_model = cls.env["product.product"] + cls.product_category_model = cls.env["product.category"] + cls.wizard_model = cls.env["stock.change.product.qty"] + cls.stock_inventory = cls.env["stock.inventory"] + cls.preset_reason = cls.env["stock.inventory.line.reason"] + + # INSTANCES + cls.stock_valuation_account = cls.env["account.account"].create( + { + "name": "Stock Valuation", + "code": "Stock Valuation", + "user_type_id": cls.env.ref( + "account.data_account_type_current_assets" + ).id, + } + ) + cls.category = cls.product_category_model.create( + { + "name": "Physical (test)", + "property_cost_method": "standard", + "property_valuation": "real_time", + "property_stock_valuation_account_id": cls.stock_valuation_account, + } + ) + + company = cls.env.ref("base.main_company") + + # Instance: account type (receivable) + cls.type_recv = cls.env.ref("account.data_account_type_receivable") + + # Instance: account type (payable) + cls.type_payable = cls.env.ref("account.data_account_type_payable") + + # account (receivable) + cls.account_input = cls.env["account.account"].create( + { + "name": "test_account_reason_input", + "code": "1234", + "user_type_id": cls.type_recv.id, + "company_id": company.id, + "reconcile": True, + } + ) + + # account (payable) + cls.account_output = cls.env["account.account"].create( + { + "name": "test_account_reason_output", + "code": "4321", + "user_type_id": cls.type_payable.id, + "company_id": company.id, + "reconcile": True, + } + ) + + cls.reason = cls.preset_reason.create( + { + "name": "Test Reason", + "description": "Test Reason Description", + "account_reason_input_id": cls.account_input.id, + "account_reason_output_id": cls.account_output.id, + } + ) + + # Start Inventory with 10 units + cls.product = cls._create_product(cls, "product_product") + cls._product_change_qty(cls, cls.product, 10) + cls.inventory = cls.stock_inventory.create( + { + "name": "Inventory Adjustment Product", + "product_ids": [(4, cls.product.id)], + "preset_reason_id": cls.reason.id, + } + ) + cls.inventory.action_start() + + def _create_product(self, name): + return self.product_product_model.create( + { + "name": name, + "categ_id": self.category.id, + "type": "product", + "standard_price": 100, + } + ) + + def _product_change_qty(self, product, new_qty): + values = { + "product_tmpl_id": product.product_tmpl_id.id, + "product_id": product.id, + "new_quantity": new_qty, + } + wizard = self.wizard_model.create(values) + wizard.change_product_qty() + + def _create_reason(self, name, description=None): + return self.preset_reason.create({"name": name, "description": description}) + + def test_product_change_qty_account_input(self): + # update qty on hand and add reason + self.inventory.line_ids[0].write({"product_qty": 100}) + self.inventory.action_validate() + + # check stock moves and account moves created + stock_move = self.env["stock.move"].search( + [("product_id", "=", self.product.id), ("product_qty", "=", 90)] + ) + account_move = self.env["account.move"].search( + [("stock_move_id", "=", stock_move.id)] + ) + + # asserts + account_move_line1 = self.env["account.move.line"].search( + [ + ("move_id", "=", account_move.id), + ("account_id", "=", self.account_input.id), + ] + ) + account_move_line2 = self.env["account.move.line"].search( + [ + ("move_id", "=", account_move.id), + ("account_id", "=", self.stock_valuation_account.id), + ] + ) + self.assertEqual( + abs(account_move_line1.balance), abs(account_move_line2.balance) + ) + + def test_product_change_qty_account_output(self): + # update qty on hand and add reason + self.inventory.line_ids[0].write({"product_qty": 5}) + self.inventory.action_validate() + + # check stock moves and account moves created + stock_move = self.env["stock.move"].search( + [("product_id", "=", self.product.id), ("product_qty", "=", 5)] + ) + account_move = self.env["account.move"].search( + [("stock_move_id", "=", stock_move.id)] + ) + + # asserts + account_move_line3 = self.env["account.move.line"].search( + [ + ("move_id", "=", account_move.id), + ("account_id", "=", self.account_output.id), + ] + ) + account_move_line4 = self.env["account.move.line"].search( + [ + ("move_id", "=", account_move.id), + ("account_id", "=", self.stock_valuation_account.id), + ] + ) + self.assertEqual( + abs(account_move_line3.balance), abs(account_move_line4.balance) + ) diff --git a/stock_account_change_qty_reason/views/stock_inventory_line_reason_view.xml b/stock_account_change_qty_reason/views/stock_inventory_line_reason_view.xml new file mode 100644 index 000000000..aa838993a --- /dev/null +++ b/stock_account_change_qty_reason/views/stock_inventory_line_reason_view.xml @@ -0,0 +1,16 @@ + + + + + Preset Reason Accounts + stock.inventory.line.reason + + + + + + + + + diff --git a/stock_account_change_qty_reason/views/stock_move_view.xml b/stock_account_change_qty_reason/views/stock_move_view.xml new file mode 100644 index 000000000..022107ae8 --- /dev/null +++ b/stock_account_change_qty_reason/views/stock_move_view.xml @@ -0,0 +1,16 @@ + + + + + stock.move.form + stock.move + + + + + + + +