diff --git a/account_move_line_stock_info/__manifest__.py b/account_move_line_stock_info/__manifest__.py index 02a082b00..b91964bd7 100644 --- a/account_move_line_stock_info/__manifest__.py +++ b/account_move_line_stock_info/__manifest__.py @@ -2,19 +2,16 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Account Move Line Stock Info", - "version": "12.0.1.0.0", - "depends": [ - "stock_account" - ], - "author": "Eficent," - "Odoo Community Association (OCA)", + "version": "13.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', - ] + "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/account_move_line.py b/account_move_line_stock_info/models/account_move_line.py index fdfe01075..04fd05291 100644 --- a/account_move_line_stock_info/models/account_move_line.py +++ b/account_move_line_stock_info/models/account_move_line.py @@ -5,8 +5,8 @@ from odoo import fields, models class AccountMoveLine(models.Model): - _inherit = 'account.move.line' + _inherit = "account.move.line" stock_move_id = fields.Many2one( - comodel_name='stock.move', string='Stock Move', copy=False, - index=True) + comodel_name="stock.move", string="Stock Move", copy=False, index=True + ) diff --git a/account_move_line_stock_info/models/stock_move.py b/account_move_line_stock_info/models/stock_move.py index 6d49cd7e0..ab0c64583 100644 --- a/account_move_line_stock_info/models/stock_move.py +++ b/account_move_line_stock_info/models/stock_move.py @@ -5,17 +5,19 @@ from odoo import api, fields, models class StockMove(models.Model): - _inherit = 'stock.move' + _inherit = "stock.move" account_move_line_ids = fields.One2many( - comodel_name='account.move.line', inverse_name='stock_move_id', - copy=False) + comodel_name="account.move.line", inverse_name="stock_move_id", copy=False + ) @api.model - def _prepare_account_move_line(self, qty, cost, - credit_account_id, debit_account_id): + def _prepare_account_move_line( + self, qty, cost, credit_account_id, debit_account_id + ): res = super(StockMove, self)._prepare_account_move_line( - qty, cost, credit_account_id, debit_account_id) + qty, cost, credit_account_id, debit_account_id + ) for line in res: - line[2]['stock_move_id'] = self.id + line[2]["stock_move_id"] = self.id return res 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 index 4626acecf..ca21c8e47 100644 --- 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 @@ -5,135 +5,142 @@ from odoo.tests.common import TransactionCase class TestAccountMoveLineStockInfo(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.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') + 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 = self._create_account_type('equity', 'other') - name = 'Goods Received Not Invoiced' - code = 'grni' - self.account_grni = self._create_account(acc_type, name, code, - self.company) + acc_type = self._create_account_type("equity", "other") + 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 = self._create_account_type('expense', 'other') - name = 'Cost of Goods Sold' - code = 'cogs' - self.account_cogs = self._create_account(acc_type, name, code, - self.company) + acc_type = self._create_account_type("expense", "other") + 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 = self._create_account_type('asset', 'other') - name = 'Inventory' - code = 'inventory' - self.account_inventory = self._create_account(acc_type, name, code, - self.company) + acc_type = self._create_account_type("asset", "other") + 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) + 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)], - }) + 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_type(self, name, a_type): - acc_type = self.acc_type_model.create({ - 'name': name, - 'type': a_type, - }) + acc_type = self.acc_type_model.create({"name": name, "type": a_type}) return acc_type def _create_account(self, acc_type, name, code, company): """Create an account.""" - account = self.account_model.create({ - 'name': name, - 'code': code, - 'user_type_id': acc_type.id, - 'company_id': company.id, - }) + account = self.account_model.create( + { + "name": name, + "code": code, + "user_type_id": acc_type.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, - }) + # 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, - })] - }) + 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): @@ -141,7 +148,8 @@ class TestAccountMoveLineStockInfo(TransactionCase): 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) + self.picking_type_in, self.location_supplier, self.location_stock + ) picking_in.action_confirm() picking_in.move_lines.quantity_done = 1 picking_in.action_done() @@ -154,7 +162,8 @@ class TestAccountMoveLineStockInfo(TransactionCase): account_move_line = aml picking_out = self._create_picking( - self.picking_type_out, self.location_supplier, self.location_stock) + self.picking_type_out, self.location_supplier, self.location_stock + ) picking_out.action_confirm() picking_out.move_lines.quantity_done = 1 picking_out.action_done() @@ -165,11 +174,13 @@ class TestAccountMoveLineStockInfo(TransactionCase): 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) + 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) + self.assertEqual( + account_move_line.sudo(self.account_manager).stock_move_id.name, + account_move_line.sudo(self.account_manager).name, + )