diff --git a/account_move_line_stock_info/README.rst b/account_move_line_stock_info/README.rst new file mode 100644 index 000000000000..9423fd625e58 --- /dev/null +++ b/account_move_line_stock_info/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================ +Account Move Line Stock Move +============================ + +This module adds the stock move to the account move lines that it generates. + + +Usage +===== + +* The stock manager can check the journal items generated by a stock + move, by accessing to the picking, then clicking on one of the moves, to + display the list of journal items. + +* An accounting user or manager can review the details of a move that is + associated to a journal item that she/he is checking. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/153/8.0 + + +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 +======= + +Contributors +------------ +* Jordi Ballester Alomar + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_move_line_stock_info/__init__.py b/account_move_line_stock_info/__init__.py new file mode 100644 index 000000000000..bc55e07c7956 --- /dev/null +++ b/account_move_line_stock_info/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/account_move_line_stock_info/__openerp__.py b/account_move_line_stock_info/__openerp__.py new file mode 100644 index 000000000000..582675405be1 --- /dev/null +++ b/account_move_line_stock_info/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Account Move Line Stock Move", + "version": "8.0.1.0.0", + "depends": [ + "stock_account" + ], + "author": "Eficent," + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse Management", + "installable": True, + "license": "AGPL-3", + "data": [ + 'security/ir.model.access.csv', + 'views/account_move_line_view.xml', + 'views/stock_move_view.xml', + ] +} diff --git a/account_move_line_stock_info/models/__init__.py b/account_move_line_stock_info/models/__init__.py new file mode 100644 index 000000000000..53b24cfecf78 --- /dev/null +++ b/account_move_line_stock_info/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import account_move_line +from . import stock_quant +from . import stock_move diff --git a/account_move_line_stock_info/models/account_move_line.py b/account_move_line_stock_info/models/account_move_line.py new file mode 100644 index 000000000000..932fc0aa60a5 --- /dev/null +++ b/account_move_line_stock_info/models/account_move_line.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models + + +class AccountMoveLine(models.Model): + _inherit = 'account.move.line' + + stock_move_id = fields.Many2one(comodel_name='stock.move', + string='Stock Move', copy=False) diff --git a/account_move_line_stock_info/models/stock_move.py b/account_move_line_stock_info/models/stock_move.py new file mode 100644 index 000000000000..b8de1067c7df --- /dev/null +++ b/account_move_line_stock_info/models/stock_move.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models + + +class StockMove(models.Model): + _inherit = 'stock.move' + + account_move_line_ids = fields.One2many( + comodel_name='account.move.line', inverse_name='stock_move_id', + copy=False) diff --git a/account_move_line_stock_info/models/stock_quant.py b/account_move_line_stock_info/models/stock_quant.py new file mode 100644 index 000000000000..0204f0e36853 --- /dev/null +++ b/account_move_line_stock_info/models/stock_quant.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api + + +class StockQuant(models.Model): + _inherit = 'stock.quant' + + @api.model + def _prepare_account_move_line(self, move, qty, cost, + credit_account_id, debit_account_id): + res = super(StockQuant, self)._prepare_account_move_line( + move, qty, cost, credit_account_id, debit_account_id) + for line in res: + line[2]['stock_move_id'] = move.id + return res diff --git a/account_move_line_stock_info/security/ir.model.access.csv b/account_move_line_stock_info/security/ir.model.access.csv new file mode 100644 index 000000000000..c184eb79c886 --- /dev/null +++ b/account_move_line_stock_info/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_move_line, account.move.line,account.model_account_move_line,stock.group_stock_manager,1,0,0,0 +access_stock_move_account_invoice,stock.move account invoice,stock.model_stock_move,account.group_account_invoice,1,0,0,0 +access_stock_move_account_user,stock.move account user,stock.model_stock_move,account.group_account_user,1,0,0,0 +access_stock_move_account_manager,stock.move account user,stock.model_stock_move,account.group_account_manager,1,0,0,0 diff --git a/account_move_line_stock_info/static/description/icon.png b/account_move_line_stock_info/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/account_move_line_stock_info/static/description/icon.png differ diff --git a/account_move_line_stock_info/tests/__init__.py b/account_move_line_stock_info/tests/__init__.py new file mode 100644 index 000000000000..f583070a9489 --- /dev/null +++ b/account_move_line_stock_info/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_account_move_line_stock_move diff --git a/account_move_line_stock_info/tests/test_account_move_line_stock_move.py b/account_move_line_stock_info/tests/test_account_move_line_stock_move.py new file mode 100644 index 000000000000..6a10210d8819 --- /dev/null +++ b/account_move_line_stock_info/tests/test_account_move_line_stock_move.py @@ -0,0 +1,169 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common + + +class TestAccountMoveLineStockInfo(common.TransactionCase): + + def setUp(self): + super(TestAccountMoveLineStockInfo, self).setUp() + self.product_model = self.env['product.product'] + self.product_ctg_model = self.env['product.category'] + self.acc_type_model = self.env['account.account.type'] + self.account_model = self.env['account.account'] + self.aml_model = self.env['account.move.line'] + self.stock_picking_model = self.env['stock.picking'] + self.stock_move_model = self.env['stock.move'] + self.res_users_model = self.env['res.users'] + + self.partner1 = self.env.ref('base.res_partner_1') + self.location_stock = self.env.ref('stock.stock_location_stock') + self.location_supplier = self.env.ref('stock.stock_location_suppliers') + self.location_customer = self.env.ref('stock.stock_location_customers') + self.company = self.env.ref('base.main_company') + self.picking_type_in = self.env.ref('stock.picking_type_in') + self.picking_type_out = self.env.ref('stock.picking_type_out') + self.group_stock_user = self.env.ref('stock.group_stock_user') + self.group_account_invoice = self.env.ref( + 'account.group_account_invoice') + self.group_account_manager = self.env.ref( + 'account.group_account_manager') + + # Create account for Goods Received Not Invoiced + acc_type = 'equity' + name = 'Goods Received Not Invoiced' + code = 'grni' + self.account_grni = self._create_account(acc_type, name, code, + self.company) + + # Create account for Cost of Goods Sold + acc_type = 'expense' + name = 'Cost of Goods Sold' + code = 'cogs' + self.account_cogs = self._create_account(acc_type, name, code, + self.company) + # Create account for Inventory + acc_type = 'asset' + name = 'Inventory' + code = 'inventory' + self.account_inventory = self._create_account(acc_type, name, code, + self.company) + # Create Product + self.product = self._create_product() + # company + + # Create users + self.stock_user = self._create_user('stock_user', + [self.group_stock_user, + self.group_account_invoice], + self.company) + self.account_invoice = self._create_user('account_invoice', + [self.group_account_invoice], + self.company) + self.account_manager = self._create_user('account_manager', + [self.group_account_manager], + self.company) + + def _create_user(self, login, groups, company): + """ Create a user.""" + group_ids = [group.id for group in groups] + user = \ + self.res_users_model.with_context( + {'no_reset_password': True}).create({ + 'name': 'Test User', + 'login': login, + 'password': 'demo', + 'email': 'test@yourcompany.com', + 'company_id': company.id, + 'company_ids': [(4, company.id)], + 'groups_id': [(6, 0, group_ids)] + }) + return user.id + + def _create_account(self, acc_type, name, code, company): + """Create an account.""" + types = self.acc_type_model.search([('code', '=', acc_type)]) + account = self.account_model.create({ + 'name': name, + 'code': code, + 'type': 'other', + 'user_type': types and types[0].id, + 'company_id': company.id + }) + return account + + def _create_product(self): + """Create a Product.""" +# group_ids = [group.id for group in groups] + product_ctg = self.product_ctg_model.create({ + 'name': 'test_product_ctg', + 'property_stock_valuation_account_id': self.account_inventory.id + }) + product = self.product_model.create({ + 'name': 'test_product', + 'categ_id': product_ctg.id, + 'type': 'product', + 'standard_price': 1.0, + 'list_price': 1.0, + 'valuation': 'real_time', + 'property_stock_account_input': self.account_grni.id, + 'property_stock_account_output': self.account_cogs.id, + }) + return product + + def _create_picking(self, picking_type, location, location_dest): + + picking = self.stock_picking_model.sudo(self.stock_user).create({ + 'picking_type_id': picking_type.id, + 'location_id': location.id, + 'location_dest_id': location_dest.id, + 'move_lines': [ + (0, 0, { + 'name': 'Test move', + 'product_id': self.product.id, + 'product_uom': self.product.uom_id.id, + 'product_uom_qty': 3, + 'location_id': location.id, + 'location_dest_id': location_dest.id, + 'price_unit': 10 + })] + }) + return picking + + def test_account_move_line_stock_move(self): + """Test that processing an incoming picking the account moves + generated by the picking moves will contain the stock move. + """ + picking_in = self._create_picking( + self.picking_type_in, self.location_supplier, self.location_stock) + picking_in.action_confirm() + picking_in.action_done() + + account_move_line = False + for move in picking_in.move_lines: + self.assertEqual(len(move.account_move_line_ids), 2) + for aml in move.account_move_line_ids: + self.assertEqual(aml.name, move.name) + account_move_line = aml + + picking_out = self._create_picking( + self.picking_type_out, self.location_supplier, self.location_stock) + picking_out.action_confirm() + picking_out.action_done() + + for move in picking_out.move_lines: + self.assertEqual(len(move.account_move_line_ids), 2) + for aml in move.account_move_line_ids: + self.assertEqual(aml.name, move.name) + + # Test that the account invoice user can access to the stock info + self.assertEqual(account_move_line.sudo( + self.account_invoice).stock_move_id.name, + account_move_line.sudo(self.account_invoice).name) + + # Test that the account manager can access to the stock info + self.assertEqual(account_move_line.sudo( + self.account_manager).stock_move_id.name, + account_move_line.sudo(self.account_manager).name) diff --git a/account_move_line_stock_info/views/account_move_line_view.xml b/account_move_line_stock_info/views/account_move_line_view.xml new file mode 100644 index 000000000000..6688a82b070a --- /dev/null +++ b/account_move_line_stock_info/views/account_move_line_view.xml @@ -0,0 +1,28 @@ + + + + + + account.move.line.form + account.move.line + + + + + + + + + + account.move.line.form2 + account.move.line + + + + + + + + + + diff --git a/account_move_line_stock_info/views/stock_move_view.xml b/account_move_line_stock_info/views/stock_move_view.xml new file mode 100644 index 000000000000..4a86707fdaa6 --- /dev/null +++ b/account_move_line_stock_info/views/stock_move_view.xml @@ -0,0 +1,37 @@ + + + + + + stock.move.form + stock.move + + + + + + + + + + + + + stock.move.form + stock.move + + + + + + + + + + + +