Skip to content

Commit

Permalink
account_move_line_stock_info (OCA#229)
Browse files Browse the repository at this point in the history
* [ADD] account_move_line_stock_info
  • Loading branch information
JordiBForgeFlow authored and bjeficent committed Nov 30, 2018
1 parent 1844afd commit 1497794
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 0 deletions.
57 changes: 57 additions & 0 deletions account_move_line_stock_info/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/OCA/stock-logistics-warehouse/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 <jordi.ballester@eficent.com>

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.
5 changes: 5 additions & 0 deletions account_move_line_stock_info/__init__.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions account_move_line_stock_info/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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',
]
}
7 changes: 7 additions & 0 deletions account_move_line_stock_info/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions account_move_line_stock_info/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions account_move_line_stock_info/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions account_move_line_stock_info/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions account_move_line_stock_info/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions account_move_line_stock_info/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 28 additions & 0 deletions account_move_line_stock_info/views/account_move_line_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="view_move_line_form" model="ir.ui.view">
<field name="name">account.move.line.form</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_form"/>
<field name="arch" type="xml">
<field name="quantity" position="before">
<field name="stock_move_id"/>
</field>
</field>
</record>

<record id="view_move_line_form2" model="ir.ui.view">
<field name="name">account.move.line.form2</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_form2"/>
<field name="arch" type="xml">
<field name="quantity" position="before">
<field name="stock_move_id"/>
</field>
</field>
</record>

</data>
</openerp>
37 changes: 37 additions & 0 deletions account_move_line_stock_info/views/stock_move_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="view_move_form" model="ir.ui.view">
<field name="name">stock.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form"/>
<field name="arch" type="xml">
<group name="moved_quants_grp" position="after">
<group name="account_move_lines_grp"
string="Journal Items" colspan="4">
<field name="account_move_line_ids" readonly="1"
nolabel="1"/>
</group>
</group>
</field>
</record>


<record id="view_move_picking_form" model="ir.ui.view">
<field name="name">stock.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_picking_form"/>
<field name="arch" type="xml">
<group name="moved_quants_grp" position="after">
<group name="account_move_lines_grp"
string="Journal Items" colspan="4">
<field name="account_move_line_ids" readonly="1"
nolabel="1"/>
</group>
</group>
</field>
</record>

</data>
</openerp>

0 comments on commit 1497794

Please sign in to comment.