mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_request_analytic: black, isort, prettier
This commit is contained in:
committed by
Denis Roussel
parent
8ecc0f5054
commit
23d243ff42
@@ -1,2 +1 @@
|
|||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|||||||
@@ -7,13 +7,9 @@
|
|||||||
"version": "12.0.1.0.1",
|
"version": "12.0.1.0.1",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"website": "https://github.com/stock-logistics-warehouse",
|
"website": "https://github.com/stock-logistics-warehouse",
|
||||||
"author": "Eficent, "
|
"author": "Eficent, " "Odoo Community Association (OCA)",
|
||||||
"Odoo Community Association (OCA)",
|
|
||||||
"category": "Analytic",
|
"category": "Analytic",
|
||||||
"depends": [
|
"depends": ["stock_request", "stock_analytic",],
|
||||||
"stock_request",
|
|
||||||
"stock_analytic",
|
|
||||||
],
|
|
||||||
"data": [
|
"data": [
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
"views/stock_request_views.xml",
|
"views/stock_request_views.xml",
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ from odoo import fields, models
|
|||||||
|
|
||||||
|
|
||||||
class AccountAnalyticAccount(models.Model):
|
class AccountAnalyticAccount(models.Model):
|
||||||
_inherit = 'account.analytic.account'
|
_inherit = "account.analytic.account"
|
||||||
|
|
||||||
stock_request_ids = fields.One2many(
|
stock_request_ids = fields.One2many(
|
||||||
comodel_name='stock.request', inverse_name='analytic_account_id',
|
comodel_name="stock.request",
|
||||||
string='Stock Requests', copy=False)
|
inverse_name="analytic_account_id",
|
||||||
|
string="Stock Requests",
|
||||||
|
copy=False,
|
||||||
|
)
|
||||||
|
|||||||
@@ -9,15 +9,22 @@ class StockRequest(models.Model):
|
|||||||
_inherit = "stock.request"
|
_inherit = "stock.request"
|
||||||
|
|
||||||
analytic_account_id = fields.Many2one(
|
analytic_account_id = fields.Many2one(
|
||||||
'account.analytic.account', string='Analytic Account')
|
"account.analytic.account", string="Analytic Account"
|
||||||
analytic_tag_ids = fields.Many2many(
|
)
|
||||||
'account.analytic.tag', string='Analytic Tags')
|
analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags")
|
||||||
|
|
||||||
@api.constrains('analytic_account_id')
|
@api.constrains("analytic_account_id")
|
||||||
def _check_analytic_company_constrains(self):
|
def _check_analytic_company_constrains(self):
|
||||||
if any(r.company_id and r.analytic_account_id and
|
if any(
|
||||||
r.analytic_account_id.company_id != r.company_id for r in self):
|
r.company_id
|
||||||
|
and r.analytic_account_id
|
||||||
|
and r.analytic_account_id.company_id != r.company_id
|
||||||
|
for r in self
|
||||||
|
):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_('You cannot link a analytic account '
|
_(
|
||||||
'to a stock request that belongs to '
|
"You cannot link a analytic account "
|
||||||
'another company.'))
|
"to a stock request that belongs to "
|
||||||
|
"another company."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -5,45 +5,43 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
|
|
||||||
class StockRequestOrder(models.Model):
|
class StockRequestOrder(models.Model):
|
||||||
_inherit = 'stock.request.order'
|
_inherit = "stock.request.order"
|
||||||
|
|
||||||
analytic_count = fields.Integer(
|
analytic_count = fields.Integer(compute="_compute_analytic_ids", readonly=True,)
|
||||||
compute='_compute_analytic_ids',
|
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
analytic_account_ids = fields.One2many(
|
analytic_account_ids = fields.One2many(
|
||||||
comodel_name='account.analytic.account',
|
comodel_name="account.analytic.account",
|
||||||
compute='_compute_analytic_ids',
|
compute="_compute_analytic_ids",
|
||||||
string='Analytic Accounts',
|
string="Analytic Accounts",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
analytic_tag_ids = fields.One2many(
|
analytic_tag_ids = fields.One2many(
|
||||||
comodel_name='account.analytic.tag',
|
comodel_name="account.analytic.tag",
|
||||||
compute='_compute_analytic_ids',
|
compute="_compute_analytic_ids",
|
||||||
string='Analytic Tags',
|
string="Analytic Tags",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends('stock_request_ids')
|
@api.depends("stock_request_ids")
|
||||||
def _compute_analytic_ids(self):
|
def _compute_analytic_ids(self):
|
||||||
for req in self.sudo():
|
for req in self.sudo():
|
||||||
req.analytic_account_ids = req.stock_request_ids.mapped(
|
req.analytic_account_ids = req.stock_request_ids.mapped(
|
||||||
'analytic_account_id')
|
"analytic_account_id"
|
||||||
req.analytic_tag_ids = req.stock_request_ids.mapped(
|
)
|
||||||
'analytic_tag_ids')
|
req.analytic_tag_ids = req.stock_request_ids.mapped("analytic_tag_ids")
|
||||||
req.analytic_count = len(req.analytic_account_ids)
|
req.analytic_count = len(req.analytic_account_ids)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_analytic(self):
|
def action_view_analytic(self):
|
||||||
action = self.env.ref(
|
action = self.env.ref("analytic.action_account_analytic_account_form").read()[0]
|
||||||
'analytic.action_account_analytic_account_form').read()[0]
|
analytics = self.mapped("analytic_account_ids")
|
||||||
analytics = self.mapped('analytic_account_ids')
|
|
||||||
if len(analytics) > 1:
|
if len(analytics) > 1:
|
||||||
action['domain'] = [('id', 'in', analytics.ids)]
|
action["domain"] = [("id", "in", analytics.ids)]
|
||||||
elif analytics:
|
elif analytics:
|
||||||
action['views'] = [
|
action["views"] = [
|
||||||
(self.env.ref(
|
(
|
||||||
'analytic.action_account_analytic_account_form').id,
|
self.env.ref("analytic.action_account_analytic_account_form").id,
|
||||||
'form')]
|
"form",
|
||||||
action['res_id'] = analytics.id
|
)
|
||||||
|
]
|
||||||
|
action["res_id"] = analytics.id
|
||||||
return action
|
return action
|
||||||
|
|||||||
@@ -7,15 +7,29 @@ from odoo import models
|
|||||||
class ProcurementRule(models.Model):
|
class ProcurementRule(models.Model):
|
||||||
_inherit = "stock.rule"
|
_inherit = "stock.rule"
|
||||||
|
|
||||||
def _get_stock_move_values(self, product_id, product_qty, product_uom,
|
def _get_stock_move_values(
|
||||||
location_id, name, origin, values, group_id):
|
self,
|
||||||
|
product_id,
|
||||||
|
product_qty,
|
||||||
|
product_uom,
|
||||||
|
location_id,
|
||||||
|
name,
|
||||||
|
origin,
|
||||||
|
values,
|
||||||
|
group_id,
|
||||||
|
):
|
||||||
res = super(ProcurementRule, self)._get_stock_move_values(
|
res = super(ProcurementRule, self)._get_stock_move_values(
|
||||||
product_id, product_qty, product_uom, location_id, name, origin,
|
product_id,
|
||||||
values, group_id)
|
product_qty,
|
||||||
if values.get('stock_request_id'):
|
product_uom,
|
||||||
stock_request = self.env['stock.request'].browse(
|
location_id,
|
||||||
values['stock_request_id']
|
name,
|
||||||
)
|
origin,
|
||||||
|
values,
|
||||||
|
group_id,
|
||||||
|
)
|
||||||
|
if values.get("stock_request_id"):
|
||||||
|
stock_request = self.env["stock.request"].browse(values["stock_request_id"])
|
||||||
analytic_account = stock_request.analytic_account_id
|
analytic_account = stock_request.analytic_account_id
|
||||||
analytic_tags = stock_request.analytic_tag_ids
|
analytic_tags = stock_request.analytic_tag_ids
|
||||||
res.update(
|
res.update(
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
|
|
||||||
from . import test_stock_request_analytic
|
from . import test_stock_request_analytic
|
||||||
|
|||||||
@@ -1,86 +1,98 @@
|
|||||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
# 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 import fields
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
from odoo.addons.stock_request.tests import test_stock_request
|
||||||
|
|
||||||
|
|
||||||
class TestStockRequestAnalytic(test_stock_request.TestStockRequest):
|
class TestStockRequestAnalytic(test_stock_request.TestStockRequest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestStockRequestAnalytic, self).setUp()
|
super(TestStockRequestAnalytic, self).setUp()
|
||||||
self.analytic_model = self.env['account.analytic.account']
|
self.analytic_model = self.env["account.analytic.account"]
|
||||||
self.analytic = self.analytic_model.create({'name': 'Pizza'})
|
self.analytic = self.analytic_model.create({"name": "Pizza"})
|
||||||
self.analytic2 = self.analytic_model.create({
|
self.analytic2 = self.analytic_model.create(
|
||||||
'name': 'Pizza',
|
{"name": "Pizza", "company_id": self.company_2.id,}
|
||||||
'company_id': self.company_2.id,
|
)
|
||||||
})
|
self.demand_loc = self.env["stock.location"].create(
|
||||||
self.demand_loc = self.env['stock.location'].create({
|
{
|
||||||
'name': 'demand_loc',
|
"name": "demand_loc",
|
||||||
'location_id': self.warehouse.lot_stock_id.id,
|
"location_id": self.warehouse.lot_stock_id.id,
|
||||||
'usage': 'internal',
|
"usage": "internal",
|
||||||
})
|
}
|
||||||
self.demand_route = self.env['stock.location.route'].create({
|
)
|
||||||
'name': 'Transfer',
|
self.demand_route = self.env["stock.location.route"].create(
|
||||||
'product_categ_selectable': False,
|
{
|
||||||
'product_selectable': True,
|
"name": "Transfer",
|
||||||
'company_id': self.main_company.id,
|
"product_categ_selectable": False,
|
||||||
'sequence': 10,
|
"product_selectable": True,
|
||||||
})
|
"company_id": self.main_company.id,
|
||||||
self.pizza = self._create_product('PZ', 'Pizza', False)
|
"sequence": 10,
|
||||||
self.demand_rule = self.env['stock.rule'].create({
|
}
|
||||||
'name': 'Transfer',
|
)
|
||||||
'route_id': self.demand_route.id,
|
self.pizza = self._create_product("PZ", "Pizza", False)
|
||||||
'location_src_id': self.warehouse.lot_stock_id.id,
|
self.demand_rule = self.env["stock.rule"].create(
|
||||||
'location_id': self.demand_loc.id,
|
{
|
||||||
'action': 'pull',
|
"name": "Transfer",
|
||||||
'picking_type_id': self.warehouse.int_type_id.id,
|
"route_id": self.demand_route.id,
|
||||||
'procure_method': 'make_to_stock',
|
"location_src_id": self.warehouse.lot_stock_id.id,
|
||||||
'warehouse_id': self.warehouse.id,
|
"location_id": self.demand_loc.id,
|
||||||
'company_id': self.main_company.id,
|
"action": "pull",
|
||||||
'propagate': 'False',
|
"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)]
|
self.pizza.route_ids = [(6, 0, self.demand_route.ids)]
|
||||||
|
|
||||||
def prepare_order_request_analytic(self, aa, company, analytic_tags=None):
|
def prepare_order_request_analytic(self, aa, company, analytic_tags=None):
|
||||||
expected_date = fields.Datetime.now()
|
expected_date = fields.Datetime.now()
|
||||||
analytic_tags = analytic_tags or self.env["account.analytic.tag"]
|
analytic_tags = analytic_tags or self.env["account.analytic.tag"]
|
||||||
vals = {
|
vals = {
|
||||||
'company_id': company.id,
|
"company_id": company.id,
|
||||||
'warehouse_id': self.warehouse.id,
|
"warehouse_id": self.warehouse.id,
|
||||||
'location_id': self.demand_loc.id,
|
"location_id": self.demand_loc.id,
|
||||||
'expected_date': expected_date,
|
"expected_date": expected_date,
|
||||||
'stock_request_ids': [(0, 0, {
|
"stock_request_ids": [
|
||||||
'product_id': self.pizza.id,
|
(
|
||||||
'product_uom_id': self.pizza.uom_id.id,
|
0,
|
||||||
'product_uom_qty': 5.0,
|
0,
|
||||||
'analytic_account_id': aa.id,
|
{
|
||||||
'analytic_tag_ids': [(4, tag.id) for tag in analytic_tags],
|
"product_id": self.pizza.id,
|
||||||
'company_id': company.id,
|
"product_uom_id": self.pizza.uom_id.id,
|
||||||
'warehouse_id': self.warehouse.id,
|
"product_uom_qty": 5.0,
|
||||||
'location_id': self.demand_loc.id,
|
"analytic_account_id": aa.id,
|
||||||
'expected_date': expected_date,
|
"analytic_tag_ids": [(4, tag.id) for tag in analytic_tags],
|
||||||
})]
|
"company_id": company.id,
|
||||||
|
"warehouse_id": self.warehouse.id,
|
||||||
|
"location_id": self.demand_loc.id,
|
||||||
|
"expected_date": expected_date,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
def test_stock_analytic(self):
|
def test_stock_analytic(self):
|
||||||
analytic_tag = self.env.ref('analytic.tag_contract')
|
analytic_tag = self.env.ref("analytic.tag_contract")
|
||||||
vals = self.prepare_order_request_analytic(
|
vals = self.prepare_order_request_analytic(
|
||||||
self.analytic, self.main_company, analytic_tags=analytic_tag)
|
self.analytic, self.main_company, analytic_tags=analytic_tag
|
||||||
order = self.env['stock.request.order'].create(vals)
|
)
|
||||||
|
order = self.env["stock.request.order"].create(vals)
|
||||||
req = order.stock_request_ids
|
req = order.stock_request_ids
|
||||||
order.action_confirm()
|
order.action_confirm()
|
||||||
self.assertEqual(
|
self.assertEqual(req.move_ids.mapped("analytic_account_id"), self.analytic)
|
||||||
req.move_ids.mapped('analytic_account_id'), self.analytic)
|
self.assertEqual(req.move_ids.mapped("analytic_tag_ids"), analytic_tag)
|
||||||
self.assertEqual(
|
|
||||||
req.move_ids.mapped('analytic_tag_ids'), analytic_tag)
|
|
||||||
self.assertEqual(order.analytic_count, 1)
|
self.assertEqual(order.analytic_count, 1)
|
||||||
action = order.action_view_analytic()
|
action = order.action_view_analytic()
|
||||||
self.assertTrue(action['res_id'], self.analytic.id)
|
self.assertTrue(action["res_id"], self.analytic.id)
|
||||||
|
|
||||||
def test_company(self):
|
def test_company(self):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
vals = self.prepare_order_request_analytic(
|
vals = self.prepare_order_request_analytic(
|
||||||
self.analytic2, self.main_company)
|
self.analytic2, self.main_company
|
||||||
self.env['stock.request.order'].create(vals)
|
)
|
||||||
|
self.env["stock.request.order"].create(vals)
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" ?>
|
||||||
<!-- Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
<!-- Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="view_account_analytic_account_form" model="ir.ui.view">
|
<record id="view_account_analytic_account_form" model="ir.ui.view">
|
||||||
<field name="name">analytic.order.form</field>
|
<field name="name">analytic.order.form</field>
|
||||||
<field name="model">account.analytic.account</field>
|
<field name="model">account.analytic.account</field>
|
||||||
<field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
|
<field name="inherit_id" ref="analytic.view_account_analytic_account_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//group[@name='main']" position='after'>
|
<xpath expr="//group[@name='main']" position='after'>
|
||||||
<notebook groups="stock_request.group_stock_request_user">
|
<notebook groups="stock_request.group_stock_request_user">
|
||||||
<page string="Stock Request" name="stock_request">
|
<page string="Stock Request" name="stock_request">
|
||||||
<field name="stock_request_ids"/>
|
<field name="stock_request_ids" />
|
||||||
</page>
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -1,30 +1,39 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<!-- Copyright 2017 Eficent
|
<!-- Copyright 2017 Eficent
|
||||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="stock_request_order_form" model="ir.ui.view">
|
<record id="stock_request_order_form" model="ir.ui.view">
|
||||||
<field name="name">stock.request.order.form - stock_request_analytic</field>
|
<field name="name">stock.request.order.form - stock_request_analytic</field>
|
||||||
<field name="model">stock.request.order</field>
|
<field name="model">stock.request.order</field>
|
||||||
<field name="inherit_id" ref="stock_request.stock_request_order_form"/>
|
<field name="inherit_id" ref="stock_request.stock_request_order_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<div name="button_box" position="inside">
|
<div name="button_box" position="inside">
|
||||||
<field name="analytic_account_ids" invisible="1"/>
|
<field name="analytic_account_ids" invisible="1" />
|
||||||
<field name="analytic_tag_ids" />
|
<field name="analytic_tag_ids" />
|
||||||
<button type="object"
|
<button
|
||||||
|
type="object"
|
||||||
name="action_view_analytic"
|
name="action_view_analytic"
|
||||||
class="oe_stat_button"
|
class="oe_stat_button"
|
||||||
icon="fa-list"
|
icon="fa-list"
|
||||||
attrs="{'invisible': [('analytic_count', '=', 0)]}"
|
attrs="{'invisible': [('analytic_count', '=', 0)]}"
|
||||||
groups="analytic.group_analytic_accounting">
|
groups="analytic.group_analytic_accounting"
|
||||||
<field name="analytic_count" widget="statinfo"
|
>
|
||||||
string="Analytic Accounts"/>
|
<field
|
||||||
|
name="analytic_count"
|
||||||
|
widget="statinfo"
|
||||||
|
string="Analytic Accounts"
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<xpath expr="//field[@name='stock_request_ids']/tree//field[@name='route_id']" position="after">
|
<xpath
|
||||||
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
|
expr="//field[@name='stock_request_ids']/tree//field[@name='route_id']"
|
||||||
|
position="after"
|
||||||
|
>
|
||||||
|
<field
|
||||||
|
name="analytic_account_id"
|
||||||
|
groups="analytic.group_analytic_accounting"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<!-- Copyright 2017 Eficent
|
<!-- Copyright 2017 Eficent
|
||||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="view_stock_request_form" model="ir.ui.view">
|
<record id="view_stock_request_form" model="ir.ui.view">
|
||||||
<field name="name">stock.request.form</field>
|
<field name="name">stock.request.form</field>
|
||||||
<field name="model">stock.request</field>
|
<field name="model">stock.request</field>
|
||||||
<field name="inherit_id" ref="stock_request.view_stock_request_form"/>
|
<field name="inherit_id" ref="stock_request.view_stock_request_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="procurement_group_id" position="after">
|
<field name="procurement_group_id" position="after">
|
||||||
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
|
<field
|
||||||
<field name="analytic_tag_ids" groups="analytic.group_analytic_accounting"/>
|
name="analytic_account_id"
|
||||||
|
groups="analytic.group_analytic_accounting"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="analytic_tag_ids"
|
||||||
|
groups="analytic.group_analytic_accounting"
|
||||||
|
/>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user