mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[ADD]stock_request_analytic
This commit is contained in:
64
stock_request_analytic/README.rst
Normal file
64
stock_request_analytic/README.rst
Normal file
@@ -0,0 +1,64 @@
|
||||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
|
||||
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
:alt: License: LGPL-3
|
||||
|
||||
======================
|
||||
Stock Request Analytic
|
||||
======================
|
||||
|
||||
This module allows for users to be able to display assign analytic accounts to
|
||||
stock request.
|
||||
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Assign the analytic account to the stock request.
|
||||
|
||||
|
||||
.. 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/11.0
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
* Integrate this module with stock_request_purchase to pass the analytic
|
||||
account to the purchase order
|
||||
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Probably the only solution to make this work in to put locations without
|
||||
company. In this case the constrains defined makes no sense.
|
||||
|
||||
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 smash it by providing detailed and welcomed feedback.
|
||||
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Jordi Ballester <jordi.ballester@eficent.com>.
|
||||
* Enric Tobella <etobella@creublanca.es>
|
||||
|
||||
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.
|
||||
2
stock_request_analytic/__init__.py
Normal file
2
stock_request_analytic/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
from . import models
|
||||
24
stock_request_analytic/__manifest__.py
Normal file
24
stock_request_analytic/__manifest__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
{
|
||||
"name": "Stock Request Analytic",
|
||||
"summary": "Internal request for stock",
|
||||
"version": "11.0.2.0.1",
|
||||
"license": "LGPL-3",
|
||||
"website": "https://github.com/stock-logistics-warehouse",
|
||||
"author": "Eficent, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"category": "Analytic",
|
||||
"depends": [
|
||||
"stock_request",
|
||||
"stock_analytic",
|
||||
],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"views/stock_request_views.xml",
|
||||
"views/stock_request_order_views.xml",
|
||||
"views/analytic_views.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
5
stock_request_analytic/models/__init__.py
Normal file
5
stock_request_analytic/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
from . import analytic
|
||||
from . import procurement_rule
|
||||
from . import stock_request
|
||||
from . import stock_request_order
|
||||
12
stock_request_analytic/models/analytic.py
Normal file
12
stock_request_analytic/models/analytic.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class AccountAnalyticAccount(models.Model):
|
||||
_inherit = 'account.analytic.account'
|
||||
|
||||
stock_request_ids = fields.One2many(
|
||||
comodel_name='stock.request', inverse_name='analytic_account_id',
|
||||
string='Stock Requests', copy=False)
|
||||
18
stock_request_analytic/models/procurement_rule.py
Normal file
18
stock_request_analytic/models/procurement_rule.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class ProcurementRule(models.Model):
|
||||
_inherit = 'procurement.rule'
|
||||
|
||||
def _get_stock_move_values(self, product_id, product_qty, product_uom,
|
||||
location_id, name, origin, values, group_id):
|
||||
res = super(ProcurementRule, self)._get_stock_move_values(
|
||||
product_id, product_qty, product_uom, location_id, name, origin,
|
||||
values, group_id)
|
||||
analytic_account_id = self.env['stock.request'].browse(
|
||||
values['stock_request_id']).analytic_account_id.id
|
||||
res.update(analytic_account_id=analytic_account_id)
|
||||
return res
|
||||
22
stock_request_analytic/models/stock_request.py
Normal file
22
stock_request_analytic/models/stock_request.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class StockRequest(models.Model):
|
||||
_inherit = "stock.request"
|
||||
|
||||
analytic_account_id = fields.Many2one(
|
||||
'account.analytic.account', string='Analytic Account')
|
||||
|
||||
@api.constrains('analytic_account_id')
|
||||
def _check_analytic_company_constrains(self):
|
||||
if any(request.company_id and
|
||||
request.analytic_account_id.company_id !=
|
||||
request.company_id for request in self):
|
||||
raise ValidationError(
|
||||
_('You cannot link a analytic account '
|
||||
'to a stock request that belongs to '
|
||||
'another company.'))
|
||||
41
stock_request_analytic/models/stock_request_order.py
Normal file
41
stock_request_analytic/models/stock_request_order.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright 2018 Creu Blanca
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockRequestOrder(models.Model):
|
||||
_inherit = 'stock.request.order'
|
||||
|
||||
analytic_count = fields.Integer(string='analytic count',
|
||||
compute='_compute_analytic_ids',
|
||||
readonly=True)
|
||||
analytic_account_ids = fields.One2many(
|
||||
'account.analytic.account',
|
||||
compute='_compute_analytic_ids',
|
||||
string='Analytic Accounts',
|
||||
readonly=True, copy=False)
|
||||
|
||||
@api.depends('stock_request_ids')
|
||||
def _compute_analytic_ids(self):
|
||||
for req in self.sudo():
|
||||
req.analytic_ids = req.stock_request_ids.mapped(
|
||||
'analytic_account_id')
|
||||
req.analytic_account_ids = req.stock_request_ids.mapped(
|
||||
'analytic_account_id')
|
||||
req.analytic_count = len(req.analytic_ids)
|
||||
|
||||
@api.multi
|
||||
def action_view_analytic(self):
|
||||
action = self.env.ref(
|
||||
'analytic.action_account_analytic_account_form').read()[0]
|
||||
analytics = self.mapped('analytic_account_ids')
|
||||
if len(analytics) > 1:
|
||||
action['domain'] = [('id', 'in', analytics.ids)]
|
||||
elif analytics:
|
||||
action['views'] = [
|
||||
(self.env.ref(
|
||||
'analytic.action_account_analytic_account_form').id,
|
||||
'form')]
|
||||
action['res_id'] = analytics.id
|
||||
return action
|
||||
2
stock_request_analytic/security/ir.model.access.csv
Normal file
2
stock_request_analytic/security/ir.model.access.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_stock_request_analytic_user,stock.request analytic user,stock_request.model_stock_request,analytic.group_analytic_accounting,1,0,0,0
|
||||
|
BIN
stock_request_analytic/static/description/icon.png
Normal file
BIN
stock_request_analytic/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
2
stock_request_analytic/tests/__init__.py
Normal file
2
stock_request_analytic/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
from . import test_stock_request_analytic
|
||||
79
stock_request_analytic/tests/test_stock_request_analytic.py
Normal file
79
stock_request_analytic/tests/test_stock_request_analytic.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
from odoo.addons.stock_request.tests import test_stock_request
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class TestStockRequestAnalytic(test_stock_request.TestStockRequest):
|
||||
def setUp(self):
|
||||
super(TestStockRequestAnalytic, self).setUp()
|
||||
self.analytic_model = self.env['account.analytic.account']
|
||||
self.analytic = self.analytic_model.create({'name': 'Pizza'})
|
||||
self.analytic2 = self.analytic_model.create(
|
||||
{'name': 'Pizza',
|
||||
'company_id': self.company_2.id})
|
||||
self.demand_loc = self.env['stock.location'].create(
|
||||
{'name': 'demand_loc',
|
||||
'location_id': self.warehouse.lot_stock_id.id,
|
||||
'usage': 'internal'})
|
||||
self.demand_route = self.env['stock.location.route'].create({
|
||||
'name': 'Transfer',
|
||||
'product_categ_selectable': False,
|
||||
'product_selectable': True,
|
||||
'company_id': self.main_company.id,
|
||||
'sequence': 10,
|
||||
})
|
||||
self.pizza = self._create_product('PZ', 'Pizza', False)
|
||||
self.demand_rule = self.env['procurement.rule'].create({
|
||||
'name': 'Transfer',
|
||||
'route_id': self.demand_route.id,
|
||||
'location_src_id': self.warehouse.lot_stock_id.id,
|
||||
'location_id': self.demand_loc.id,
|
||||
'action': 'move',
|
||||
'picking_type_id': self.warehouse.int_type_id.id,
|
||||
'procure_method': 'make_to_stock',
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'company_id': self.main_company.id,
|
||||
'propagate': 'False',
|
||||
})
|
||||
self.pizza.route_ids = [(6, 0, self.demand_route.ids)]
|
||||
|
||||
def prepare_order_request_analytic(self, aa, company):
|
||||
expected_date = fields.Date.today()
|
||||
vals = {
|
||||
'company_id': company.id,
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'location_id': self.demand_loc.id,
|
||||
'expected_date': expected_date,
|
||||
'stock_request_ids': [(0, 0, {
|
||||
'product_id': self.pizza.id,
|
||||
'product_uom_id': self.pizza.uom_id.id,
|
||||
'product_uom_qty': 5.0,
|
||||
'analytic_account_id': aa.id,
|
||||
'company_id': company.id,
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'location_id': self.demand_loc.id,
|
||||
'expected_date': expected_date,
|
||||
})]
|
||||
}
|
||||
return vals
|
||||
|
||||
def test_stock_analytic(self):
|
||||
vals = self.prepare_order_request_analytic(
|
||||
self.analytic, self.main_company)
|
||||
order = self.env['stock.request.order'].create(vals)
|
||||
req = order.stock_request_ids
|
||||
order.action_confirm()
|
||||
self.assertEqual(
|
||||
req.move_ids.mapped('analytic_account_id'), self.analytic)
|
||||
self.assertEqual(order.analytic_count, 1)
|
||||
action = order.action_view_analytic()
|
||||
self.assertTrue(action['res_id'], self.analytic.id)
|
||||
|
||||
def test_company(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
vals = self.prepare_order_request_analytic(
|
||||
self.analytic2, self.main_company)
|
||||
self.env['stock.request.order'].create(vals)
|
||||
20
stock_request_analytic/views/analytic_views.xml
Normal file
20
stock_request_analytic/views/analytic_views.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||
<odoo>
|
||||
<record id="view_account_analytic_account_form" model="ir.ui.view">
|
||||
<field name="name">analytic.order.form</field>
|
||||
<field name="model">account.analytic.account</field>
|
||||
<field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='main']" position='after'>
|
||||
<notebook groups="stock_request.group_stock_request_user">
|
||||
<page string="Stock Request" name="stock_request">
|
||||
<field name="stock_request_ids"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
29
stock_request_analytic/views/stock_request_order_views.xml
Normal file
29
stock_request_analytic/views/stock_request_order_views.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2017 Eficent
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
|
||||
<record id="stock_request_order_form" model="ir.ui.view">
|
||||
<field name="name">stock.request.order.form</field>
|
||||
<field name="model">stock.request.order</field>
|
||||
<field name="inherit_id" ref="stock_request.stock_request_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<field name="analytic_account_ids" invisible="1"/>
|
||||
<button type="object"
|
||||
name="action_view_analytic"
|
||||
class="oe_stat_button"
|
||||
icon="fa-truck"
|
||||
attrs="{'invisible': [('analytic_count', '=', 0)]}"
|
||||
groups="analytic.group_analytic_accounting">
|
||||
<field name="analytic_count" widget="statinfo"
|
||||
string="analytic"/>
|
||||
</button>
|
||||
</div>
|
||||
<xpath expr="//sheet/notebook/page/field[@name='stock_request_ids']/tree//field[@name='route_id']" position="after">
|
||||
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
17
stock_request_analytic/views/stock_request_views.xml
Normal file
17
stock_request_analytic/views/stock_request_views.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2017 Eficent
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
|
||||
<record id="view_stock_request_form" model="ir.ui.view">
|
||||
<field name="name">stock.request.form</field>
|
||||
<field name="model">stock.request</field>
|
||||
<field name="inherit_id" ref="stock_request.view_stock_request_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="procurement_group_id" position="after">
|
||||
<field name="analytic_account_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user